Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ce11d0bfe | ||
|
|
b3d92558fc |
No files matched your search
+4
-4
@@ -10,20 +10,20 @@ def get_ai_response(messages: list, settings: SystemSettings) -> str:
|
|||||||
formatted_messages = [{"role": msg.role, "content": msg.content} for msg in messages]
|
formatted_messages = [{"role": msg.role, "content": msg.content} for msg in messages]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 1. Priorité absolue : Test Gemini direct (Rapide, sans intermédiaire)
|
# 1. Priorité absolue : Test Gemini direct
|
||||||
if settings.gemini_api_key:
|
if settings.gemini_api_key:
|
||||||
client = OpenAI(
|
client = OpenAI(
|
||||||
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
|
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
|
||||||
api_key=settings.gemini_api_key
|
api_key=settings.gemini_api_key
|
||||||
)
|
)
|
||||||
# Utilisation de l'identifiant standard API pour la version Flash
|
# Correction : Utilisation exacte du modèle 3.5 Flash-Lite
|
||||||
model = "gemini-1.5-flash"
|
model = "gemini-3.5-flash-lite"
|
||||||
response = client.chat.completions.create(model=model, messages=formatted_messages)
|
response = client.chat.completions.create(model=model, messages=formatted_messages)
|
||||||
|
|
||||||
# 2. Test OpenRouter (Fallback)
|
# 2. Test OpenRouter (Fallback)
|
||||||
elif settings.openrouter_api_key:
|
elif settings.openrouter_api_key:
|
||||||
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=settings.openrouter_api_key)
|
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=settings.openrouter_api_key)
|
||||||
model = "google/gemini-1.5-pro" # Identifiant mis à jour et valide
|
model = "google/gemini-3.5-flash-lite"
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model=model,
|
model=model,
|
||||||
messages=formatted_messages,
|
messages=formatted_messages,
|
||||||
|
|||||||
+17
-35
@@ -1,60 +1,44 @@
|
|||||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, Text
|
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, DateTime, Float
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from .database import Base
|
from .database import Base
|
||||||
from sqlalchemy import Float, DateTime
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
|
|
||||||
class User(Base):
|
class User(Base):
|
||||||
__tablename__ = "users"
|
__tablename__ = "users"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
email = Column(String, unique=True, index=True, nullable=False)
|
email = Column(String, unique=True, index=True)
|
||||||
username = Column(String, unique=True, index=True, nullable=False)
|
username = Column(String, unique=True, index=True)
|
||||||
hashed_password = Column(String, nullable=False)
|
hashed_password = Column(String)
|
||||||
totp_secret = Column(String, nullable=False)
|
totp_secret = Column(String)
|
||||||
is_admin = Column(Boolean, default=False)
|
is_admin = Column(Boolean, default=False)
|
||||||
|
projects = relationship("Project", back_populates="owner")
|
||||||
# Relation : Un utilisateur peut avoir plusieurs projets
|
|
||||||
projects = relationship("Project", back_populates="owner", cascade="all, delete-orphan")
|
|
||||||
|
|
||||||
|
|
||||||
class Project(Base):
|
class Project(Base):
|
||||||
__tablename__ = "projects"
|
__tablename__ = "projects"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
title = Column(String, nullable=False)
|
title = Column(String, index=True)
|
||||||
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||||
is_pinned = Column(Boolean, default=False)
|
is_pinned = Column(Boolean, default=False)
|
||||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
user_id = Column(Integer, ForeignKey("users.id"))
|
||||||
|
|
||||||
# Relations
|
|
||||||
owner = relationship("User", back_populates="projects")
|
owner = relationship("User", back_populates="projects")
|
||||||
messages = relationship("Message", back_populates="project", cascade="all, delete-orphan")
|
messages = relationship("Message", back_populates="project", cascade="all, delete-orphan")
|
||||||
|
|
||||||
|
|
||||||
class Message(Base):
|
class Message(Base):
|
||||||
__tablename__ = "messages"
|
__tablename__ = "messages"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
role = Column(String, nullable=False) # Ex: 'user', 'assistant', 'worker_1', 'system'
|
role = Column(String)
|
||||||
content = Column(Text, nullable=False)
|
content = Column(String)
|
||||||
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||||
project_id = Column(Integer, ForeignKey("projects.id"), nullable=False)
|
project_id = Column(Integer, ForeignKey("projects.id"))
|
||||||
|
|
||||||
# Relation
|
|
||||||
project = relationship("Project", back_populates="messages")
|
project = relationship("Project", back_populates="messages")
|
||||||
|
|
||||||
class SystemSettings(Base):
|
class SystemSettings(Base):
|
||||||
__tablename__ = "system_settings"
|
__tablename__ = "system_settings"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
# Serveur Mail (Obligatoire)
|
|
||||||
smtp_host = Column(String, nullable=False)
|
smtp_host = Column(String, nullable=False)
|
||||||
smtp_port = Column(Integer, nullable=False)
|
smtp_port = Column(Integer, nullable=False)
|
||||||
smtp_user = Column(String, nullable=False)
|
smtp_user = Column(String, nullable=False)
|
||||||
smtp_password = Column(String, nullable=False)
|
smtp_password = Column(String, nullable=False)
|
||||||
# Clés API (Optionnelles)
|
|
||||||
openrouter_api_key = Column(String, nullable=True)
|
openrouter_api_key = Column(String, nullable=True)
|
||||||
openrouter_management_key = Column(String, nullable=True)
|
openrouter_management_key = Column(String, nullable=True)
|
||||||
groq_api_key = Column(String, nullable=True)
|
groq_api_key = Column(String, nullable=True)
|
||||||
@@ -65,25 +49,23 @@ class SystemSettings(Base):
|
|||||||
cloudflare_api_token = Column(String, nullable=True)
|
cloudflare_api_token = Column(String, nullable=True)
|
||||||
huggingface_api_key = Column(String, nullable=True)
|
huggingface_api_key = Column(String, nullable=True)
|
||||||
|
|
||||||
class AIModel(Base):
|
class AIModel(Base):
|
||||||
"""Stocke la liste des modèles extraits depuis les fournisseurs."""
|
"""Stocke la liste des modèles extraits depuis les fournisseurs."""
|
||||||
__tablename__ = "ai_models"
|
__tablename__ = "ai_models"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
provider = Column(String, index=True) # ex: openrouter, groq
|
provider = Column(String, index=True)
|
||||||
model_id = Column(String, unique=True, index=True) # ex: google/gemini-1.5-pro
|
model_id = Column(String, unique=True, index=True)
|
||||||
name = Column(String)
|
name = Column(String)
|
||||||
context_length = Column(Integer)
|
context_length = Column(Integer)
|
||||||
pricing_prompt = Column(Float) # Coût pour 1M tokens
|
pricing_prompt = Column(Float)
|
||||||
pricing_completion = Column(Float)
|
pricing_completion = Column(Float)
|
||||||
last_updated = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
last_updated = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||||
|
|
||||||
class FinancialLog(Base):
|
class FinancialLog(Base):
|
||||||
"""Suivi financier par fournisseur."""
|
"""Suivi financier par fournisseur."""
|
||||||
__tablename__ = "financial_logs"
|
__tablename__ = "financial_logs"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
provider = Column(String, index=True)
|
provider = Column(String, index=True)
|
||||||
balance = Column(Float) # Crédit restant
|
balance = Column(Float)
|
||||||
total_usage = Column(Float) # Consommation totale
|
total_usage = Column(Float)
|
||||||
checked_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
checked_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||||
Reference in new issue
Block a user