WIP: completed alpha build of frontend; hx action triggering GET instead of POST request

This commit is contained in:
Francis Secada 2025-01-21 16:16:05 -05:00
parent 1e371613dc
commit b7a466c714
11 changed files with 137 additions and 25 deletions

View File

@ -18,7 +18,7 @@ services:
- traefik.enable=true
- traefik.docker.network=proxy
- traefik.http.routers.pygentic_ai.entrypoints=websecure
- traefik.http.routers.pygentic_ai.rule=Host(`rankedjobsmicroservice.francissecada.com`)
- traefik.http.routers.pygentic_ai.rule=Host(`pygenticai.francissecada.com`)
- traefik.http.routers.pygentic_ai.tls=true
healthcheck:
test: curl --fail http://localhost:5051/ || exit 1
@ -48,7 +48,7 @@ services:
- traefik.enable=true
- traefik.docker.network=proxy
- traefik.http.routers.celery_ranked_jobs.entrypoints=websecure
- traefik.http.routers.celery_ranked_jobs.rule=Host(`celery.rankedjobsmicroservice.francissecada.com`)
- traefik.http.routers.celery_ranked_jobs.rule=Host(`celery.pygenticai.francissecada.com`)
networks:
- proxy
depends_on:

View File

@ -191,7 +191,7 @@ markupsafe==3.0.2
# jinjax
mdurl==0.1.2
# via markdown-it-py
mistralai==1.3.1
mistralai==1.4.0
# via pydantic-ai-slim
mypy-extensions==1.0.0
# via typing-inspect

View File

