Added code samples for AI-Agents
This commit is contained in:
58
models/gigachat_types.py
Normal file
58
models/gigachat_types.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Типы для работы с 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"
|
||||
|
||||
Reference in New Issue
Block a user