From de52b6c2f90ff220ed9469167d51e3f5d7474fa2 Mon Sep 17 00:00:00 2001 From: Parth Sareen Date: Fri, 6 Dec 2024 14:13:15 -0800 Subject: [PATCH] bugfix: "null" value json mode (#7979) --- cmd/cmd.go | 8 ++++++++ llm/server.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 3d59be281..29608400f 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -1036,6 +1036,10 @@ func chat(cmd *cobra.Command, opts runOptions) (*api.Message, error) { return nil } + if opts.Format == "json" { + opts.Format = `"` + opts.Format + `"` + } + req := &api.ChatRequest{ Model: opts.Model, Messages: opts.Messages, @@ -1121,6 +1125,10 @@ func generate(cmd *cobra.Command, opts runOptions) error { } } + if opts.Format == "json" { + opts.Format = `"` + opts.Format + `"` + } + request := api.GenerateRequest{ Model: opts.Model, Prompt: opts.Prompt, diff --git a/llm/server.go b/llm/server.go index ad5306d7d..fadf10ef8 100644 --- a/llm/server.go +++ b/llm/server.go @@ -746,7 +746,7 @@ func (s *llmServer) Completion(ctx context.Context, req CompletionRequest, fn fu // TODO (parthsareen): Move conversion to grammar with sampling logic // API should do error handling for invalid formats - if req.Format != nil { + if req.Format != nil && strings.TrimSpace(string(req.Format)) != "null" { if strings.ToLower(strings.TrimSpace(string(req.Format))) == `"json"` { request["grammar"] = jsonGrammar if !strings.Contains(strings.ToLower(req.Prompt), "json") {