Files
New-planet-ai-agent/models/gigachat_types.py

59 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Типы для работы с GigaChat API."""
from typing import List, Literal, Optional
from pydantic import BaseModel, Field
class GigaChatMessage(BaseModel):
"""Сообщение для GigaChat API."""
role: Literal["system", "user", "assistant"]
content: str
class GigaChatRequest(BaseModel):
"""Запрос к GigaChat API."""
model: str = Field(default="GigaChat-2", description="Модель GigaChat")
messages: List[GigaChatMessage] = Field(..., description="История сообщений")
temperature: float = Field(default=0.7, ge=0.0, le=2.0)
max_tokens: int = Field(default=2000, ge=1, le=8192)
top_p: float = Field(default=0.9, ge=0.0, le=1.0)
stream: bool = Field(default=False)
class GigaChatChoice(BaseModel):
"""Вариант ответа от GigaChat."""
message: GigaChatMessage
index: int
finish_reason: Optional[str] = None
class GigaChatUsage(BaseModel):
"""Использование токенов."""
prompt_tokens: int
completion_tokens: int
total_tokens: int
class GigaChatResponse(BaseModel):
"""Ответ от GigaChat API."""
id: str
object: str
created: int
model: str
choices: List[GigaChatChoice]
usage: GigaChatUsage
class GigaChatTokenResponse(BaseModel):
"""Ответ на запрос токена."""
access_token: str
expires_at: int
token_type: str = "Bearer"