Skip to content

Commit

Permalink
new variables ux and schema
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Dec 11, 2024
1 parent 154bfc5 commit 14356c1
Show file tree
Hide file tree
Showing 15 changed files with 453 additions and 236 deletions.
6 changes: 5 additions & 1 deletion bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from bots.custom_fields import PostgresJSONEncoder, CustomURLField
from daras_ai_v2 import icons, urls
from daras_ai_v2.crypto import get_random_doc_id
from daras_ai_v2.fastapi_tricks import get_route_path
from daras_ai_v2.fastapi_tricks import get_route_path, get_api_route_url
from daras_ai_v2.language_model import format_chat_entry
from functions.models import CalledFunctionResponse
from gooeysite.bg_db_conn import get_celery_result_db_safe
Expand Down Expand Up @@ -827,6 +827,10 @@ def get_web_widget_config(self, target="#gooey-embed") -> dict:
)
),
)
if settings.DEBUG:
from routers.bots_api import stream_create

config["apiUrl"] = get_api_route_url(stream_create)
return config

def translate(self, text: str) -> str:
Expand Down
8 changes: 6 additions & 2 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
from daras_ai_v2.html_spinner_widget import html_spinner, scroll_into_view
from daras_ai_v2.manage_api_keys_widget import manage_api_keys
from daras_ai_v2.meta_preview_url import meta_preview_url
from daras_ai_v2.prompt_vars import variables_input
from daras_ai_v2.query_params_util import extract_query_params
from daras_ai_v2.ratelimits import ensure_rate_limits, RateLimitExceeded
from daras_ai_v2.send_email import send_reported_run_email
from daras_ai_v2.urls import paginate_queryset, paginate_button
from daras_ai_v2.user_date_widgets import render_local_dt_attrs
from functions.models import RecipeFunction, FunctionTrigger
from daras_ai_v2.variables_widget import variables_input
from functions.models import RecipeFunction, FunctionTrigger, VariableSchema
from functions.recipe_functions import (
functions_input,
call_recipe_functions,
Expand Down Expand Up @@ -142,6 +142,10 @@ class RequestModel(BaseModel):
title="⌥ Variables",
description="Variables to be used as Jinja prompt templates and in functions as arguments",
)
variables_schema: dict[str, VariableSchema] | None = Field(
title="Variables Schema",
description="Schema for variables to be used in the variables input",
)

ResponseModel: typing.Type[BaseModel]

Expand Down
13 changes: 8 additions & 5 deletions daras_ai_v2/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,18 @@ def _process_and_send_msg(
# get latest messages for context
saved_msgs = bot.convo.msgs_for_llm_context()

variables = (bot.saved_run.state.get("variables") or {}) | build_run_vars(
bot.convo, bot.user_msg_id
)
system_vars, system_vars_schema = build_system_vars(bot.convo, bot.user_msg_id)
state = bot.saved_run.state
variables = (state.get("variables") or {}) | system_vars
variables_schema = (state.get("variables_schema") or {}) | system_vars_schema
body = dict(
input_prompt=input_text,
input_audio=input_audio,
input_images=input_images,
input_documents=input_documents,
messages=saved_msgs,
variables=variables,
variables_schema=variables_schema,
)
if bot.user_language:
body["user_language"] = bot.user_language
Expand Down Expand Up @@ -484,7 +486,7 @@ def _process_and_send_msg(
)


def build_run_vars(convo: Conversation, user_msg_id: str):
def build_system_vars(convo: Conversation, user_msg_id: str) -> tuple[dict, dict]:
from routers.bots_api import MSG_ID_PREFIX

bi = convo.bot_integration
Expand Down Expand Up @@ -524,7 +526,8 @@ def build_run_vars(convo: Conversation, user_msg_id: str):
variables["bot_twilio_phone_number"] = (
bi.twilio_phone_number and bi.twilio_phone_number.as_international
)
return variables
variables_schema = {var: {"role": "system"} for var in variables}
return variables, variables_schema


def _save_msgs(
Expand Down
147 changes: 0 additions & 147 deletions daras_ai_v2/prompt_vars.py

This file was deleted.

2 changes: 1 addition & 1 deletion daras_ai_v2/query_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from daras_ai_v2.language_model import (
run_language_model,
)
from daras_ai_v2.prompt_vars import render_prompt_vars
from daras_ai_v2.variables_widget import render_prompt_vars

Model = typing.TypeVar("Model", bound=BaseModel)

Expand Down
Loading

0 comments on commit 14356c1

Please sign in to comment.