Documentation
¶
Index ¶
- func RequestIDFromContext(ctx context.Context) string
- func WithAllowedProviders(ctx context.Context, providers []string) context.Context
- func WithRequestID(ctx context.Context, id string) context.Context
- type AttemptHook
- type ChatExecutor
- func (e ChatExecutor) ChatNonStream(ctx context.Context, req translate.ChatRequest, prefer, providerFilter string) (ChatResult, error)
- func (e ChatExecutor) ChatStreamProxy(ctx context.Context, req translate.ChatRequest, prefer, providerFilter string) (StreamResult, error)
- func (e ChatExecutor) ObserveStreamFailure(accountID string, err error, model string)
- type ChatResult
- type StreamResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestIDFromContext ¶ added in v0.2.6
func WithAllowedProviders ¶ added in v0.2.21
Types ¶
type AttemptHook ¶ added in v0.2.6
type AttemptHook func(accounts.RequestAttempt)
type ChatExecutor ¶
type ChatExecutor struct {
Pool *accounts.Pool
WorkerKey string
HTTPClient *http.Client
Providers *providerRegistry
OnAttempt AttemptHook
MaxAttempts int
}
func NewChatExecutor ¶
func NewChatExecutor(pool *accounts.Pool, workerKey string) ChatExecutor
func (ChatExecutor) ChatNonStream ¶
func (e ChatExecutor) ChatNonStream(ctx context.Context, req translate.ChatRequest, prefer, providerFilter string) (ChatResult, error)
func (ChatExecutor) ChatStreamProxy ¶
func (e ChatExecutor) ChatStreamProxy(ctx context.Context, req translate.ChatRequest, prefer, providerFilter string) (StreamResult, error)
func (ChatExecutor) ObserveStreamFailure ¶ added in v0.2.28
func (e ChatExecutor) ObserveStreamFailure(accountID string, err error, model string)
ObserveStreamFailure applies a post-headers streaming failure to the pool. Upstream can answer 200 and then fail inside the SSE body, which happens after the executor already returned a successful StreamResult; the relay error is the first place the failure is observable. Same-account retry is impossible at that point (bytes are on the wire), so this only records the classified state for the next request's scheduling.
type ChatResult ¶
type ChatResult struct {
Model string
Content string
Reasoning string
ToolCalls json.RawMessage
FinishReason string
PromptTokens int
CompletionTokens int
CacheReadTokens *int
CacheWriteTokens *int
CachedTokens *int
UsageSource string
Credits *float64
AccountID string
Provider string
AttemptCount int
RawNote string
}