Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
c6c52627
Unverified
Commit
c6c52627
authored
Dec 04, 2024
by
Parth Sareen
Committed by
GitHub
Dec 04, 2024
Browse files
api: add generate endpoint for structured outputs (#7939)
parent
630e7dc6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
7 deletions
+4
-7
api/types.go
api/types.go
+1
-1
cmd/cmd.go
cmd/cmd.go
+1
-1
server/routes.go
server/routes.go
+2
-5
No files found.
api/types.go
View file @
c6c52627
...
@@ -67,7 +67,7 @@ type GenerateRequest struct {
...
@@ -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.
...
...
cmd/cmd.go
View file @
c6c52627
...
@@ -1126,7 +1126,7 @@ func generate(cmd *cobra.Command, opts runOptions) error {
...
@@ -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
,
...
...
server/routes.go
View file @
c6c52627
...
@@ -148,10 +148,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
...
@@ -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) {
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment