Skip to content

Commit

Permalink
Speech and Copiliot: update titles to include language and saved run …
Browse files Browse the repository at this point in the history
…name instead of input prompt
  • Loading branch information
devxpy committed Feb 27, 2025
1 parent 9b0e02a commit 841cc97
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
18 changes: 14 additions & 4 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from daras_ai_v2.send_email import send_reported_run_email
from daras_ai_v2.urls import paginate_button, paginate_queryset
from daras_ai_v2.user_date_widgets import render_local_dt_attrs
from daras_ai_v2.utils import get_relative_time
from daras_ai_v2.variables_widget import variables_input
from functions.models import FunctionTrigger, RecipeFunction, VariableSchema
from functions.recipe_functions import (
Expand All @@ -70,7 +71,6 @@
from routers.root import RecipeTabs
from workspaces.models import Workspace, WorkspaceMembership
from workspaces.widgets import get_current_workspace, set_current_workspace
from daras_ai_v2.utils import get_relative_time

DEFAULT_META_IMG = (
# Small
Expand Down Expand Up @@ -741,7 +741,7 @@ def _render_publish_form(

with form_container:
if user_can_edit:
title = pr.title or self.title
title = self.get_run_title(self.current_sr, self.current_pr)
notes = pr.notes
else:
title = self._get_default_pr_title()
Expand Down Expand Up @@ -879,8 +879,7 @@ def _render_workspace_selector(self, *, key: str) -> "Workspace":
return self.current_workspace

def _get_default_pr_title(self):
recipe_title = self.get_root_pr().title or self.title
return f"{self.request.user.first_name_possesive()} {recipe_title}"
return f"{self.request.user.first_name_possesive()} {self.get_run_title(self.current_sr, self.current_pr)}"

def _validate_published_run_title(self, title: str):
if slugify(title) in settings.DISALLOWED_TITLE_SLUGS:
Expand Down Expand Up @@ -1096,6 +1095,17 @@ def _render_admin_options(self, current_run: SavedRun, published_run: PublishedR
)
raise gui.RedirectException(self.app_url())

@classmethod
def get_prompt_title(cls, sr: SavedRun) -> str | None:
return truncate_text_words(
cls.preview_input(sr.to_dict()) or "",
maxlen=60,
).replace("\n", " ")

@classmethod
def get_run_title(cls, sr: SavedRun, pr: PublishedRun) -> str:
return pr.title or cls.get_recipe_title()

@classmethod
def get_recipe_title(cls) -> str:
return cls.get_root_pr().title or cls.title or cls.workflow.label
Expand Down
13 changes: 5 additions & 8 deletions daras_ai_v2/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ def get_title_breadcrumbs(
is_example = not is_root and pr and pr.saved_run == sr
is_run = not is_root and not is_example

recipe_title = page_cls.get_recipe_title()
prompt_title = truncate_text_words(
page_cls.preview_input(sr.to_dict()) or "",
maxlen=60,
).replace("\n", " ")

metadata = page_cls.workflow.get_or_create_metadata()
root_breadcrumb = TitleUrl(metadata.short_title, page_cls.app_url())

Expand All @@ -105,7 +99,9 @@ def get_title_breadcrumbs(
case _ if is_example:
assert pr is not None
return TitleBreadCrumbs(
pr.title or prompt_title or recipe_title,
pr.title
or page_cls.get_prompt_title(sr)
or page_cls.get_run_title(sr, pr),
root_title=root_breadcrumb,
published_title=None,
)
Expand All @@ -118,7 +114,8 @@ def get_title_breadcrumbs(
else:
published_title = None
return TitleBreadCrumbs(
prompt_title or f"Run: {recipe_title}",
page_cls.get_prompt_title(sr)
or f"Run: {page_cls.get_run_title(sr, pr)}",
root_title=root_breadcrumb,
published_title=published_title,
)
Expand Down
19 changes: 19 additions & 0 deletions recipes/VideoBots.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
PublishedRun,
PublishedRunVisibility,
Workflow,
SavedRun,
)
from celeryapp.tasks import send_integration_attempt_email
from daras_ai.image_input import (
Expand Down Expand Up @@ -318,6 +319,24 @@ def related_workflows(self):
CompareText2ImgPage,
]

@classmethod
def get_run_title(cls, sr: SavedRun, pr: PublishedRun) -> str:
import langcodes

try:
lang = langcodes.Language.get(
sr.state.get("user_language") or sr.state.get("asr_language") or ""
).display_name()
except (KeyError, langcodes.LanguageTagError):
lang = None
title = super().get_run_title(sr, pr)
return " ".join(filter(None, [lang, title]))

@classmethod
def get_prompt_title(cls, state: dict) -> str | None:
# don't show the input prompt in the run titles, instead show get_run_title()
return None

def preview_description(self, state: dict) -> str:
return "Create customized chatbots from your own docs/PDF/webpages. Craft your own bot prompts using the creative GPT3, fast GPT 3.5-turbo or powerful GPT4 & optionally prevent hallucinations by constraining all answers to just your citations. Available as Facebook, Instagram, WhatsApp bots or via API. Add multi-lingual speech recognition and text-to-speech in 100+ languages and even video responses. Collect 👍🏾 👎🏽 feedback + see usage & retention graphs too! This is the workflow that powers https://Farmer.CHAT and it's yours to tweak."
# return "Create an amazing, interactive AI videobot with just a GPT3 script + a video clip or photo. To host it on your own site or app, contact us at [email protected]"
Expand Down
5 changes: 4 additions & 1 deletion recipes/VideoBotsStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def show_title_breadcrumb_share(
gui.markdown("# " + self.get_dynamic_meta_title())

def get_dynamic_meta_title(self):
return f"📊 {self.bi.name} Analytics" if self.bi else self.title
if self.bi:
return f"📊 {self.bi.name} Analytics"
else:
return self.title

def render(self):
self.setup_sentry()
Expand Down
15 changes: 14 additions & 1 deletion recipes/asr_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from jinja2.lexer import whitespace_re
from pydantic import BaseModel, Field

from bots.models import Workflow
from bots.models import Workflow, SavedRun, PublishedRun
from daras_ai_v2.asr import (
language_filter_selector,
asr_language_selector,
Expand Down Expand Up @@ -93,6 +93,19 @@ def get_example_preferred_fields(cls, state: dict) -> list[str]:
"translation_target",
]

@classmethod
def get_run_title(cls, sr: SavedRun, pr: PublishedRun) -> str:
import langcodes

try:
lang = langcodes.Language.get(sr.state["language"] or "").display_name()
except (KeyError, langcodes.LanguageTagError):
lang = None
model = AsrModels.get(sr.state.get("selected_model"))
lang_or_model = lang or (model and model.value)

return " ".join(filter(None, [lang_or_model, cls.get_recipe_title()]))

def preview_image(self, state: dict) -> str | None:
return DEFAULT_ASR_META_IMG

Expand Down

0 comments on commit 841cc97

Please sign in to comment.