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
47500550
Commit
47500550
authored
Mar 10, 2025
by
Jesse Gross
Committed by
Michael Yang
Mar 11, 2025
Browse files
Restrict Gemma to a single image per request
parent
2c40c4d3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletion
+11
-1
server/prompt.go
server/prompt.go
+11
-1
No files found.
server/prompt.go
View file @
47500550
...
@@ -26,6 +26,7 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
...
@@ -26,6 +26,7 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
var
system
[]
api
.
Message
var
system
[]
api
.
Message
isMllama
:=
checkMllamaModelFamily
(
m
)
isMllama
:=
checkMllamaModelFamily
(
m
)
isGemma3
:=
checkGemma3ModelFamily
(
m
)
var
imageNumTokens
int
var
imageNumTokens
int
// TODO: Ideally we would compute this from the projector metadata but some pieces are implementation dependent
// TODO: Ideally we would compute this from the projector metadata but some pieces are implementation dependent
...
@@ -40,7 +41,7 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
...
@@ -40,7 +41,7 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
n
:=
len
(
msgs
)
-
1
n
:=
len
(
msgs
)
-
1
// in reverse, find all messages that fit into context window
// in reverse, find all messages that fit into context window
for
i
:=
n
;
i
>=
0
;
i
--
{
for
i
:=
n
;
i
>=
0
;
i
--
{
if
isMllama
&&
len
(
msgs
[
i
]
.
Images
)
>
1
{
if
(
isMllama
||
isGemma3
)
&&
len
(
msgs
[
i
]
.
Images
)
>
1
{
return
""
,
nil
,
errTooManyImages
return
""
,
nil
,
errTooManyImages
}
}
...
@@ -157,3 +158,12 @@ func checkMllamaModelFamily(m *Model) bool {
...
@@ -157,3 +158,12 @@ func checkMllamaModelFamily(m *Model) bool {
}
}
return
false
return
false
}
}
func
checkGemma3ModelFamily
(
m
*
Model
)
bool
{
for
_
,
arch
:=
range
m
.
Config
.
ModelFamilies
{
if
arch
==
"gemma3"
{
return
true
}
}
return
false
}
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