Spaces:
Running
Running
Update modules/api.py
Browse files- modules/api.py +6 -6
modules/api.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# modules/api.py — VERSÃO FINAL OFICIAL:
|
| 2 |
"""
|
| 3 |
API wrapper Akira IA.
|
| 4 |
Prioridade: LOCAL (Hermes 7B finetuned + LoRA angolano) → Mistral API → Gemini → Fallback
|
|
@@ -120,11 +120,11 @@ class LLMManager:
|
|
| 120 |
except Exception as e:
|
| 121 |
logger.warning(f"Hermes local falhou: {e}")
|
| 122 |
|
| 123 |
-
# 2. MISTRAL API
|
| 124 |
elif provider == 'mistral' and self.mistral_client:
|
| 125 |
try:
|
| 126 |
resp = self.mistral_client.chat.complete(
|
| 127 |
-
model=self.config.MISTRAL_MODEL #
|
| 128 |
messages=messages,
|
| 129 |
temperature=self.config.TOP_P,
|
| 130 |
max_tokens=60
|
|
@@ -142,7 +142,7 @@ class LLMManager:
|
|
| 142 |
gemini_hist = []
|
| 143 |
for msg in messages[1:]:
|
| 144 |
role = "user" if msg["role"] == "user" else "model"
|
| 145 |
-
gemini_hist.append({"role": role, "parts": [{"text": msg["content"
|
| 146 |
resp = self.gemini_model.generate_content(
|
| 147 |
gemini_hist,
|
| 148 |
generation_config=genai.GenerationConfig(
|
|
@@ -226,7 +226,7 @@ class AkiraAPI:
|
|
| 226 |
resposta = self._generate_response(prompt, contexto.obter_historico_para_llm(), is_privileged)
|
| 227 |
contexto.atualizar_contexto(mensagem, resposta)
|
| 228 |
|
| 229 |
-
#
|
| 230 |
try:
|
| 231 |
db = Database(getattr(self.config, 'DB_PATH', 'akira.db'))
|
| 232 |
trainer = Treinamento(db)
|
|
@@ -270,7 +270,7 @@ class AkiraAPI:
|
|
| 270 |
analise: Dict, contexto: Contexto, is_blocking: bool,
|
| 271 |
is_privileged: bool = False, is_reply: bool = False) -> str:
|
| 272 |
historico_raw = contexto.obter_historico()
|
| 273 |
-
historico_texto = '\n'.join([f"Usuário: {m[0]}\nAkira: {m[1]}" for m in historico_raw[-10:]])
|
| 274 |
now = datetime.datetime.now()
|
| 275 |
data_hora = now.strftime('%d/%m/%Y %H:%M')
|
| 276 |
|
|
|
|
| 1 |
+
# modules/api.py — VERSÃO FINAL OFICIAL: SyntaxError MORTO, AKIRA VIVA, ANGOLA NO TOPO!
|
| 2 |
"""
|
| 3 |
API wrapper Akira IA.
|
| 4 |
Prioridade: LOCAL (Hermes 7B finetuned + LoRA angolano) → Mistral API → Gemini → Fallback
|
|
|
|
| 120 |
except Exception as e:
|
| 121 |
logger.warning(f"Hermes local falhou: {e}")
|
| 122 |
|
| 123 |
+
# 2. MISTRAL API — VÍRGULA CORRIGIDA AQUI!
|
| 124 |
elif provider == 'mistral' and self.mistral_client:
|
| 125 |
try:
|
| 126 |
resp = self.mistral_client.chat.complete(
|
| 127 |
+
model=self.config.MISTRAL_MODEL, # ← VÍRGULA ADICIONADA! SyntaxError MORTO!
|
| 128 |
messages=messages,
|
| 129 |
temperature=self.config.TOP_P,
|
| 130 |
max_tokens=60
|
|
|
|
| 142 |
gemini_hist = []
|
| 143 |
for msg in messages[1:]:
|
| 144 |
role = "user" if msg["role"] == "user" else "model"
|
| 145 |
+
gemini_hist.append({"role": role, "parts": [{"text": msg["content"}]})
|
| 146 |
resp = self.gemini_model.generate_content(
|
| 147 |
gemini_hist,
|
| 148 |
generation_config=genai.GenerationConfig(
|
|
|
|
| 226 |
resposta = self._generate_response(prompt, contexto.obter_historico_para_llm(), is_privileged)
|
| 227 |
contexto.atualizar_contexto(mensagem, resposta)
|
| 228 |
|
| 229 |
+
# REGISTRO DE INTERAÇÃO
|
| 230 |
try:
|
| 231 |
db = Database(getattr(self.config, 'DB_PATH', 'akira.db'))
|
| 232 |
trainer = Treinamento(db)
|
|
|
|
| 270 |
analise: Dict, contexto: Contexto, is_blocking: bool,
|
| 271 |
is_privileged: bool = False, is_reply: bool = False) -> str:
|
| 272 |
historico_raw = contexto.obter_historico()
|
| 273 |
+
historico_texto = '\n'.join([f"Usuário: {m[0]}\nAkira: {m[1]}" for m in historico_raw[-10:]])
|
| 274 |
now = datetime.datetime.now()
|
| 275 |
data_hora = now.strftime('%d/%m/%Y %H:%M')
|
| 276 |
|