llm: loosen format check to default to no format (#8127)
This commit is contained in:
parent
8f805dd74b
commit
0f06a6daa7
@ -722,20 +722,14 @@ func (s *llmServer) Completion(ctx context.Context, req CompletionRequest, fn fu
|
|||||||
return fmt.Errorf("unexpected server status: %s", status.ToString())
|
return fmt.Errorf("unexpected server status: %s", status.ToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.Format) > 0 {
|
if bytes.Equal(req.Format, []byte(`"json"`)) {
|
||||||
switch {
|
|
||||||
case bytes.Equal(req.Format, []byte(`"json"`)):
|
|
||||||
request["grammar"] = grammarJSON
|
request["grammar"] = grammarJSON
|
||||||
case bytes.HasPrefix(req.Format, []byte("{")):
|
} else if bytes.HasPrefix(req.Format, []byte("{")) {
|
||||||
// User provided a JSON schema
|
|
||||||
g := llama.SchemaToGrammar(req.Format)
|
g := llama.SchemaToGrammar(req.Format)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
return fmt.Errorf("invalid JSON schema in format")
|
return fmt.Errorf("invalid JSON schema in format")
|
||||||
}
|
}
|
||||||
request["grammar"] = string(g)
|
request["grammar"] = string(g)
|
||||||
default:
|
|
||||||
return errors.New(`invalid format: expected "json" or a JSON schema`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handling JSON marshaling with special characters unescaped.
|
// Handling JSON marshaling with special characters unescaped.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user