Skip to content

Commit

Permalink
Merge branch 'master' into copilot_stats_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Feb 1, 2024
2 parents e004111 + 24cf032 commit 95f288f
Show file tree
Hide file tree
Showing 14 changed files with 496 additions and 280 deletions.
33 changes: 25 additions & 8 deletions bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,16 @@ class PublishedRunAdmin(admin.ModelAdmin):
"view_user",
"open_in_gooey",
"linked_saved_run",
"view_runs",
"created_at",
"updated_at",
]
list_filter = ["workflow", "visibility", "created_by__is_paying"]
search_fields = ["workflow", "published_run_id"]
search_fields = ["workflow", "published_run_id", "title", "notes"]
autocomplete_fields = ["saved_run", "created_by", "last_edited_by"]
readonly_fields = [
"open_in_gooey",
"view_runs",
"created_at",
"updated_at",
]
Expand All @@ -243,19 +245,28 @@ def linked_saved_run(self, published_run: PublishedRun):

linked_saved_run.short_description = "Linked Run"

@admin.display(description="View Runs")
def view_runs(self, published_run: PublishedRun):
return list_related_html_url(
SavedRun.objects.filter(parent_version__published_run=published_run),
query_param="parent_version__published_run__id__exact",
instance_id=published_run.id,
show_add=False,
)


@admin.register(SavedRun)
class SavedRunAdmin(admin.ModelAdmin):
list_display = [
"__str__",
"example_id",
"run_id",
"view_user",
"created_at",
"open_in_gooey",
"view_parent_published_run",
"run_time",
"updated_at",
"price",
"preview_input",
"created_at",
"updated_at",
]
list_filter = ["workflow"]
search_fields = ["workflow", "example_id", "run_id", "uid"]
Expand All @@ -278,6 +289,11 @@ class SavedRunAdmin(admin.ModelAdmin):
django.db.models.JSONField: {"widget": JSONEditorWidget},
}

def lookup_allowed(self, key, value):
if key in ["parent_version__published_run__id__exact"]:
return True
return super().lookup_allowed(key, value)

def view_user(self, saved_run: SavedRun):
return change_obj_url(
AppUser.objects.get(uid=saved_run.uid),
Expand All @@ -291,9 +307,10 @@ def view_bots(self, saved_run: SavedRun):

view_bots.short_description = "View Bots"

@admin.display(description="Input")
def preview_input(self, saved_run: SavedRun):
return truncate_text_words(BasePage.preview_input(saved_run.state) or "", 100)
@admin.display(description="View Published Run")
def view_parent_published_run(self, saved_run: SavedRun):
pr = saved_run.parent_published_run()
return pr and change_obj_url(pr)


@admin.register(PublishedRunVersion)
Expand Down
10 changes: 9 additions & 1 deletion bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,15 @@ class Meta:
]

def __str__(self):
return self.get_app_url()
from daras_ai_v2.breadcrumbs import get_title_breadcrumbs

title = get_title_breadcrumbs(
Workflow(self.workflow).page_cls, self, self.parent_published_run()
).h1_title
return title or self.get_app_url()

def parent_published_run(self) -> "PublishedRun":
return self.parent_version and self.parent_version.published_run

def get_app_url(self):
workflow = Workflow(self.workflow)
Expand Down
2 changes: 1 addition & 1 deletion daras_ai_v2/all_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def normalize_slug(page_slug):
normalize_slug(slug): page
for page in (all_api_pages + all_hidden_pages)
for slug in page.slug_versions
}
} | {str(page.workflow.value): page for page in (all_api_pages + all_hidden_pages)}

workflow_map: dict[Workflow, typing.Type[BasePage]] = {
page.workflow: page for page in all_api_pages
Expand Down
6 changes: 2 additions & 4 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ def get_runs_from_query_params(
) -> tuple[SavedRun, PublishedRun | None]:
if run_id and uid:
sr = cls.run_doc_sr(run_id, uid)
pr = (sr and sr.parent_version and sr.parent_version.published_run) or None
pr = sr.parent_published_run()
else:
pr = cls.get_published_run(published_run_id=example_id or "")
sr = pr.saved_run
Expand All @@ -940,9 +940,7 @@ def get_pr_from_query_params(
) -> PublishedRun | None:
if run_id and uid:
sr = cls.get_sr_from_query_params(example_id, run_id, uid)
return (
sr and sr.parent_version and sr.parent_version.published_run
) or None
return sr.parent_published_run()
elif example_id:
return cls.get_published_run(published_run_id=example_id)
else:
Expand Down
20 changes: 10 additions & 10 deletions daras_ai_v2/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


def flatapply_parallel(
fn: typing.Callable[[T], list[R]],
*iterables: typing.Sequence[T],
fn: typing.Callable[..., list[R]],
*iterables,
max_workers: int = None,
message: str = "",
) -> typing.Generator[str, None, list[R]]:
Expand All @@ -20,8 +20,8 @@ def flatapply_parallel(


def apply_parallel(
fn: typing.Callable[[T], R],
*iterables: typing.Sequence[T],
fn: typing.Callable[..., R],
*iterables,
max_workers: int = None,
message: str = "",
) -> typing.Generator[str, None, list[R]]:
Expand All @@ -42,8 +42,8 @@ def apply_parallel(


def fetch_parallel(
fn: typing.Callable[[T], R],
*iterables: typing.Sequence[T],
fn: typing.Callable[..., R],
*iterables,
max_workers: int = None,
) -> typing.Generator[R, None, None]:
assert iterables, "fetch_parallel() requires at least one iterable"
Expand All @@ -57,16 +57,16 @@ def fetch_parallel(


def flatmap_parallel(
fn: typing.Callable[[T], list[R]],
*iterables: typing.Sequence[T],
fn: typing.Callable[..., list[R]],
*iterables,
max_workers: int = None,
) -> list[R]:
return flatten(map_parallel(fn, *iterables, max_workers=max_workers))


def map_parallel(
fn: typing.Callable[[T], R],
*iterables: typing.Sequence[T],
fn: typing.Callable[..., R],
*iterables,
max_workers: int = None,
) -> list[R]:
assert iterables, "map_parallel() requires at least one iterable"
Expand Down
Loading

0 comments on commit 95f288f

Please sign in to comment.