api: add generate endpoint for structured outputs (#7939)
This commit is contained in:
parent
630e7dc6ff
commit
c6c526275d
@ -67,7 +67,7 @@ type GenerateRequest struct {
|
|||||||
Raw bool `json:"raw,omitempty"`
|
Raw bool `json:"raw,omitempty"`
|
||||||
|
|
||||||
// Format specifies the format to return a response in.
|
// Format specifies the format to return a response in.
|
||||||
Format string `json:"format"`
|
Format json.RawMessage `json:"format,omitempty"`
|
||||||
|
|
||||||
// KeepAlive controls how long the model will stay loaded in memory following
|
// KeepAlive controls how long the model will stay loaded in memory following
|
||||||
// this request.
|
// this request.
|
||||||
|
@ -1126,7 +1126,7 @@ func generate(cmd *cobra.Command, opts runOptions) error {
|
|||||||
Prompt: opts.Prompt,
|
Prompt: opts.Prompt,
|
||||||
Context: generateContext,
|
Context: generateContext,
|
||||||
Images: opts.Images,
|
Images: opts.Images,
|
||||||
Format: opts.Format,
|
Format: json.RawMessage(opts.Format),
|
||||||
System: opts.System,
|
System: opts.System,
|
||||||
Options: opts.Options,
|
Options: opts.Options,
|
||||||
KeepAlive: opts.KeepAlive,
|
KeepAlive: opts.KeepAlive,
|
||||||
|
@ -148,10 +148,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Format != "" && req.Format != "json" {
|
if req.Raw && (req.Template != "" || req.System != "" || len(req.Context) > 0) {
|
||||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "format must be empty or \"json\""})
|
|
||||||
return
|
|
||||||
} else if req.Raw && (req.Template != "" || req.System != "" || len(req.Context) > 0) {
|
|
||||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "raw mode does not support template, system, or context"})
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "raw mode does not support template, system, or context"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -278,7 +275,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
|
|||||||
if err := r.Completion(c.Request.Context(), llm.CompletionRequest{
|
if err := r.Completion(c.Request.Context(), llm.CompletionRequest{
|
||||||
Prompt: prompt,
|
Prompt: prompt,
|
||||||
Images: images,
|
Images: images,
|
||||||
Format: json.RawMessage(req.Format),
|
Format: req.Format,
|
||||||
Options: opts,
|
Options: opts,
|
||||||
}, func(cr llm.CompletionResponse) {
|
}, func(cr llm.CompletionResponse) {
|
||||||
res := api.GenerateResponse{
|
res := api.GenerateResponse{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user