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
fabf2f34
Unverified
Commit
fabf2f34
authored
Dec 21, 2023
by
Bruce MacDonald
Committed by
GitHub
Dec 21, 2023
Browse files
allow for starting llava queries with filepath (#1549)
parent
a607d922
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
5 deletions
+24
-5
cmd/cmd.go
cmd/cmd.go
+24
-5
No files found.
cmd/cmd.go
View file @
fabf2f34
...
@@ -928,8 +928,23 @@ func generateInteractive(cmd *cobra.Command, opts generateOptions) error {
...
@@ -928,8 +928,23 @@ func generateInteractive(cmd *cobra.Command, opts generateOptions) error {
return
nil
return
nil
case
strings
.
HasPrefix
(
line
,
"/"
)
:
case
strings
.
HasPrefix
(
line
,
"/"
)
:
args
:=
strings
.
Fields
(
line
)
args
:=
strings
.
Fields
(
line
)
fmt
.
Printf
(
"Unknown command '%s'. Type /? for help
\n
"
,
args
[
0
])
isFile
:=
false
continue
if
multiModal
{
for
_
,
f
:=
range
extractFileNames
(
line
)
{
if
strings
.
HasPrefix
(
f
,
args
[
0
])
{
isFile
=
true
break
}
}
}
if
isFile
{
prompt
+=
line
}
else
{
fmt
.
Printf
(
"Unknown command '%s'. Type /? for help
\n
"
,
args
[
0
])
continue
}
default
:
default
:
prompt
+=
line
prompt
+=
line
}
}
...
@@ -937,7 +952,7 @@ func generateInteractive(cmd *cobra.Command, opts generateOptions) error {
...
@@ -937,7 +952,7 @@ func generateInteractive(cmd *cobra.Command, opts generateOptions) error {
if
len
(
prompt
)
>
0
&&
multiline
==
MultilineNone
{
if
len
(
prompt
)
>
0
&&
multiline
==
MultilineNone
{
opts
.
Prompt
=
prompt
opts
.
Prompt
=
prompt
if
multiModal
{
if
multiModal
{
newPrompt
,
images
,
err
:=
extractFile
Names
(
prompt
)
newPrompt
,
images
,
err
:=
extractFile
Data
(
prompt
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -991,13 +1006,17 @@ func normalizeFilePath(fp string) string {
...
@@ -991,13 +1006,17 @@ func normalizeFilePath(fp string) string {
return
fp
return
fp
}
}
func
extractFileNames
(
input
string
)
(
string
,
[]
ImageData
,
error
)
{
func
extractFileNames
(
input
string
)
[]
string
{
// Regex to match file paths starting with / or ./ and include escaped spaces (\ or %20)
// Regex to match file paths starting with / or ./ and include escaped spaces (\ or %20)
// and followed by more characters and a file extension
// and followed by more characters and a file extension
regexPattern
:=
`(?:\./|/)[\S\\ ]+?\.(?i:jpg|jpeg|png|svg)\b`
regexPattern
:=
`(?:\./|/)[\S\\ ]+?\.(?i:jpg|jpeg|png|svg)\b`
re
:=
regexp
.
MustCompile
(
regexPattern
)
re
:=
regexp
.
MustCompile
(
regexPattern
)
filePaths
:=
re
.
FindAllString
(
input
,
-
1
)
return
re
.
FindAllString
(
input
,
-
1
)
}
func
extractFileData
(
input
string
)
(
string
,
[]
ImageData
,
error
)
{
filePaths
:=
extractFileNames
(
input
)
var
imgs
[]
ImageData
var
imgs
[]
ImageData
for
_
,
fp
:=
range
filePaths
{
for
_
,
fp
:=
range
filePaths
{
...
...
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