nub/internal/llm/openai/wire.go
Tom a97013d876 initial commit
- v 0.1.0 siehe CHANGELOG.md
2026-07-25 11:08:01 +02:00

110 lines
3 KiB
Go

// Package openai ist der OpenAI-kompatible Provider-Adapter. Provider-SDK-Typen
// und das Wire-Format bleiben strikt in diesem Paket (E-02).
package openai
import "encoding/json"
type wireRequest struct {
Model string `json:"model"`
Messages []wireMessage `json:"messages"`
Tools []wireToolDef `json:"tools,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
Stream bool `json:"stream"`
StreamOptions *streamOptions `json:"stream_options,omitempty"`
}
type streamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
type wireMessage struct {
Role string `json:"role"`
Content json.RawMessage `json:"content,omitempty"`
ToolCalls []wireToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
}
type wireToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function wireToolCallFunc `json:"function"`
}
type wireToolCallFunc struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
}
type wireToolDef struct {
Type string `json:"type"`
Function wireFunctionDef `json:"function"`
}
type wireFunctionDef struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters,omitempty"`
}
type wireContentPart struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ImageURL *wireImageURL `json:"image_url,omitempty"`
}
type wireImageURL struct {
URL string `json:"url"`
}
// --- Stream chunk ---
type wireChunk struct {
Choices []wireChoice `json:"choices"`
Usage *wireUsage `json:"usage"`
}
type wireChoice struct {
Delta wireDelta `json:"delta"`
FinishReason *string `json:"finish_reason"`
}
type wireDelta struct {
Content *string `json:"content"`
ReasoningContent *string `json:"reasoning_content"`
ToolCalls []wireToolCallDelta `json:"tool_calls"`
}
type wireToolCallDelta struct {
Index int `json:"index"`
ID *string `json:"id"`
Type *string `json:"type"`
Function *wireToolCallFuncDelta `json:"function"`
}
type wireToolCallFuncDelta struct {
Name *string `json:"name"`
Arguments *string `json:"arguments"`
}
type wireUsage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
PromptTokensDetails *wireTokensDetails `json:"prompt_tokens_details"`
}
type wireTokensDetails struct {
CachedTokens int `json:"cached_tokens"`
}
// wireStreamError deckt Endpoints ab, die Fehler als SSE-Event statt als
// HTTP-Fehler senden (5.1 Punkt 7).
type wireStreamError struct {
Error *wireErrorBody `json:"error"`
}
type wireErrorBody struct {
Message string `json:"message"`
Type string `json:"type"`
Code string `json:"code"`
}