Skip to content

Commit

Permalink
Merge branch 'master' into Paypal
Browse files Browse the repository at this point in the history
  • Loading branch information
clr-li committed Dec 27, 2023
2 parents 04cbea2 + 93715d3 commit a994673
Show file tree
Hide file tree
Showing 77 changed files with 4,378 additions and 1,060 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ RUN pip install --no-cache-dir -U poetry pip && poetry install --no-cache --only

# install nltk stopwords
RUN poetry run python -c 'import nltk; nltk.download("stopwords")'
# install playwright
RUN poetry run playwright install-deps && poetry run playwright install

# copy the code into the container
COPY . .
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ gooey.ai (dev)
App ID: 228027632918921
```

Create a [meta developer account](https://developers.facebook.com/docs/development/register/) & ask someone to add you to the test app [here](https://developers.facebook.com/apps/228027632918921/roles/roles/?business_id=549319917267066)
Create a [meta developer account](https://developers.facebook.com/docs/development/register/) & send admin your **facebook ID** to add you to the test app [here](https://developers.facebook.com/apps/228027632918921/roles/roles/?business_id=549319917267066)

1. start ngrok

Expand Down Expand Up @@ -148,6 +148,11 @@ docker cp $cid:/app/fixture.json .
echo $PWD/fixture.json
```

```bash
# copy fixture.json from server to local
rsync -P -a <username>@captain.us-1.gooey.ai:/home/<username>/fixture.json .
```

```bash
# reset the database
./manage.py reset_db -c
Expand All @@ -166,3 +171,4 @@ echo $PWD/fixture.json
createdb -T template0 $PGDATABASE
pg_dump $SOURCE_DATABASE | psql -q $PGDATABASE
```

61 changes: 59 additions & 2 deletions bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
FeedbackComment,
CHATML_ROLE_ASSISSTANT,
SavedRun,
PublishedRun,
PublishedRunVersion,
Message,
Platform,
Feedback,
Conversation,
BotIntegration,
MessageAttachment,
)
from app_users.models import AppUser
from bots.tasks import create_personal_channels_for_all_members
from daras_ai.image_input import truncate_text_words
from daras_ai_v2.base import BasePage
from gooeysite.custom_actions import export_to_excel, export_to_csv
from gooeysite.custom_filters import (
related_json_field_summary,
Expand Down Expand Up @@ -91,13 +96,14 @@ class BotIntegrationAdmin(admin.ModelAdmin):
"updated_at",
"billing_account_uid",
"saved_run",
"published_run",
"analysis_run",
]
list_filter = ["platform"]

form = BotIntegrationAdminForm

autocomplete_fields = ["saved_run", "analysis_run"]
autocomplete_fields = ["saved_run", "published_run", "analysis_run"]

readonly_fields = [
"fb_page_access_token",
Expand All @@ -117,6 +123,7 @@ class BotIntegrationAdmin(admin.ModelAdmin):
"fields": [
"name",
"saved_run",
"published_run",
"billing_account_uid",
"user_language",
],
Expand Down Expand Up @@ -203,6 +210,38 @@ def view_analysis_results(self, bi: BotIntegration):
return html


@admin.register(PublishedRun)
class PublishedRunAdmin(admin.ModelAdmin):
list_display = [
"__str__",
"published_run_id",
"view_user",
"view_saved_run",
"created_at",
"updated_at",
]
list_filter = ["workflow"]
search_fields = ["workflow", "published_run_id"]
autocomplete_fields = ["saved_run", "created_by", "last_edited_by"]
readonly_fields = [
"open_in_gooey",
"created_at",
"updated_at",
]

def view_user(self, published_run: PublishedRun):
if published_run.created_by is None:
return None
return change_obj_url(published_run.created_by)

view_user.short_description = "View User"

def view_saved_run(self, published_run: PublishedRun):
return change_obj_url(published_run.saved_run)

view_saved_run.short_description = "View Saved Run"


@admin.register(SavedRun)
class SavedRunAdmin(admin.ModelAdmin):
list_display = [
Expand All @@ -214,9 +253,11 @@ class SavedRunAdmin(admin.ModelAdmin):
"run_time",
"updated_at",
"price",
"preview_input",
]
list_filter = ["workflow"]
search_fields = ["workflow", "example_id", "run_id", "uid"]
autocomplete_fields = ["parent_version"]

readonly_fields = [
"open_in_gooey",
Expand Down Expand Up @@ -248,6 +289,16 @@ 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.register(PublishedRunVersion)
class PublishedRunVersionAdmin(admin.ModelAdmin):
search_fields = ["id", "version_id", "published_run__published_run_id"]
autocomplete_fields = ["published_run", "saved_run", "changed_by"]


class LastActiveDeltaFilter(admin.SimpleListFilter):
title = Conversation.last_active_delta.short_description
Expand Down Expand Up @@ -360,6 +411,12 @@ class FeedbackInline(admin.TabularInline):
readonly_fields = ["created_at"]


class MessageAttachmentInline(admin.TabularInline):
model = MessageAttachment
extra = 0
readonly_fields = ["url", "metadata", "created_at"]


class AnalysisResultFilter(admin.SimpleListFilter):
title = "analysis_result"
parameter_name = "analysis_result"
Expand Down Expand Up @@ -419,7 +476,7 @@ class MessageAdmin(admin.ModelAdmin):
ordering = ["created_at"]
actions = [export_to_csv, export_to_excel]

inlines = [FeedbackInline]
inlines = [MessageAttachmentInline, FeedbackInline]

formfield_overrides = {
django.db.models.JSONField: {"widget": JSONEditorWidget},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Generated by Django 4.2.5 on 2023-11-22 13:45

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("files", "0001_initial"),
("bots", "0046_savedrun_bots_savedr_created_cb8e09_idx_and_more"),
]

operations = [
migrations.CreateModel(
name="MessageAttachment",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("url", models.TextField()),
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
],
options={
"ordering": ["created_at"],
},
),
migrations.AlterModelOptions(
name="feedback",
options={"get_latest_by": "created_at", "ordering": ["-created_at"]},
),
migrations.AddIndex(
model_name="feedback",
index=models.Index(
fields=["-created_at"], name="bots_feedba_created_fbd16a_idx"
),
),
migrations.AddField(
model_name="messageattachment",
name="message",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="attachments",
to="bots.message",
),
),
migrations.AddField(
model_name="messageattachment",
name="metadata",
field=models.ForeignKey(
blank=True,
default=None,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="message_attachments",
to="files.filemetadata",
),
),
]
18 changes: 18 additions & 0 deletions bots/migrations/0048_alter_messageattachment_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2023-11-25 12:38

import bots.custom_fields
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("bots", "0047_messageattachment_alter_feedback_options_and_more"),
]

operations = [
migrations.AlterField(
model_name="messageattachment",
name="url",
field=bots.custom_fields.CustomURLField(max_length=2048),
),
]
Loading

0 comments on commit a994673

Please sign in to comment.