From 05d8baffb1efe47ffca73fe7a0123306fad3ca48 Mon Sep 17 00:00:00 2001 From: Francis Secada Date: Tue, 21 Jan 2025 22:36:11 -0500 Subject: [PATCH] WIP: adding `pygentic.css` for css spinner element; patching other components. Result objects not loading correctly and messages not stacking --- src/backend/core/consts.py | 4 +- src/backend/core/tools.py | 4 +- src/frontend/static/css/pygentic_ai.css | 31 ++++++++++++ src/frontend/static/favicon.ico | Bin 0 -> 3890 bytes .../templates/components/main/header.html | 4 ++ .../components/main/style_sheets.html | 2 + .../components/snippets/Spinner.jinja | 4 ++ .../components/snippets/StatusResult.jinja | 3 +- src/frontend/templates/home.html | 20 +++----- src/frontend/templates/result.html | 6 +-- src/frontend/templates/status.html | 45 +++++++++++------- 11 files changed, 85 insertions(+), 38 deletions(-) create mode 100644 src/frontend/static/css/pygentic_ai.css create mode 100644 src/frontend/static/favicon.ico create mode 100644 src/frontend/templates/components/snippets/Spinner.jinja diff --git a/src/backend/core/consts.py b/src/backend/core/consts.py index 0f84cf9..b86c069 100644 --- a/src/backend/core/consts.py +++ b/src/backend/core/consts.py @@ -1,4 +1,6 @@ -AI_MODEL = "gpt-4o" +from backend.utils import get_val + +AI_MODEL = get_val("OPENAI_MODEL", "gpt-4o") default_system_prompt = """ You are an advanced and intelligent AI assistant specializing in generating comprehensive and detailed SWOT analyses for a variety of scenarios, topics, diff --git a/src/backend/core/tools.py b/src/backend/core/tools.py index c2b3d61..b6f1a7b 100644 --- a/src/backend/core/tools.py +++ b/src/backend/core/tools.py @@ -1,3 +1,5 @@ +from pprint import pformat + import httpx from bs4 import BeautifulSoup as soup from pydantic_ai import RunContext @@ -117,7 +119,7 @@ async def run_agent( f"Perform a comprehensive SWOT analysis for this product: {url}", deps=deps, ) - logger.info(f"Agent Result: {result}") + logger.info(f"Agent Result: {pformat(result.data)}") if deps.update_status_func: await deps.update_status_func(deps.request, "Analysis Complete") diff --git a/src/frontend/static/css/pygentic_ai.css b/src/frontend/static/css/pygentic_ai.css new file mode 100644 index 0000000..a8b50a8 --- /dev/null +++ b/src/frontend/static/css/pygentic_ai.css @@ -0,0 +1,31 @@ +/* Spinner Wrapper with Overlay Effect */ +.spinner-wrapper { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: rgba(255, 255, 255, 0.7); /* Light overlay effect */ + display: flex; + justify-content: center; + align-items: center; + z-index: 50; +} + +.loader { + border: 4px solid rgba(0, 0, 0, 0.1); /* Light gray */ + border-top: 4px solid #3273dc; /* Bulma primary color */ + border-radius: 50%; + width: 40px; + height: 40px; + animation: spin 0.8s linear infinite; +} + +@keyframes spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/src/frontend/static/favicon.ico b/src/frontend/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..218a1fbf6cbd59ee4d77b657c3e6b67295cecb32 GIT binary patch literal 3890 zcmcIn3s96*6uw}9yR3`g1CUiwpil`#)O>?7HskvdScyFZ1QCfx(kPkA0@5g2LykE$ zy}$=*Dh6YjqsgG+D*};)mIZVO9Y;bo@wLnD*SY_)u1jpY+VnFY_ndqF`M-OM+;DXl@z#uMyAby&{wy6yf|~G0q+m;Zl(pr)clze1rY4J3ny@ zI@gK;1!Wj`@G=JOzaZG2XKp?-Ki7b3uWOJ1O28EO|2lqL8_eUG01>ey;J&3(gqnXOEmTC!q$s z{|0;7p)jvE^t=|9^ymDMi4e_L@Spfw%AMiwV~^Z);=dt*;-nZu2H9ipr&jot#Q#4QawAs{d*MeWKFf z`Af@_86bWw&Hp^}sW*9AmDdW5(&d3hDJ2dm^_i4r&|r6}q%@NTo5wnp5}m4k(&Z7g z4^{MC-rE9((m94w4+tRJxX)L*r&|J*2sSaATji~TgD%~6ZM=M23hQurRMz6ZA+kW1 zAF&5I0<2+K0Zu08qrW+;$t!8^v+n3!rYGQNJ42D$gr|KTFQWLqreJmAwvLB!nZT;- ze@9%F5Py)e17RjcbE~A?Szgrj?E@_gJ1-F~GJJM{L0-g=SI)5eH-;mv49AFnZ^Hy6 zZdYSvrXFv+uR_Fo)p#wj3K2;)1O>v$4<~$J_={K+e*ueDm19Z5uZYfg zWHY~@LDxBo?=h6zH{cl6gTr`6WB#$EZ7kP62Z;X|h@+K*+kB7m7UH(%Z{#m(W7tv3 z5SPoaE}x zt3C7c+d)49n6PW=Aum zebcl4yw_%g=L`8RNw`Ai7y&1dD;CC`gZq$47#EgdE5Bj>yLx}$4TkVk(jbIk>Jr23 z_1OQU|Fng>5imIkQJe20C^Q`}1xMlCjcU>(3&CNVsRwjM{Vm@ACGFCbqPup&d>MP3 z&j9cH!*@)%8)Jn{V{awq-dFS4i=q1^My?V1EGAPU_`-gsmhPTMhWXrrj?_;u-Tc-w zc_-8|Pr8HCirbxYjG#Lyr$kM7YLCar&n&*<8=9P}k4W5#ErcA7HC=0WoBK(*h}!Tu z#3n{_>v(&AcBqZ9y? {% block title %}Pygentic AI{% endblock title %} + {% block head_content %} {% endblock head_content %} {% include 'components/main/style_sheets.html' %} \ No newline at end of file diff --git a/src/frontend/templates/components/main/style_sheets.html b/src/frontend/templates/components/main/style_sheets.html index 7185789..af23842 100644 --- a/src/frontend/templates/components/main/style_sheets.html +++ b/src/frontend/templates/components/main/style_sheets.html @@ -1,5 +1,7 @@ + +
+ \ No newline at end of file diff --git a/src/frontend/templates/components/snippets/StatusResult.jinja b/src/frontend/templates/components/snippets/StatusResult.jinja index 5e196bf..c3946ae 100644 --- a/src/frontend/templates/components/snippets/StatusResult.jinja +++ b/src/frontend/templates/components/snippets/StatusResult.jinja @@ -1,11 +1,12 @@ {# def div_class: str, + header_content: str = '' #}
-

+

{{ header_content }}

{{ content }} diff --git a/src/frontend/templates/home.html b/src/frontend/templates/home.html index 7e56f23..0d0ec72 100644 --- a/src/frontend/templates/home.html +++ b/src/frontend/templates/home.html @@ -9,6 +9,7 @@
+

Search Here

-
@@ -36,14 +36,14 @@ id="status">
- -{% endblock js_content %} \ No newline at end of file +{% endblock content %} \ No newline at end of file diff --git a/src/frontend/templates/result.html b/src/frontend/templates/result.html index a5f7feb..611a5f7 100644 --- a/src/frontend/templates/result.html +++ b/src/frontend/templates/result.html @@ -1,12 +1,12 @@ {% if result %} - -
+

Analysis Complete

- {% for cat in results %} + {% for cat in result %}
    diff --git a/src/frontend/templates/status.html b/src/frontend/templates/status.html index 947ff35..3cfe60d 100644 --- a/src/frontend/templates/status.html +++ b/src/frontend/templates/status.html @@ -1,21 +1,30 @@ {% if messages %} -
    - {% for message in messages %} - {% set is_error = message.startswith('Error:') %} - {% set is_loading = loop.last and not result %} - {% set is_tool_message = message.startswith('Using tool') %} -
    - {% set bg_color = 'danger' if is_error else ('dark' if is_loading else "info") %} - {% if is_error %} - {% set content = message.split('body:', 1)[1] %} - {% elif is_tool_message %} - {% set content = message.split('', 2)[2].split('...', 1)[1] %} - {% else %} - {% set content = message %} - {% endif %} - {{ message }} +
    +
    + {% for message in messages %} + {% set is_error = message.startswith('Error:') %} + {% set is_loading = loop.last and not result %} + {% set is_tool_message = message.startswith('Using tool') %} +
    + {% set bg_color = 'danger' if is_error else ('dark' if is_loading else + "info") %} + {% if is_error %} + {% set header_content, content = message.split('body:', 1) %} + {% elif is_tool_message %} + {% set header_content, content = message.split(' ', 2)[2].split('...', 1) %} + {% elif is_loading %} + {% set content = message %} + {% set header_content = 'In Progress' %} + {% else %} + {% set content = message %} + {% set header_content = 'Complete' %} + {% endif %} + {{ message }} + +
    + {% endfor %}
    - {% endfor %} -
    +
{% endif %} \ No newline at end of file