Skip to content

Commit

Permalink
add is_api_call to savedrun
Browse files Browse the repository at this point in the history
show api call in breadcrumbs
  • Loading branch information
devxpy committed Feb 12, 2024
1 parent dc70569 commit 6cd5617
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 15 deletions.
18 changes: 18 additions & 0 deletions bots/migrations/0059_savedrun_is_api_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-02-12 07:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bots', '0058_alter_savedrun_unique_together_and_more'),
]

operations = [
migrations.AddField(
model_name='savedrun',
name='is_api_call',
field=models.BooleanField(default=False),
),
]
2 changes: 2 additions & 0 deletions bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class SavedRun(models.Model):
page_title = models.TextField(default="", blank=True, help_text="(Deprecated)")
page_notes = models.TextField(default="", blank=True, help_text="(Deprecated)")

is_api_call = models.BooleanField(default=False)

objects = SavedRunQuerySet.as_manager()

class Meta:
Expand Down
1 change: 1 addition & 0 deletions celeryapp/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def gui_runner(
):
page = page_cls(request=SimpleNamespace(user=AppUser.objects.get(id=user_id)))
sr = page.run_doc_sr(run_id, uid)
sr.is_api_call = is_api_call

st.set_session_state(state)
run_time = 0
Expand Down
23 changes: 10 additions & 13 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _render_header(self):

if tbreadcrumbs:
with st.tag("div", className="me-3 mb-1 mb-lg-0 py-2 py-lg-0"):
render_breadcrumbs(tbreadcrumbs)
render_breadcrumbs(tbreadcrumbs, current_run.is_api_call)

author = self.run_user or current_run.get_creator()
if not is_root_example:
Expand Down Expand Up @@ -996,9 +996,7 @@ def get_or_create_root_published_run(cls) -> PublishedRun:
workflow=cls.workflow,
published_run_id="",
defaults={
"saved_run": lambda: cls.run_doc_sr(
run_id="", uid="", create=True, parent=None, parent_version=None
),
"saved_run": lambda: cls.run_doc_sr(run_id="", uid="", create=True),
"created_by": None,
"last_edited_by": None,
"title": cls.title,
Expand All @@ -1022,15 +1020,11 @@ def run_doc_sr(
run_id: str,
uid: str,
create: bool = False,
parent: SavedRun | None = None,
parent_version: PublishedRunVersion | None = None,
defaults: dict = None,
) -> SavedRun:
config = dict(workflow=cls.workflow, uid=uid, run_id=run_id)
if create:
return SavedRun.objects.get_or_create(
**config,
defaults=dict(parent=parent, parent_version=parent_version),
)[0]
return SavedRun.objects.get_or_create(**config, defaults=defaults)[0]
else:
return SavedRun.objects.get(**config)

Expand Down Expand Up @@ -1408,7 +1402,7 @@ def should_submit_after_login(self) -> bool:
and not self.request.user.is_anonymous
)

def create_new_run(self):
def create_new_run(self, is_api_call: bool = False):
st.session_state[StateKeys.run_status] = "Starting..."
st.session_state.pop(StateKeys.error_msg, None)
st.session_state.pop(StateKeys.run_time, None)
Expand Down Expand Up @@ -1443,8 +1437,11 @@ def create_new_run(self):
run_id,
uid,
create=True,
parent=parent,
parent_version=parent_version,
defaults=dict(
parent=parent,
parent_version=parent_version,
is_api_call=is_api_call,
),
).set(self.state_to_doc(st.session_state))

return None, run_id, uid
Expand Down
5 changes: 4 additions & 1 deletion daras_ai_v2/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def has_breadcrumbs(self):
return bool(self.root_title or self.published_title)


