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
084929c2
Unverified
Commit
084929c2
authored
Oct 28, 2024
by
Patrick Devine
Committed by
GitHub
Oct 28, 2024
Browse files
add mllama image processing to the generate handler (#7384)
parent
abd5dfd0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
1 deletion
+20
-1
server/routes.go
server/routes.go
+20
-1
No files found.
server/routes.go
View file @
084929c2
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"cmp"
"context"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
...
...
@@ -33,6 +34,7 @@ import (
"github.com/ollama/ollama/openai"
"github.com/ollama/ollama/parser"
"github.com/ollama/ollama/runners"
"github.com/ollama/ollama/server/imageproc"
"github.com/ollama/ollama/template"
"github.com/ollama/ollama/types/errtypes"
"github.com/ollama/ollama/types/model"
...
...
@@ -189,7 +191,24 @@ func (s *Server) GenerateHandler(c *gin.Context) {
images
:=
make
([]
llm
.
ImageData
,
len
(
req
.
Images
))
for
i
:=
range
req
.
Images
{
images
[
i
]
=
llm
.
ImageData
{
ID
:
i
,
Data
:
req
.
Images
[
i
]}
if
isMllama
{
data
,
aspectRatioID
,
err
:=
imageproc
.
Preprocess
(
req
.
Images
[
i
])
if
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
"error processing image"
})
return
}
buf
:=
new
(
bytes
.
Buffer
)
err
=
binary
.
Write
(
buf
,
binary
.
LittleEndian
,
data
)
if
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
"error processing image"
})
return
}
images
[
i
]
=
llm
.
ImageData
{
Data
:
buf
.
Bytes
(),
AspectRatioID
:
aspectRatioID
}
}
else
{
images
[
i
]
=
llm
.
ImageData
{
ID
:
i
,
Data
:
req
.
Images
[
i
]}
}
}
prompt
:=
req
.
Prompt
...
...
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