llm.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2025 AIDC-AI
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """
  13. LLM API schemas
  14. """
  15. from typing import Optional
  16. from pydantic import BaseModel, Field
  17. class LLMChatRequest(BaseModel):
  18. """LLM chat request"""
  19. prompt: str = Field(..., description="User prompt")
  20. temperature: float = Field(0.7, ge=0.0, le=2.0, description="Temperature (0.0-2.0)")
  21. max_tokens: int = Field(2000, ge=1, le=32000, description="Maximum tokens")
  22. class Config:
  23. json_schema_extra = {
  24. "example": {
  25. "prompt": "Explain the concept of atomic habits in 3 sentences",
  26. "temperature": 0.7,
  27. "max_tokens": 2000
  28. }
  29. }
  30. class LLMChatResponse(BaseModel):
  31. """LLM chat response"""
  32. success: bool = True
  33. message: str = "Success"
  34. content: str = Field(..., description="Generated response")
  35. tokens_used: Optional[int] = Field(None, description="Tokens used (if available)")