Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions providers/openaicompat/language_model_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func ExtraContentFunc(choice openaisdk.ChatCompletionChoice) []fantasy.Content {
if err != nil {
return content
}
if reasoningData.ReasoningContent != "" {
if reasoning := reasoningData.GetReasoning(); reasoning != "" {
content = append(content, fantasy.ReasoningContent{
Text: reasoningData.ReasoningContent,
Text: reasoning,
})
}
return content
Expand Down Expand Up @@ -110,11 +110,11 @@ func StreamExtraFunc(chunk openaisdk.ChatCompletionChunk, yield func(fantasy.Str
Delta: reasoningContent,
})
}
if reasoningData.ReasoningContent != "" {
if reasoning := reasoningData.GetReasoning(); reasoning != "" {
if !reasoningStarted {
ctx[reasoningStartedCtx] = true
}
return ctx, emitEvent(reasoningData.ReasoningContent)
return ctx, emitEvent(reasoning)
}
if reasoningStarted && (choice.Delta.Content != "" || len(choice.Delta.ToolCalls) > 0) {
ctx[reasoningStartedCtx] = false
Expand Down
13 changes: 13 additions & 0 deletions providers/openaicompat/provider_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ type ProviderOptions struct {
}

// ReasoningData represents reasoning data for OpenAI-compatible provider.
// Different providers may use different field names (reasoning_content vs reasoning).
type ReasoningData struct {
// Most common
ReasoningContent string `json:"reasoning_content"`
// So far, only used by Cerebras specifically for GLM 4.6
Reasoning string `json:"reasoning"`
}

// GetReasoning returns the reasoning content whether it's in `reasoning` or
// `reasoning_content` JSON fields.
func (r *ReasoningData) GetReasoning() string {
if r.ReasoningContent != "" {
return r.ReasoningContent
}
return r.Reasoning
}

// Options implements the ProviderOptions interface.
Expand Down
Loading