fix(openai): strings.Builder for tool-arg accumulation (R7c)
This commit is contained in:
1 parent
79a69e5dce
commit
385cd26e4b
2 files changed
+8
-7
No files matched your search
@@ -332,7 +332,7 @@ func (p *OpenAIProvider) ChatStream(ctx context.Context, req llm.ChatRequest) (<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if tc.Function.Arguments != "" {
|
if tc.Function.Arguments != "" {
|
||||||
pending.argsJSON += tc.Function.Arguments
|
pending.args.WriteString(tc.Function.Arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,7 +355,7 @@ func (p *OpenAIProvider) ChatStream(ctx context.Context, req llm.ChatRequest) (<
|
|||||||
type pendingTC struct {
|
type pendingTC struct {
|
||||||
id string
|
id string
|
||||||
name string
|
name string
|
||||||
argsJSON string
|
args strings.Builder
|
||||||
}
|
}
|
||||||
|
|
||||||
// emitToolCalls sends EventToolCallDone for each completed tool call in
|
// emitToolCalls sends EventToolCallDone for each completed tool call in
|
||||||
@@ -379,7 +379,7 @@ func emitToolCalls(events chan<- llm.ChatEvent, toolCalls map[int]*pendingTC) {
|
|||||||
ToolCall: &llm.ToolCall{
|
ToolCall: &llm.ToolCall{
|
||||||
ID: tc.id,
|
ID: tc.id,
|
||||||
Name: tc.name,
|
Name: tc.name,
|
||||||
Input: json.RawMessage(tc.argsJSON),
|
Input: json.RawMessage(tc.args.String()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,11 +75,12 @@ func TestOpenAIChatStreamPartsBeatString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmitToolCalls_OrderedByIndex(t *testing.T) {
|
func TestEmitToolCalls_OrderedByIndex(t *testing.T) {
|
||||||
toolCalls := map[int]*pendingTC{
|
mk := func(id, name string) *pendingTC {
|
||||||
2: {id: "c", name: "third", argsJSON: "{}"},
|
p := &pendingTC{id: id, name: name}
|
||||||
0: {id: "a", name: "first", argsJSON: "{}"},
|
p.args.WriteString("{}")
|
||||||
1: {id: "b", name: "second", argsJSON: "{}"},
|
return p
|
||||||
}
|
}
|
||||||
|
toolCalls := map[int]*pendingTC{2: mk("c", "third"), 0: mk("a", "first"), 1: mk("b", "second")}
|
||||||
ch := make(chan llm.ChatEvent, 10)
|
ch := make(chan llm.ChatEvent, 10)
|
||||||
emitToolCalls(ch, toolCalls)
|
emitToolCalls(ch, toolCalls)
|
||||||
close(ch)
|
close(ch)
|
||||||
|
|||||||
Reference in new issue
Block a user