瀏覽代碼

llm: loosen format check to default to no format (#8127)

Jeffrey Morgan 4 月之前
父節點
當前提交
0f06a6daa7
共有 1 個文件被更改,包括 7 次插入13 次删除
  1. 7 13
      llm/server.go

+ 7 - 13
llm/server.go

@@ -722,20 +722,14 @@ func (s *llmServer) Completion(ctx context.Context, req CompletionRequest, fn fu
 		return fmt.Errorf("unexpected server status: %s", status.ToString())
 	}
 
-	if len(req.Format) > 0 {
-		switch {
-		case bytes.Equal(req.Format, []byte(`"json"`)):
-			request["grammar"] = grammarJSON
-		case bytes.HasPrefix(req.Format, []byte("{")):
-			// User provided a JSON schema
-			g := llama.SchemaToGrammar(req.Format)
-			if g == nil {
-				return fmt.Errorf("invalid JSON schema in format")
-			}
-			request["grammar"] = string(g)
-		default:
-			return errors.New(`invalid format: expected "json" or a JSON schema`)
+	if bytes.Equal(req.Format, []byte(`"json"`)) {
+		request["grammar"] = grammarJSON
+	} else if bytes.HasPrefix(req.Format, []byte("{")) {
+		g := llama.SchemaToGrammar(req.Format)
+		if g == nil {
+			return fmt.Errorf("invalid JSON schema in format")
 		}
+		request["grammar"] = string(g)
 	}
 
 	// Handling JSON marshaling with special characters unescaped.