fix: improve reload_excludes configuration for uvicorn server and added support for newer models (openai)

This commit is contained in:
Louis ROMAIN
2026-01-04 23:38:06 +01:00
parent 18c66b1ef8
commit c31493bfdf
3 changed files with 78 additions and 31 deletions

View File

@@ -104,25 +104,26 @@ if __name__ == "__main__":
backend_port = get_backend_port(project_root)
# Configure uvicorn, exclude run_code_workspace directory to avoid file monitoring triggering reload
# When code execution tool creates temporary files, it should not trigger service reload
# Note: Use relative path patterns to avoid Windows path issues
# Configure reload_excludes with absolute paths to properly exclude directories
venv_dir = project_root / "venv"
data_dir = project_root / "data"
reload_excludes = [
str(d)
for d in [
venv_dir,
project_root / ".venv",
data_dir,
project_root / "web" / "node_modules",
project_root / "web" / ".next",
project_root / ".git",
]
if d.exists()
]
uvicorn.run(
"api.main:app",
host="0.0.0.0",
port=backend_port,
reload=True,
reload_excludes=[
# Code execution workspace - most important, must exclude
# Use glob patterns, relative to project root directory
"**/run_code_workspace/**",
"**/tmp*/**",
"**/__pycache__/**",
"**/*.pyc",
"**/user/solve/**",
"**/user/question/**",
"**/user/research/**",
"**/user/co-writer/**",
"**/logs/**",
],
reload_excludes=reload_excludes,
)

View File

@@ -4,6 +4,7 @@ Manages system status checks and model connection tests
"""
from datetime import datetime
import re
import time
from fastapi import APIRouter
@@ -15,6 +16,49 @@ from src.core.core import get_embedding_config, get_llm_config, get_tts_config
router = APIRouter()
def _uses_max_completion_tokens(model: str) -> bool:
"""
Check if the model uses max_completion_tokens instead of max_tokens.
Newer OpenAI models (o1, o3, gpt-4o, gpt-5.x, etc.) require max_completion_tokens
while older models use max_tokens.
"""
model_lower = model.lower()
# Models that require max_completion_tokens:
# - o1, o3 series (reasoning models)
# - gpt-4o series
# - gpt-5.x and later
patterns = [
r"^o[13]", # o1, o3 models
r"^gpt-4o", # gpt-4o models
r"^gpt-[5-9]", # gpt-5.x and later
r"^gpt-\d{2,}", # gpt-10+ (future proofing)
]
for pattern in patterns:
if re.match(pattern, model_lower):
return True
return False
def _get_token_limit_kwargs(model: str, max_tokens: int) -> dict:
"""
Get the appropriate token limit parameter for the model.
Args:
model: The model name
max_tokens: The desired token limit
Returns:
Dictionary with either max_tokens or max_completion_tokens
"""
if _uses_max_completion_tokens(model):
return {"max_completion_tokens": max_tokens}
return {"max_tokens": max_tokens}
class TestResponse(BaseModel):
success: bool
message: str
@@ -96,16 +140,17 @@ async def test_llm_connection():
api_key = llm_config["api_key"]
base_url = llm_config["base_url"]
# Send a minimal test request
test_prompt = "test"
# Send a minimal test request with a prompt that guarantees output
test_prompt = "Say 'OK' to confirm you are working."
token_kwargs = _get_token_limit_kwargs(model, max_tokens=20)
response = await openai_complete_if_cache(
model=model,
prompt=test_prompt,
system_prompt="You are a helpful assistant.",
system_prompt="You are a helpful assistant. Respond briefly.",
api_key=api_key,
base_url=base_url,
temperature=0.1,
max_tokens=5, # Minimal tokens for testing
**token_kwargs, # Use appropriate token param for model
)
response_time = (time.time() - start_time) * 1000

View File

@@ -34,20 +34,21 @@ if __name__ == "__main__":
backend_port = get_backend_port(project_root)
# Configure reload_excludes to skip temporary files and output directories
# Configure reload_excludes to skip directories that shouldn't trigger reloads
# Use absolute paths to ensure they're properly resolved
reload_excludes = [
"**/run_code_workspace/**", # Code execution workspace
"**/tmp*/**", # All temp directories
"**/__pycache__/**", # Python cache
"**/*.pyc", # Python compiled files
"**/user/solve/**", # Solve output directory
"**/user/question/**", # Question output directory
"**/user/research/**", # Research output directory
"**/user/co-writer/**", # Co-Writer output directory
"**/logs/**", # Logs directory
"**/user/logs/**", # User logs directory
str(project_root / "venv"), # Virtual environment
str(project_root / ".venv"), # Virtual environment (alternative name)
str(project_root / "data"), # Data directory (includes knowledge_bases, user data, logs)
str(project_root / "node_modules"), # Node modules (if any at root)
str(project_root / "web" / "node_modules"), # Web node modules
str(project_root / "web" / ".next"), # Next.js build
str(project_root / ".git"), # Git directory
]
# Filter out non-existent directories to avoid warnings
reload_excludes = [d for d in reload_excludes if Path(d).exists()]
# Start uvicorn server with reload enabled
uvicorn.run(
"src.api.main:app",