Files
llmproxy/app/models.py
2025-12-31 06:35:08 +00:00

42 lines
1.2 KiB
Python

from pydantic import BaseModel, Field
from typing import List, Dict, Any, Optional
# Models for incoming requests
class ChatMessage(BaseModel):
"""Represents a single message in the chat history."""
role: str
content: str
class Tool(BaseModel):
"""Represents a tool definition provided by the user."""
type: str
function: Dict[str, Any]
class IncomingRequest(BaseModel):
"""Defines the structure of the request from the client."""
messages: List[ChatMessage]
tools: Optional[List[Tool]] = None
stream: Optional[bool] = False
# Models for outgoing responses
class ToolCallFunction(BaseModel):
"""Function call details within a tool call."""
name: str
arguments: str # JSON string of arguments
class ToolCall(BaseModel):
"""Represents a tool call requested by the LLM."""
id: str
type: str = "function"
function: ToolCallFunction
class ResponseMessage(BaseModel):
"""The message part of the response from the proxy."""
role: str = "assistant"
content: Optional[str] = None
tool_calls: Optional[List[ToolCall]] = None
class ProxyResponse(BaseModel):
"""Defines the final structured response sent back to the client."""
message: ResponseMessage