diff --git a/.env.example b/.env.example index 308708e..b64d8e9 100644 --- a/.env.example +++ b/.env.example @@ -12,3 +12,7 @@ OIDC_VERIFY_ISS=true # Frontend redirect URI VITE_OIDC_REDIRECT_URI=http://localhost:5173 + +# Ollama Cloud model name (optional) +# Set to a valid Ollama model for your account, e.g. "llama3" or "gpt-4o-mini". +OLLAMA_MODEL=llama3 diff --git a/backend/app/main.py b/backend/app/main.py index daeb9dc..d73542f 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -11,7 +11,8 @@ from app.auth import get_discovery, settings, validate_token from app.schemas import AuthCallbackRequest, AuthConfigResponse, ChatRequest OLLAMA_API_KEY = os.getenv("OLLAMA_API_KEY") -OLLAMA_API_URL = os.getenv("OLLAMA_API_URL", "https://ollama.com/v1/chat/completions") +OLLAMA_API_URL = os.getenv("OLLAMA_API_URL", "https://api.ollama.com/v1/chat/completions") +OLLAMA_MODEL = os.getenv("OLLAMA_MODEL") if not OLLAMA_API_KEY: raise RuntimeError("Environment variable OLLAMA_API_KEY is required") @@ -33,11 +34,13 @@ app.add_middleware( ) async def event_stream(request: ChatRequest) -> AsyncGenerator[str, None]: + model = OLLAMA_MODEL or request.model payload = { - "model": request.model, + "model": model, "messages": [message.dict() for message in request.messages], "stream": True, } + logger.debug("Sending Ollama request with model=%s", model) headers = { "Authorization": f"Bearer {OLLAMA_API_KEY}", "Content-Type": "application/json",