Skip to content

Commit 69edea1

Browse files
authored
fix ordering of returned arg key names to consistent alphabetic order (#4006)
Signed-off-by: Filinto Duran <[email protected]>
1 parent 2624121 commit 69edea1

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

conversation/echo/echo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
"reflect"
21+
"sort"
2122
"strconv"
2223
"strings"
2324

@@ -102,6 +103,8 @@ func (e *Echo) Converse(ctx context.Context, r *conversation.Request) (res *conv
102103
for argName := range propMap {
103104
argNames = append(argNames, argName)
104105
}
106+
// sort the arg names to keep deterministic order for tests
107+
sort.Strings(argNames)
105108
}
106109
}
107110

conversation/echo/echo_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,69 @@ func TestConverseAlpha2(t *testing.T) {
183183
},
184184
},
185185
},
186+
{
187+
name: "tool call request with multiple arguments alphabetic ordering of arguments",
188+
messages: []llms.MessageContent{
189+
{
190+
Role: llms.ChatMessageTypeHuman,
191+
Parts: []llms.ContentPart{
192+
llms.TextContent{Text: "hello echo"},
193+
},
194+
},
195+
},
196+
tools: []llms.Tool{
197+
{
198+
Type: "function",
199+
Function: &llms.FunctionDefinition{
200+
Name: "myfunc",
201+
Description: "A function that does something",
202+
Parameters: map[string]any{
203+
"type": "object",
204+
"properties": map[string]any{
205+
"unit": map[string]any{
206+
"type": "string",
207+
"description": "unit should come last",
208+
},
209+
"name": map[string]any{
210+
"type": "string",
211+
"description": "The name to process, should come second",
212+
},
213+
"location": map[string]any{
214+
"type": "string",
215+
"description": "location should come first",
216+
},
217+
},
218+
},
219+
},
220+
},
221+
},
222+
expected: &conversation.Response{
223+
Outputs: []conversation.Result{
224+
{
225+
StopReason: "tool_calls",
226+
Choices: []conversation.Choice{
227+
{
228+
FinishReason: "tool_calls",
229+
Index: 0,
230+
Message: conversation.Message{
231+
Content: "hello echo",
232+
ToolCallRequest: &[]llms.ToolCall{
233+
{
234+
ID: "0", // ID is auto-generated by the echo component
235+
Type: "function",
236+
FunctionCall: &llms.FunctionCall{
237+
Name: "myfunc",
238+
Arguments: "location,name,unit",
239+
},
240+
},
241+
},
242+
},
243+
},
244+
},
245+
},
246+
},
247+
},
248+
},
186249
{
187250
name: "text message with tool call response",
188251
// echo responds with the text message and tool call response appended to the message content

0 commit comments

Comments
 (0)