Skip to content

Commit 82a7744

Browse files
committed
Fix: Ensure function params are not null
Mistral's validation is more strict than OpenAIs and will reject a function if the parameter field is set to null or completely omitted. It is strictly expecting a valid map. This change makes that so. Signed-off-by: Craig Jellick <[email protected]>
1 parent 1bf1f8b commit 82a7744

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/openai/client.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"strings"
1515
"sync/atomic"
1616

17+
"github.com/getkin/kin-openapi/openapi3"
1718
openai "github.com/gptscript-ai/chat-completion-client"
1819
"github.com/gptscript-ai/gptscript/pkg/cache"
1920
"github.com/gptscript-ai/gptscript/pkg/hash"
@@ -327,15 +328,20 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
327328

328329
for _, tool := range messageRequest.Tools {
329330
params := tool.Function.Parameters
331+
if params == nil {
332+
params = &openapi3.Schema{}
333+
}
330334

331-
request.Tools = append(request.Tools, openai.Tool{
335+
oTool := openai.Tool{
332336
Type: openai.ToolTypeFunction,
333337
Function: &openai.FunctionDefinition{
334338
Name: tool.Function.Name,
335339
Description: tool.Function.Description,
336340
Parameters: params,
337341
},
338-
})
342+
}
343+
344+
request.Tools = append(request.Tools, oTool)
339345
}
340346

341347
id := fmt.Sprint(atomic.AddInt64(&completionID, 1))
@@ -474,7 +480,7 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
474480
},
475481
}
476482

477-
slog.Debug("calling openai", "message", request.Messages)
483+
slog.Info("calling openai", "message", request.Messages)
478484

479485
if !request.Stream {
480486
resp, err := c.c.CreateChatCompletion(ctx, request)
@@ -518,7 +524,7 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
518524
return nil, err
519525
}
520526
if len(response.Choices) > 0 {
521-
slog.Debug("stream", "content", response.Choices[0].Delta.Content)
527+
slog.Info("stream", "content", response.Choices[0].Delta.Content)
522528
}
523529
if partial != nil {
524530
partialMessage = appendMessage(partialMessage, response)

0 commit comments

Comments
 (0)