def render_breadcrumbs(breadcrumbs: TitleBreadCrumbs):
def render_breadcrumbs(breadcrumbs: TitleBreadCrumbs, is_api_call: bool = False):
st.html(
"""
<style>
Expand Down Expand Up @@ -68,6 +68,9 @@ def render_breadcrumbs(breadcrumbs: TitleBreadCrumbs):
link_to=breadcrumbs.published_title.url,
)

if is_api_call:
st.caption("(API)")


def get_title_breadcrumbs(
page_cls: typing.Union["BasePage", typing.Type["BasePage"]],
Expand Down
2 changes: 1 addition & 1 deletion routers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def submit_api_call(
},
)
# create a new run
example_id, run_id, uid = self.create_new_run()
example_id, run_id, uid = self.create_new_run(is_api_call=True)
# submit the task
result = self.call_runner_task(example_id, run_id, uid, is_api_call=True)
return self, result, run_id, uid
Expand Down
18 changes: 18 additions & 0 deletions usage_costs/migrations/0004_alter_modelpricing_model_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-02-07 16:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('usage_costs', '0003_alter_modelpricing_model_name'),
]

operations = [
migrations.AlterField(
model_name='modelpricing',
name='model_name',
field=models.CharField(choices=[('gpt_4_vision', 'GPT-4 Vision (openai)'), ('gpt_4_turbo', 'GPT-4 Turbo (openai)'), ('gpt_4', 'GPT-4 (openai)'), ('gpt_4_32k', 'GPT-4 32K (openai)'), ('gpt_3_5_turbo', 'ChatGPT (openai)'), ('gpt_3_5_turbo_16k', 'ChatGPT 16k (openai)'), ('llama2_70b_chat', 'Llama 2 (Meta AI)'), ('palm2_chat', 'PaLM 2 Chat (Google)'), ('palm2_text', 'PaLM 2 Text (Google)'), ('text_davinci_003', 'GPT-3.5 Davinci-3 (openai)'), ('text_davinci_002', 'GPT-3.5 Davinci-2 (openai)'), ('text_curie_001', 'Curie (openai)'), ('text_babbage_001', 'Babbage (openai)'), ('text_ada_001', 'Ada (openai)'), ('code_davinci_002', 'Codex [Deprecated] (openai)'), ('protogen_2_2', 'Protogen V2.2 (darkstorm2150)'), ('epicdream', 'epiCDream (epinikion)'), ('dream_shaper', 'DreamShaper (Lykon)'), ('dreamlike_2', 'Dreamlike Photoreal 2.0 (dreamlike.art)'), ('sd_2', 'Stable Diffusion v2.1 (stability.ai)'), ('sd_1_5', 'Stable Diffusion v1.5 (RunwayML)'), ('dall_e', 'DALL·E 2 (OpenAI)'), ('dall_e_3', 'DALL·E 3 (OpenAI)'), ('openjourney_2', 'Open Journey v2 beta (PromptHero) 🐢'), ('openjourney', 'Open Journey (PromptHero) 🐢'), ('analog_diffusion', 'Analog Diffusion (wavymulder) 🐢'), ('protogen_5_3', 'Protogen v5.3 (darkstorm2150) 🐢'), ('jack_qiao', 'Stable Diffusion v1.4 [Deprecated] (Jack Qiao)'), ('rodent_diffusion_1_5', 'Rodent Diffusion 1.5 [Deprecated] (NerdyRodent)'), ('deepfloyd_if', 'DeepFloyd IF [Deprecated] (stability.ai)'), ('dream_shaper', 'DreamShaper (Lykon)'), ('dreamlike_2', 'Dreamlike Photoreal 2.0 (dreamlike.art)'), ('sd_2', 'Stable Diffusion v2.1 (stability.ai)'), ('sd_1_5', 'Stable Diffusion v1.5 (RunwayML)'), ('dall_e', 'Dall-E (OpenAI)'), ('instruct_pix2pix', '✨ InstructPix2Pix (Tim Brooks)'), ('openjourney_2', 'Open Journey v2 beta (PromptHero) 🐢'), ('openjourney', 'Open Journey (PromptHero) 🐢'), ('analog_diffusion', 'Analog Diffusion (wavymulder) 🐢'), ('protogen_5_3', 'Protogen v5.3 (darkstorm2150) 🐢'), ('jack_qiao', 'Stable Diffusion v1.4 [Deprecated] (Jack Qiao)'), ('rodent_diffusion_1_5', 'Rodent Diffusion 1.5 [Deprecated] (NerdyRodent)'), ('sd_2', 'Stable Diffusion v2.1 (stability.ai)'), ('runway_ml', 'Stable Diffusion v1.5 (RunwayML)'), ('dall_e', 'Dall-E (OpenAI)'), ('jack_qiao', 'Stable Diffusion v1.4 [Deprecated] (Jack Qiao)'), ('wav2lip', 'LipSync (wav2lip)')], help_text='The name of the model. Only used for Display purposes.', max_length=255),
),
]

0 comments on commit 6cd5617

Please sign in to comment.