@danhachuel/thunderbolt 0.3.16 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/main.py +18 -10
- package/package.json +1 -1
package/app/main.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import hashlib
|
|
4
4
|
import json
|
|
5
5
|
import re
|
|
6
|
+
from contextlib import nullcontext
|
|
6
7
|
from datetime import date, datetime
|
|
7
8
|
import sys
|
|
8
9
|
import uuid
|
|
@@ -3752,7 +3753,7 @@ def _persist_llm_cards(settings: dict[str, Any], cards: list[dict[str, Any]], ac
|
|
|
3752
3753
|
return updated
|
|
3753
3754
|
|
|
3754
3755
|
|
|
3755
|
-
def _render_llm_card(settings: dict[str, Any], cards: list[dict[str, Any]], index: int) -> None:
|
|
3756
|
+
def _render_llm_card(settings: dict[str, Any], cards: list[dict[str, Any]], index: int, *, embedded: bool = False) -> None:
|
|
3756
3757
|
card = normalize_llm_card(cards[index], index)
|
|
3757
3758
|
cards[index] = card
|
|
3758
3759
|
card_id = str(card["id"])
|
|
@@ -3766,7 +3767,8 @@ def _render_llm_card(settings: dict[str, Any], cards: list[dict[str, Any]], inde
|
|
|
3766
3767
|
with header_cols[1]:
|
|
3767
3768
|
status_kind, status_label = _llm_card_config_status(card)
|
|
3768
3769
|
_api_status_badge(status_label, status_kind)
|
|
3769
|
-
|
|
3770
|
+
card_form = nullcontext() if embedded else st.form(f"llm_card_form_{card_id}")
|
|
3771
|
+
with card_form:
|
|
3770
3772
|
key_col, model_col = st.columns(2)
|
|
3771
3773
|
with key_col:
|
|
3772
3774
|
api_key = card.get("api_key", "")
|
|
@@ -3806,9 +3808,9 @@ def _render_llm_card(settings: dict[str, Any], cards: list[dict[str, Any]], inde
|
|
|
3806
3808
|
with action_col:
|
|
3807
3809
|
action_buttons = st.columns(2)
|
|
3808
3810
|
with action_buttons[0]:
|
|
3809
|
-
refresh_clicked = st.form_submit_button("Consultar modelos", use_container_width=True)
|
|
3811
|
+
refresh_clicked = st.form_submit_button("Consultar modelos", use_container_width=True, key=f"llm_card_{card_id}_refresh")
|
|
3810
3812
|
with action_buttons[1]:
|
|
3811
|
-
test_clicked = st.form_submit_button("Testar chamada API", use_container_width=True)
|
|
3813
|
+
test_clicked = st.form_submit_button("Testar chamada API", use_container_width=True, key=f"llm_card_{card_id}_test")
|
|
3812
3814
|
|
|
3813
3815
|
extra_values: dict[str, str] = {}
|
|
3814
3816
|
if definition.extra_fields:
|
|
@@ -3839,10 +3841,10 @@ def _render_llm_card(settings: dict[str, Any], cards: list[dict[str, Any]], inde
|
|
|
3839
3841
|
key=f"llm_card_{card_id}_telegram",
|
|
3840
3842
|
)
|
|
3841
3843
|
|
|
3842
|
-
save_clicked = st.form_submit_button("Salvar", type="primary", use_container_width=True)
|
|
3844
|
+
save_clicked = st.form_submit_button("Salvar", type="primary", use_container_width=True, key=f"llm_card_{card_id}_save")
|
|
3843
3845
|
remove_clicked = False
|
|
3844
3846
|
if definition.code != "openai":
|
|
3845
|
-
remove_clicked = st.form_submit_button("Remover cartão", use_container_width=True)
|
|
3847
|
+
remove_clicked = st.form_submit_button("Remover cartão", use_container_width=True, key=f"llm_card_{card_id}_remove")
|
|
3846
3848
|
|
|
3847
3849
|
edited = dict(card)
|
|
3848
3850
|
edited.update({"api_key": str(api_key or "").strip(), "model": str(model or "").strip(), "base_url": str(base_url or "").strip(), "enabled": bool(enabled), "telegram_llm": bool(telegram_llm), **extra_values})
|
|
@@ -3883,7 +3885,7 @@ def _render_llm_card(settings: dict[str, Any], cards: list[dict[str, Any]], inde
|
|
|
3883
3885
|
st.error(f"Último teste: {saved_test['message']}")
|
|
3884
3886
|
|
|
3885
3887
|
|
|
3886
|
-
def render_llm_provider_cards(settings: dict[str, Any]) -> None:
|
|
3888
|
+
def render_llm_provider_cards(settings: dict[str, Any], *, embedded: bool = False) -> None:
|
|
3887
3889
|
"""Renderizar cartões LLM fora da form global para permitir acções por cartão."""
|
|
3888
3890
|
migrated, changed = ensure_llm_provider_cards(settings)
|
|
3889
3891
|
cards = [dict(item) for item in migrated.get(LLM_CARDS_KEY, [])]
|
|
@@ -3893,7 +3895,7 @@ def render_llm_provider_cards(settings: dict[str, Any]) -> None:
|
|
|
3893
3895
|
with st.expander("LLM — providers e modelos", expanded=False):
|
|
3894
3896
|
st.caption("Configure cada provider num cartão independente. Pode repetir o mesmo provider para manter várias API keys; o cartão activo é usado pela geração de conteúdo.")
|
|
3895
3897
|
for index in range(len(cards)):
|
|
3896
|
-
_render_llm_card(settings, cards, index)
|
|
3898
|
+
_render_llm_card(settings, cards, index, embedded=embedded)
|
|
3897
3899
|
st.divider()
|
|
3898
3900
|
st.markdown("**Adicionar provider LLM**")
|
|
3899
3901
|
provider_codes = [item.code for item in LLM_PROVIDER_CATALOG]
|
|
@@ -3903,7 +3905,12 @@ def render_llm_provider_cards(settings: dict[str, Any]) -> None:
|
|
|
3903
3905
|
format_func=lambda value: ui_text(provider_definition(value).label, current_ui_language()),
|
|
3904
3906
|
key="llm_new_provider_choice",
|
|
3905
3907
|
)
|
|
3906
|
-
|
|
3908
|
+
add_provider_clicked = (
|
|
3909
|
+
st.form_submit_button("Configurar Novo Provedor LLM", type="primary", use_container_width=True, key="add_llm_provider_card")
|
|
3910
|
+
if embedded
|
|
3911
|
+
else st.button("Configurar Novo Provedor LLM", type="primary", use_container_width=True, key="add_llm_provider_card")
|
|
3912
|
+
)
|
|
3913
|
+
if add_provider_clicked:
|
|
3907
3914
|
new_card = new_llm_card(provider_to_add, card_id=f"llm-{provider_to_add}-{uuid.uuid4().hex[:8]}")
|
|
3908
3915
|
cards.append(new_card)
|
|
3909
3916
|
_persist_llm_cards(settings, cards, str(settings.get(LLM_ACTIVE_CARD_KEY) or DEFAULT_LLM_CARD_ID))
|
|
@@ -3933,7 +3940,6 @@ def render_settings():
|
|
|
3933
3940
|
st.subheader("API Keys")
|
|
3934
3941
|
port = st.number_input("Porta Streamlit", 1, 65535, int(settings.get("port", 3030)))
|
|
3935
3942
|
moneyprinter_path = st.text_input("Pasta do motor de vídeo", settings.get("moneyprinter_path", ""), key="settings_moneyprinter_path")
|
|
3936
|
-
render_llm_provider_cards(settings)
|
|
3937
3943
|
with st.form("settings_form"):
|
|
3938
3944
|
with st.expander("Niche Finder — Kaggle", expanded=False):
|
|
3939
3945
|
st.caption("O dataset permanece no Kaggle. O Thunderbolt usa estas credenciais apenas para publicar/executar a kernel e obter os resultados pequenos da análise.")
|
|
@@ -3959,6 +3965,8 @@ def render_settings():
|
|
|
3959
3965
|
apify_run_timeout = st.number_input("Limite da execução (s)", min_value=30, max_value=7200, value=int(settings.get("apify_run_timeout_seconds", 900)), step=30)
|
|
3960
3966
|
_render_credential_status(apify_api_token)
|
|
3961
3967
|
|
|
3968
|
+
render_llm_provider_cards(settings, embedded=True)
|
|
3969
|
+
|
|
3962
3970
|
with st.expander("Nano Banana — geração de thumbnails", expanded=False):
|
|
3963
3971
|
st.caption("A Nano Banana gera a imagem final das thumbnails a partir da variante escolhida. A chave é guardada apenas no storage local e é distinta da chave do Gemini usado como LLM textual.")
|
|
3964
3972
|
nano_cols = st.columns(2)
|
package/package.json
CHANGED