Skip to content

Commit e28e030

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 e28e030

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/openai/client.go

Lines changed: 6 additions & 2 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,6 +328,9 @@ 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

331335
request.Tools = append(request.Tools, openai.Tool{
332336
Type: openai.ToolTypeFunction,
@@ -474,7 +478,7 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
474478
},
475479
}
476480

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

479483
if !request.Stream {
480484
resp, err := c.c.CreateChatCompletion(ctx, request)
@@ -518,7 +522,7 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
518522
return nil, err
519523
}
520524
if len(response.Choices) > 0 {
521-
slog.Debug("stream", "content", response.Choices[0].Delta.Content)
525+
slog.Info("stream", "content", response.Choices[0].Delta.Content)
522526
}
523527
if partial != nil {
524528
partialMessage = appendMessage(partialMessage, response)

0 commit comments

Comments
 (0)