-
Notifications
You must be signed in to change notification settings - Fork 5
Bot builder in sidebar #830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
033b8b0
cf576c7
380269c
33f0be9
836d551
80bf66f
ece5e7f
6125a44
fcad662
65119e1
e32ed67
47b8c6e
2078fc3
b023d9d
8ddf643
d609211
34cf1e7
47d5e2a
b0cfe27
3df1ff4
b337a18
efbceda
689d02f
6e61641
a0a2277
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,17 +2,105 @@ | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| from bots.models import BotIntegration | ||||||||||||||||||||||||
| from daras_ai_v2 import settings | ||||||||||||||||||||||||
| from widgets.sidebar import SidebarRef, use_sidebar | ||||||||||||||||||||||||
| from starlette.requests import Request | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| from workspaces.models import Workspace | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def render_gooey_builder(page_slug: str, builder_state: dict): | ||||||||||||||||||||||||
| DEFAULT_GOOEY_BUILDER_PHOTO_URL = "https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/63bdb560-b891-11f0-b9bc-02420a00014a/generate-ai-abstract-symbol-artificial-intelligence-colorful-stars-icon-vector%201.jpg" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def can_launch_gooey_builder( | ||||||||||||||||||||||||
| request: Request, current_workspace: Workspace | None | ||||||||||||||||||||||||
| ) -> bool: | ||||||||||||||||||||||||
| if not request.user or request.user.is_anonymous: | ||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||
| if request.user.is_admin(): | ||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||
| return current_workspace and current_workspace.enable_bot_builder | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def render_gooey_builder_launcher( | ||||||||||||||||||||||||
| request: Request, | ||||||||||||||||||||||||
| current_workspace: Workspace | None = None, | ||||||||||||||||||||||||
| is_fab_button: bool = False, | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| if not can_launch_gooey_builder(request, current_workspace): | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| sidebar_ref = use_sidebar("builder-sidebar", request.session) | ||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||
| bi = BotIntegration.objects.get(id=settings.GOOEY_BUILDER_INTEGRATION_ID) | ||||||||||||||||||||||||
| except BotIntegration.DoesNotExist: | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
| branding = bi.get_web_widget_branding() | ||||||||||||||||||||||||
| photo_url = branding.get( | ||||||||||||||||||||||||
| "photoUrl", | ||||||||||||||||||||||||
| DEFAULT_GOOEY_BUILDER_PHOTO_URL, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| branding["showPoweredByGooey"] = False | ||||||||||||||||||||||||
| if is_fab_button: | ||||||||||||||||||||||||
| with gui.styled("& .gooey-builder-open-button:hover { scale: 1.2; }"): | ||||||||||||||||||||||||
| with gui.div( | ||||||||||||||||||||||||
| className="w-100 position-absolute", | ||||||||||||||||||||||||
| style={"bottom": "24px", "left": "16px", "zIndex": "1000"}, | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| gooey_builder_open_button = gui.button( | ||||||||||||||||||||||||
| label=f"<img src='{photo_url}' style='width: 56px; height: 56px; border-radius: 50%;' />", | ||||||||||||||||||||||||
| className="btn btn-secondary border-0 d-none d-md-block p-0 gooey-builder-open-button", | ||||||||||||||||||||||||
| style={ | ||||||||||||||||||||||||
| "width": "56px", | ||||||||||||||||||||||||
| "height": "56px", | ||||||||||||||||||||||||
| "borderRadius": "50%", | ||||||||||||||||||||||||
| "boxShadow": "#0000001a 0 1px 4px, #0003 0 2px 12px", | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| if gooey_builder_open_button: | ||||||||||||||||||||||||
| sidebar_ref.set_open(True) | ||||||||||||||||||||||||
| raise gui.RerunException() | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| gooey_builder_mobile_open_button = gui.button( | ||||||||||||||||||||||||
| label=f"<img src='{photo_url}' style='width: 36px; height: 36px; border-radius: 50%;' />", | ||||||||||||||||||||||||
| className="border-0 m-0 btn btn-secondary rounded-pill d-md-none gooey-builder-open-button p-0", | ||||||||||||||||||||||||
| style={ | ||||||||||||||||||||||||
| "width": "36px", | ||||||||||||||||||||||||
| "height": "36px", | ||||||||||||||||||||||||
| "borderRadius": "50%", | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| if gooey_builder_mobile_open_button: | ||||||||||||||||||||||||
| sidebar_ref.set_mobile_open(True) | ||||||||||||||||||||||||
| raise gui.RerunException() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def render_gooey_builder_inline( | ||||||||||||||||||||||||
| page_slug: str, builder_state: dict, sidebar_ref: SidebarRef | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| if not settings.GOOEY_BUILDER_INTEGRATION_ID: | ||||||||||||||||||||||||
| return | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # hidden button to trigger the onClose event passed in the widget config | ||||||||||||||||||||||||
| gui.tag( | ||||||||||||||||||||||||
| "button", | ||||||||||||||||||||||||
| type="submit", | ||||||||||||||||||||||||
| name="onCloseGooeyBuilder", | ||||||||||||||||||||||||
| value="yes", | ||||||||||||||||||||||||
| hidden=True, | ||||||||||||||||||||||||
| id="onClose", | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if gui.session_state.pop("onCloseGooeyBuilder", None): | ||||||||||||||||||||||||
| sidebar_ref.set_open(False) | ||||||||||||||||||||||||
| sidebar_ref.set_mobile_open(False) | ||||||||||||||||||||||||
| raise gui.RerunException() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| bi = BotIntegration.objects.get(id=settings.GOOEY_BUILDER_INTEGRATION_ID) | ||||||||||||||||||||||||
| config = bi.get_web_widget_config( | ||||||||||||||||||||||||
| hostname="gooey.ai", target="#gooey-builder-embed" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
Comment on lines
97
to
100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing exception handling for BotIntegration lookup. Unlike 🔧 Proposed fix to add exception handling- bi = BotIntegration.objects.get(id=settings.GOOEY_BUILDER_INTEGRATION_ID)
+ try:
+ bi = BotIntegration.objects.get(id=settings.GOOEY_BUILDER_INTEGRATION_ID)
+ except BotIntegration.DoesNotExist:
+ return
config = bi.get_web_widget_config(
hostname="gooey.ai", target="#gooey-builder-embed"
)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| config["mode"] = "inline" | ||||||||||||||||||||||||
| config["showRunLink"] = True | ||||||||||||||||||||||||
| branding = config.setdefault("branding", {}) | ||||||||||||||||||||||||
| branding["showPoweredByGooey"] = False | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -25,7 +113,7 @@ def render_gooey_builder(page_slug: str, builder_state: dict): | |||||||||||||||||||||||
| gui.html( | ||||||||||||||||||||||||
| # language=html | ||||||||||||||||||||||||
| f""" | ||||||||||||||||||||||||
| <div id="gooey-builder-embed"></div> | ||||||||||||||||||||||||
| <div id="gooey-builder-embed" style="height: 100%"></div> | ||||||||||||||||||||||||
| <script id="gooey-builder-embed-script" src="{settings.WEB_WIDGET_LIB}"></script> | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
@@ -42,8 +130,12 @@ def render_gooey_builder(page_slug: str, builder_state: dict): | |||||||||||||||||||||||
| GooeyEmbed.setGooeyBuilderVariables = (value) => { | ||||||||||||||||||||||||
| config.payload.variables = value; | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| GooeyEmbed.setGooeyBuilderVariables(variables); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| config.onClose = function() { | ||||||||||||||||||||||||
| document.getElementById("onClose").click(); | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| GooeyEmbed.mount(config); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing exception handling for BotIntegration lookup.
Unlike
render_gooey_builder_launcher(lines 32-35), this function doesn't catchBotIntegration.DoesNotExist. If the integration is missing, this will raise an unhandled exception.Suggested fix
🤖 Prompt for AI Agents