支持fastapi服务

This commit is contained in:
puke
2025-10-28 01:33:36 +08:00
committed by puke
parent c387137446
commit c200761b97
28 changed files with 1854 additions and 4 deletions

31
api/schemas/llm.py Normal file
View File

@@ -0,0 +1,31 @@
"""
LLM API schemas
"""
from typing import Optional
from pydantic import BaseModel, Field
class LLMChatRequest(BaseModel):
"""LLM chat request"""
prompt: str = Field(..., description="User prompt")
temperature: float = Field(0.7, ge=0.0, le=2.0, description="Temperature (0.0-2.0)")
max_tokens: int = Field(2000, ge=1, le=32000, description="Maximum tokens")
class Config:
json_schema_extra = {
"example": {
"prompt": "Explain the concept of atomic habits in 3 sentences",
"temperature": 0.7,
"max_tokens": 2000
}
}
class LLMChatResponse(BaseModel):
"""LLM chat response"""
success: bool = True
message: str = "Success"
content: str = Field(..., description="Generated response")
tokens_used: Optional[int] = Field(None, description="Tokens used (if available)")