Skip to content

Commit bf41c3b

Browse files
authored
Fix: Ensure function params are not null (#325)
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 9953432 commit bf41c3b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pkg/openai/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"sync/atomic"
1313

14+
"github.com/getkin/kin-openapi/openapi3"
1415
openai "github.com/gptscript-ai/chat-completion-client"
1516
"github.com/gptscript-ai/gptscript/pkg/cache"
1617
"github.com/gptscript-ai/gptscript/pkg/hash"
@@ -323,6 +324,9 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
323324

324325
for _, tool := range messageRequest.Tools {
325326
params := tool.Function.Parameters
327+
if params == nil {
328+
params = &openapi3.Schema{}
329+
}
326330

327331
request.Tools = append(request.Tools, openai.Tool{
328332
Type: openai.ToolTypeFunction,

0 commit comments

Comments
 (0)