feat: version ai result schemas

This commit is contained in:
Grendgi
2026-06-17 16:46:03 +03:00
parent f32265400b
commit 63553fba33
5 changed files with 94 additions and 22 deletions

View File

@@ -38,11 +38,14 @@ type Usage struct {
TotalTokens int `json:"total_tokens"`
}
const ChatResultSchemaVersion = "ai.chat_result.v1"
type ChatResult struct {
Content string `json:"content"`
Model string `json:"model"`
Usage *Usage `json:"usage,omitempty"`
DurationMS int64 `json:"duration_ms"`
SchemaVersion string `json:"schema_version"`
Content string `json:"content"`
Model string `json:"model"`
Usage *Usage `json:"usage,omitempty"`
DurationMS int64 `json:"duration_ms"`
}
type chatRequest struct {
@@ -137,10 +140,11 @@ func (c *Client) Chat(ctx context.Context, in ChatInput) (*ChatResult, error) {
modelName = c.model
}
return &ChatResult{
Content: out.Choices[0].Message.Content,
Model: modelName,
Usage: out.Usage,
DurationMS: duration.Milliseconds(),
SchemaVersion: ChatResultSchemaVersion,
Content: out.Choices[0].Message.Content,
Model: modelName,
Usage: out.Usage,
DurationMS: duration.Milliseconds(),
}, nil
}