feat: added proper settings handling
This commit is contained in:
+17
-22
@@ -10,13 +10,14 @@ from typing import Any
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pathlib import Path
|
||||
from pydantic import BaseModel, Field, validator
|
||||
|
||||
from alfred.agent.agent import Agent
|
||||
from alfred.agent.config import settings
|
||||
from alfred.agent.llm.deepseek import DeepSeekClient
|
||||
from alfred.agent.llm.exceptions import LLMAPIError, LLMConfigurationError
|
||||
from alfred.agent.llm.ollama import OllamaClient
|
||||
from alfred.settings import settings
|
||||
from alfred.infrastructure.persistence import get_memory, init_memory
|
||||
|
||||
logging.basicConfig(
|
||||
@@ -30,37 +31,31 @@ app = FastAPI(
|
||||
version="0.2.0",
|
||||
)
|
||||
|
||||
# TODO: Make a variable
|
||||
manifests = "manifests"
|
||||
# Sécurité : on vérifie que le dossier existe pour ne pas faire planter l'app au démarrage
|
||||
if os.path.exists(manifests):
|
||||
app.mount("/manifests", StaticFiles(directory=manifests), name="manifests")
|
||||
else:
|
||||
print(
|
||||
f"⚠️ ATTENTION : Le dossier '{manifests}' est introuvable. Le plugin ne marchera pas."
|
||||
)
|
||||
|
||||
# Initialize memory context at startup
|
||||
storage_dir = os.getenv("MEMORY_STORAGE_DIR", "memory_data")
|
||||
init_memory(storage_dir=storage_dir)
|
||||
logger.info(f"Memory context initialized (storage: {storage_dir})")
|
||||
memory_path = Path(settings.data_storage) / "memory"
|
||||
init_memory(storage_dir=str(memory_path))
|
||||
logger.info(f"Memory context initialized (path: {memory_path})")
|
||||
|
||||
# Initialize LLM based on environment variable
|
||||
llm_provider = os.getenv("LLM_PROVIDER", "deepseek").lower()
|
||||
llm_provider = settings.default_llm_provider.lower()
|
||||
|
||||
|
||||
try:
|
||||
if llm_provider == "ollama":
|
||||
logger.info("Using Ollama LLM")
|
||||
llm = OllamaClient()
|
||||
else:
|
||||
if llm_provider == "local":
|
||||
logger.info("Using local Ollama LLM")
|
||||
llm = OllamaClient(settings=settings)
|
||||
elif llm_provider == "deepseek":
|
||||
logger.info("Using DeepSeek LLM")
|
||||
llm = DeepSeekClient()
|
||||
elif llm_provider == "claude":
|
||||
raise ValueError(f"LLM provider not fully implemented: {llm_provider}")
|
||||
else:
|
||||
raise ValueError(f"Unknown LLM provider: {llm_provider}")
|
||||
except LLMConfigurationError as e:
|
||||
logger.error(f"Failed to initialize LLM: {e}")
|
||||
raise
|
||||
|
||||
# Initialize agent
|
||||
agent = Agent(llm=llm, max_tool_iterations=settings.max_tool_iterations)
|
||||
agent = Agent(settings=settings, llm=llm, max_tool_iterations=settings.max_tool_iterations)
|
||||
logger.info("Agent Media API initialized")
|
||||
|
||||
|
||||
@@ -115,7 +110,7 @@ def extract_last_user_content(messages: list[dict[str, Any]]) -> str:
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
"""Health check endpoint."""
|
||||
return {"status": "healthy", "version": "0.2.0"}
|
||||
return {"status": "healthy", "version": "0.2.0"} # TODO: SHOULD BE DYNAMIC
|
||||
|
||||
|
||||
@app.get("/v1/models")
|
||||
|
||||
Reference in New Issue
Block a user