Skip to content

fix(go): exclude reasoning part when return value from Text() function #3165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions go/ai/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,18 @@ func (c *ModelResponseChunk) Text() string {
}
var sb strings.Builder
for _, p := range c.Content {
sb.WriteString(p.Text)
// IMPORTANT: Include both text and data parts for JSON parsing.
// The LLM JSON Mode is usually returned as markdown (text) rather than valid JSON data
if p.IsText() || p.IsData() {
sb.WriteString(p.Text)
}
}
return sb.String()
}

// Text returns the contents of a [Message] as a string. It
// returns an empty string if the message has no content.
// If you want to get reasoning from the message, use Reasoning() instead.
func (m *Message) Text() string {
if m == nil {
return ""
Expand All @@ -787,7 +792,9 @@ func (m *Message) Text() string {
}
var sb strings.Builder
for _, p := range m.Content {
sb.WriteString(p.Text)
if p.IsText() || p.IsData() {
sb.WriteString(p.Text)
}
}
return sb.String()
}
Expand Down