Skip to content

Commit 785ad9a

Browse files
authored
fix(go): fixed missing reasoning part type (#3819)
1 parent d939aee commit 785ad9a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

go/ai/document.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ func (p *Part) unmarshalPartFromSchema(s partSchema) {
291291
case s.Custom != nil:
292292
p.Kind = PartCustom
293293
p.Custom = s.Custom
294+
case s.Reasoning != "":
295+
p.Kind = PartReasoning
296+
p.Text = s.Reasoning
297+
p.ContentType = "plain/text"
294298
default:
295299
p.Kind = PartText
296300
p.Text = s.Text

go/ai/document_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,34 @@ func TestDocumentJSON(t *testing.T) {
110110
t.Errorf("mismatch (-want, +got)\n%s", diff)
111111
}
112112
}
113+
114+
func TestReasoningPartJSON(t *testing.T) {
115+
reasoningText := "This is my reasoning process"
116+
signature := []byte("sig123")
117+
118+
originalPart := NewReasoningPart(reasoningText, signature)
119+
120+
b, err := json.Marshal(originalPart)
121+
if err != nil {
122+
t.Fatalf("failed to marshal reasoning part: %v", err)
123+
}
124+
125+
t.Logf("marshaled reasoning part: %s\n", string(b))
126+
127+
var unmarshaledPart Part
128+
if err := json.Unmarshal(b, &unmarshaledPart); err != nil {
129+
t.Fatalf("failed to unmarshal reasoning part: %v", err)
130+
}
131+
132+
if !unmarshaledPart.IsReasoning() {
133+
t.Errorf("unmarshaled part is not reasoning, got kind: %v", unmarshaledPart.Kind)
134+
}
135+
136+
if unmarshaledPart.Text != reasoningText {
137+
t.Errorf("unmarshaled reasoning text = %q, want %q", unmarshaledPart.Text, reasoningText)
138+
}
139+
140+
if unmarshaledPart.ContentType != "plain/text" {
141+
t.Errorf("unmarshaled reasoning content type = %q, want %q", unmarshaledPart.ContentType, "plain/text")
142+
}
143+
}

0 commit comments

Comments
 (0)