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
d125510b
Commit
d125510b
authored
Feb 01, 2024
by
Michael Yang
Browse files
remove image tags
parent
fb569880
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
+15
-10
server/images.go
server/images.go
+1
-2
server/routes.go
server/routes.go
+14
-8
No files found.
server/images.go
View file @
d125510b
...
@@ -184,10 +184,9 @@ func (m *Model) ChatPrompts(msgs []api.Message) (*ChatHistory, error) {
...
@@ -184,10 +184,9 @@ func (m *Model) ChatPrompts(msgs []api.Message) (*ChatHistory, error) {
for
i
:=
range
msg
.
Images
{
for
i
:=
range
msg
.
Images
{
currentVars
.
Prompt
+=
fmt
.
Sprintf
(
" [img-%d]"
,
len
(
images
)
+
i
)
currentVars
.
Prompt
+=
fmt
.
Sprintf
(
" [img-%d]"
,
len
(
images
)
+
i
)
currentVars
.
Images
=
append
(
currentVars
.
Images
,
llm
.
ImageData
{
currentVars
.
Images
=
append
(
currentVars
.
Images
,
llm
.
ImageData
{
ID
:
i
,
ID
:
len
(
images
)
+
i
,
Data
:
msg
.
Images
[
i
],
Data
:
msg
.
Images
[
i
],
})
})
}
}
images
=
append
(
images
,
currentVars
.
Images
...
)
images
=
append
(
images
,
currentVars
.
Images
...
)
...
...
server/routes.go
View file @
d125510b
...
@@ -1254,7 +1254,8 @@ func trimmedPrompt(ctx context.Context, chat *ChatHistory, model *Model) (string
...
@@ -1254,7 +1254,8 @@ func trimmedPrompt(ctx context.Context, chat *ChatHistory, model *Model) (string
var
images
[]
llm
.
ImageData
var
images
[]
llm
.
ImageData
// reverse iterate through the prompts to build the prompt string in a way that fits the max context length
// reverse iterate through the prompts to build the prompt string in a way that fits the max context length
for
i
:=
len
(
chat
.
Prompts
)
-
1
;
i
>=
0
;
i
--
{
for
i
:=
len
(
chat
.
Prompts
)
-
1
;
i
>=
0
;
i
--
{
promptText
,
err
:=
promptString
(
model
,
chat
.
Prompts
[
i
],
i
==
len
(
chat
.
Prompts
)
-
1
)
prompt
:=
chat
.
Prompts
[
i
]
promptText
,
err
:=
promptString
(
model
,
prompt
,
i
==
len
(
chat
.
Prompts
)
-
1
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
...
@@ -1268,15 +1269,20 @@ func trimmedPrompt(ctx context.Context, chat *ChatHistory, model *Model) (string
...
@@ -1268,15 +1269,20 @@ func trimmedPrompt(ctx context.Context, chat *ChatHistory, model *Model) (string
break
// reached max context length, stop adding more prompts
break
// reached max context length, stop adding more prompts
}
}
totalTokenLength
+=
len
(
encodedTokens
)
for
j
:=
range
prompt
.
Images
{
systemPromptIncluded
=
systemPromptIncluded
||
chat
.
Prompts
[
i
]
.
System
!=
""
if
totalTokenLength
+
768
>
loaded
.
NumCtx
{
promptsToAdd
=
append
(
promptsToAdd
,
promptInfo
{
vars
:
chat
.
Prompts
[
i
],
tokenLen
:
len
(
encodedTokens
)})
// this decreases the token length but overestimating is fine
prompt
.
Prompt
=
strings
.
ReplaceAll
(
prompt
.
Prompt
,
fmt
.
Sprintf
(
" [img-%d]"
,
prompt
.
Images
[
j
]
.
ID
),
""
)
continue
}
images
=
append
(
images
,
chat
.
Prompts
[
i
]
.
Images
...
)
totalTokenLength
+=
768
images
=
append
(
images
,
prompt
.
Images
[
j
])
}
// clip has a projection dimension of 768
totalTokenLength
+=
len
(
encodedTokens
)
// TODO: use kv['clip.vision.projection_dim'] from projection instead
systemPromptIncluded
=
systemPromptIncluded
||
prompt
.
System
!=
""
totalTokenLength
+=
768
*
len
(
chat
.
Prompts
[
i
]
.
Images
)
promptsToAdd
=
append
(
promptsToAdd
,
promptInfo
{
vars
:
prompt
,
tokenLen
:
len
(
encodedTokens
)}
)
}
}
// ensure the system prompt is included, if not already
// ensure the system prompt is included, if not already
...
...
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