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
ccfd41c4
Unverified
Commit
ccfd41c4
authored
Mar 13, 2025
by
Michael Yang
Committed by
GitHub
Mar 13, 2025
Browse files
Merge pull request #9742 from ollama/mxyng/engine-error-embeddings
fix: error on models that don't support embeddings
parents
45a13b1d
ec46f328
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
66 deletions
+9
-66
runner/ollamarunner/runner.go
runner/ollamarunner/runner.go
+7
-62
server/routes.go
server/routes.go
+2
-4
No files found.
runner/ollamarunner/runner.go
View file @
ccfd41c4
...
@@ -691,65 +691,6 @@ type EmbeddingResponse struct {
...
@@ -691,65 +691,6 @@ type EmbeddingResponse struct {
Embedding
[]
float32
`json:"embedding"`
Embedding
[]
float32
`json:"embedding"`
}
}
func
(
s
*
Server
)
embeddings
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
req
EmbeddingRequest
if
err
:=
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
req
);
err
!=
nil
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"bad request: %s"
,
err
),
http
.
StatusBadRequest
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
slog
.
Debug
(
"embedding request"
,
"content"
,
req
.
Content
)
seq
,
err
:=
s
.
NewSequence
(
req
.
Content
,
nil
,
NewSequenceParams
{
embedding
:
true
})
if
err
!=
nil
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"Failed to create new sequence: %v"
,
err
),
http
.
StatusInternalServerError
)
return
}
// Ensure there is a place to put the sequence, released when removed from s.seqs
if
err
:=
s
.
seqsSem
.
Acquire
(
r
.
Context
(),
1
);
err
!=
nil
{
if
errors
.
Is
(
err
,
context
.
Canceled
)
{
slog
.
Info
(
"aborting embeddings request due to client closing the connection"
)
}
else
{
slog
.
Error
(
"Failed to acquire semaphore"
,
"error"
,
err
)
}
return
}
s
.
mu
.
Lock
()
found
:=
false
for
i
,
sq
:=
range
s
.
seqs
{
if
sq
==
nil
{
seq
.
cache
,
seq
.
inputs
,
err
=
s
.
cache
.
LoadCacheSlot
(
seq
.
inputs
,
req
.
CachePrompt
)
if
err
!=
nil
{
s
.
mu
.
Unlock
()
http
.
Error
(
w
,
fmt
.
Sprintf
(
"Failed to load cache: %v"
,
err
),
http
.
StatusInternalServerError
)
return
}
s
.
seqs
[
i
]
=
seq
s
.
cond
.
Signal
()
found
=
true
break
}
}
s
.
mu
.
Unlock
()
if
!
found
{
http
.
Error
(
w
,
"could not find an available sequence"
,
http
.
StatusInternalServerError
)
return
}
embedding
:=
<-
seq
.
embedding
if
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
&
EmbeddingResponse
{
Embedding
:
embedding
,
});
err
!=
nil
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"failed to encode response: %v"
,
err
),
http
.
StatusInternalServerError
)
}
}
type
HealthResponse
struct
{
type
HealthResponse
struct
{
Status
string
`json:"status"`
Status
string
`json:"status"`
Progress
float32
`json:"progress"`
Progress
float32
`json:"progress"`
...
@@ -927,9 +868,13 @@ func Execute(args []string) error {
...
@@ -927,9 +868,13 @@ func Execute(args []string) error {
defer
listener
.
Close
()
defer
listener
.
Close
()
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
mux
.
HandleFunc
(
"/embedding"
,
server
.
embeddings
)
// TODO: support embeddings
mux
.
HandleFunc
(
"/completion"
,
server
.
completion
)
mux
.
HandleFunc
(
"POST /embedding"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
mux
.
HandleFunc
(
"/health"
,
server
.
health
)
http
.
Error
(
w
,
"this model does not support embeddings"
,
http
.
StatusNotImplemented
)
})
mux
.
HandleFunc
(
"POST /completion"
,
server
.
completion
)
mux
.
HandleFunc
(
"GET /health"
,
server
.
health
)
httpServer
:=
http
.
Server
{
httpServer
:=
http
.
Server
{
Handler
:
mux
,
Handler
:
mux
,
...
...
server/routes.go
View file @
ccfd41c4
...
@@ -483,8 +483,7 @@ func (s *Server) EmbedHandler(c *gin.Context) {
...
@@ -483,8 +483,7 @@ func (s *Server) EmbedHandler(c *gin.Context) {
}
}
if
err
:=
g
.
Wait
();
err
!=
nil
{
if
err
:=
g
.
Wait
();
err
!=
nil
{
slog
.
Error
(
"embedding generation failed"
,
"error"
,
err
)
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
strings
.
TrimSpace
(
err
.
Error
())})
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
fmt
.
Errorf
(
"failed to generate embeddings: %v"
,
err
)})
return
return
}
}
...
@@ -545,8 +544,7 @@ func (s *Server) EmbeddingsHandler(c *gin.Context) {
...
@@ -545,8 +544,7 @@ func (s *Server) EmbeddingsHandler(c *gin.Context) {
embedding
,
err
:=
r
.
Embedding
(
c
.
Request
.
Context
(),
req
.
Prompt
)
embedding
,
err
:=
r
.
Embedding
(
c
.
Request
.
Context
(),
req
.
Prompt
)
if
err
!=
nil
{
if
err
!=
nil
{
slog
.
Info
(
fmt
.
Sprintf
(
"embedding generation failed: %v"
,
err
))
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
strings
.
TrimSpace
(
err
.
Error
())})
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
fmt
.
Errorf
(
"failed to generate embedding: %v"
,
err
)})
return
return
}
}
...
...
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