- ai_service.py: единый AI-сервис (chat, chat_with_history, analyze_document) - routes/ai.py: POST /api/v1/ai/chat (chat, summarize, extract_risks, classify, translate) - config.py: ANTHROPIC_API_KEY, ANTHROPIC_MODEL - requirements.txt: anthropic>=0.42.0 - api-client.ts: aiApi (chat, summarize, extractRisks) - CSP: connect-src добавлен https://api.anthropic.com - app/api/ai-chat: прокси на бэкенд /api/v1/ai/chat (Anthropic) - legal_agents/llm_client.py: переведён на ai_service (Claude) - AIAccessSettings: только Claude (Sonnet 4, 3 Sonnet, 3 Opus) - k8s, .env.example: OPENAI → ANTHROPIC - package.json: удалена зависимость openai - Документация: OpenAI/GPT заменены на Claude/Anthropic Провайдер: исключительно Anthropic Claude Модель по умолчанию: claude-sonnet-4-20250514 Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""AI-ассистент КЛГ АСУ ТК — работает через Anthropic Claude API."""
|
||
from fastapi import APIRouter, Depends, HTTPException
|
||
from pydantic import BaseModel
|
||
|
||
from app.api.deps import get_current_user
|
||
from app.core.config import settings
|
||
|
||
router = APIRouter(tags=["ai"])
|
||
|
||
|
||
class AIRequest(BaseModel):
|
||
prompt: str
|
||
task: str = "chat" # chat | summarize | extract_risks | classify | translate
|
||
context: str | None = None
|
||
|
||
|
||
class AIResponse(BaseModel):
|
||
result: str | None
|
||
model: str
|
||
provider: str = "anthropic"
|
||
|
||
|
||
@router.post("/ai/chat", response_model=AIResponse)
|
||
def ai_chat(
|
||
req: AIRequest,
|
||
user=Depends(get_current_user),
|
||
):
|
||
"""Отправить запрос AI-ассистенту (Anthropic Claude)."""
|
||
from app.services.ai_service import chat, analyze_document
|
||
|
||
if req.task == "chat":
|
||
system = (
|
||
"Ты — AI-ассистент системы КЛГ АСУ ТК (контроль лётной годности воздушных судов). "
|
||
"Отвечай на русском языке. Используй терминологию ВК РФ, ФАП, ICAO, EASA."
|
||
)
|
||
if req.context:
|
||
system += f"\n\nКонтекст: {req.context}"
|
||
result = chat(prompt=req.prompt, system=system)
|
||
else:
|
||
text = f"{req.context}\n\n{req.prompt}" if req.context else req.prompt
|
||
result = analyze_document(text=text, task=req.task)
|
||
|
||
if result is None:
|
||
raise HTTPException(503, "AI-сервис недоступен. Проверьте ANTHROPIC_API_KEY.")
|
||
|
||
return AIResponse(result=result, model=settings.ANTHROPIC_MODEL)
|