@ -139,7 +139,7 @@ dependencies = [
"markdown-it-py==3.0.0",
"markupsafe==3.0.2",
"mdurl==0.1.2",
"mistralai==1.3.1",
"mistralai==1.4.0",
"mypy-extensions==1.0.0",
"openai==1.59.9",
"opentelemetry-api==1.29.0",

View File

@ -2,7 +2,8 @@
form_id: str,
action: str,
target: str,
method: str = 'GET'
method: str = 'GET',
trigger: str = 'submit'
#}
<div class="container">
<form id="{{ form_id }}"
@ -15,14 +16,8 @@ method: str = 'GET'
{% elif method.lower() == 'delete' %}
hx-delete={{ action }}
{% endif %}
hx-trigger={{ trigger }}
hx-target="#{{ target }}">
{{ content }}
<div class="field">
<div class="control">
<input type="submit"
class="button is-success"
value="submit">
</div>
</div>
</form>
</div>

View File

@ -0,0 +1,12 @@
{# def
result,
#}
<li>
<span class='icon'>
{{ content }}
</span>
<span>
{{ result }}
</span>
</li>

View File

@ -0,0 +1,13 @@
{# def
div_class: str,
#}
<article class="message is-{{ div_class }}">
<div class="message-header">
<p></p>
</div>
<div class="message-body">
{{ content }}
</div>
</article>

View File

@ -0,0 +1,33 @@
<section class="section">
<div class="container"
id="result-container">
<h2 class="subtitle is-2">Analysis Complete</h2>
<div class="fixed-grid">
<div class="grid">
{% for cat in results %}
<div class="cell">
<div class="content">
<ul>
{% for result in cat %}
<ResultEntry result=result>
{% if cat == 'strengths' %}
<i class="fas fa-solid fa-arrow-up"></i>
{% elif cat == 'weaknesses' %}
<i class="fas fa-solid fa-arrow-down"></i>
{% elif cat == 'opportunities' %}
<i class="fas fa-regular fa-lightbulb"></i>
{% else %}
<i
class="fas fa-solid fa-triangle-exclamation"></i>
{% endif %}
</ResultEntry>
</ul>
</div>
</div>
{% endfor %}
{% endfor %}
</div>
</div>
</div>
</section>

View File

@ -0,0 +1,22 @@
{% if messages %}
<div id="status-container"
class="container">
{% 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') %}
<div class="box">
{% 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 %}
<StatusResult :div_class=bg_color>{{ message }}</StatusResult>
</div>
{% endfor %}
</div>
{% endif %}

View File

@ -5,16 +5,53 @@
<p class="title">SWOT ANALYZER</p>
<p class="subtitle">Strengths, Weaknesses, Opportunities and Threats
breakdown, courtesy of Generative AI-driven insights.</p>
<p>Try it out now!</p>
</div>
</section>
<div class="container">
<h1 class="title">Search Here</h1>
<Search form_id="swotSearch"
action="/analyze"
target="swotAnalysis"
method="post"></Search>
</div>
<section class="section">
<div class="container">
<h1 class="title">Search Here</h1>
<Search form_id="swotSearch"
action="/analyze"
target="status"
method="post">
<div class="field mt-1 pt-1">
<div class="control">
<button type="submit"
class="button is-success"
hx-on:click="
const [status, result] = ['#status', '#result'].map(id => document.querySelector(id));
status.style.display = 'block';
result.style.display = 'none';
">Analyze</button>
</div>
</div>
</Search>
</div>
</section>
<section class="section">
<div class="container"
id="swotAnalysis">
<div class="box"
id="status"
hx-get='/status'
hx-trigger='load, every 1s'
hx-swap='innerHTML transition: false'
style="display: none">
</div>
<div class="box"
id="result"
hx-get='/result'
hx-trigger="load, every 1s[!this.querySelector('#result-container') || this.style.display === 'none']"
hx-swap='innerHTML'
hx-on:after-request="
if(this.innerHTML.trim().length > 0) {
const statusDiv = document.querySelector(#status);
if (statusDiv) statusDiv.style.display = 'none';
this.style.display = 'block'
}
">
</div>
</div>
</section>
{% endblock content %}

8
uv.lock generated
View File

@ -341,7 +341,7 @@ requires-dist = [
{ name = "markdown-it-py", specifier = "==3.0.0" },
{ name = "markupsafe", specifier = "==3.0.2" },
{ name = "mdurl", specifier = "==0.1.2" },
{ name = "mistralai", specifier = "==1.3.1" },
{ name = "mistralai", specifier = "==1.4.0" },
{ name = "mypy-extensions", specifier = "==1.0.0" },
{ name = "openai", specifier = "==1.59.9" },
{ name = "opentelemetry-api", specifier = "==1.29.0" },
@ -1971,7 +1971,7 @@ wheels = [
[[package]]
name = "mistralai"
version = "1.3.1"
version = "1.4.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "eval-type-backport" },
@ -1981,9 +1981,9 @@ dependencies = [
{ name = "python-dateutil" },
{ name = "typing-inspect" },
]
sdist = { url = "https://files.pythonhosted.org/packages/2f/50/59669ee8d21fd27a4f887148b1efb19d9be5ed22ec19c8e6eb842407ac0f/mistralai-1.3.1.tar.gz", hash = "sha256:1c30385656393f993625943045ad20de2aff4c6ab30fc6e8c727d735c22b1c08", size = 133338 }
sdist = { url = "https://files.pythonhosted.org/packages/f1/ca/9aedf3142b2f989e1e5992ba913c96ca3e3459259aa40d870dfc4007be23/mistralai-1.4.0.tar.gz", hash = "sha256:b8a09eda1864cba02ebf70439ca1925025e073d3f6f3eeccfdd146ad0f2260fb", size = 125775 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/1a/b4/a76b6942b78383d5499f776d880a166296542383f6f952feeef96d0ea692/mistralai-1.3.1-py3-none-any.whl", hash = "sha256:35e74feadf835b7d2145095114b9cf3ba86c4cf1044f28f49b02cd6ddd0a5733", size = 261271 },
{ url = "https://files.pythonhosted.org/packages/1e/9b/67647d4d384016e2941765c5e860a89c83341546af098bb197763492a354/mistralai-1.4.0-py3-none-any.whl", hash = "sha256:74a8b8f5b737b199c83ccc89721cb82a71e8b093b38b27c99d38cbcdf550668c", size = 262460 },
]
[[package]]