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
6347f501
Unverified
Commit
6347f501
authored
Jan 07, 2024
by
Daniel Hiltgen
Committed by
GitHub
Jan 07, 2024
Browse files
Merge pull request #1828 from dhiltgen/fix_llava
Accept windows paths for image processing
parents
5feec959
e0d05b0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
2 deletions
+54
-2
cmd/interactive.go
cmd/interactive.go
+3
-2
cmd/interactive_test.go
cmd/interactive_test.go
+51
-0
No files found.
cmd/interactive.go
View file @
6347f501
...
...
@@ -458,9 +458,10 @@ func normalizeFilePath(fp string) string {
}
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
optional drive letter, / ./ \
or .
\
and include escaped
or unescaped
spaces (\ or %20)
// and followed by more characters and a file extension
regexPattern
:=
`(?:\./|/)[\S\\ ]+?\.(?i:jpg|jpeg|png|svg)\b`
// This will capture non filename strings, but we'll check for file existence to remove mismatches
regexPattern
:=
`(?:[a-zA-Z]:)?(?:\./|/|\\)[\S\\ ]+?\.(?i:jpg|jpeg|png|svg)\b`
re
:=
regexp
.
MustCompile
(
regexPattern
)
return
re
.
FindAllString
(
input
,
-
1
)
...
...
cmd/interactive_test.go
0 → 100644
View file @
6347f501
package
cmd
import
(
"testing"
"github.com/stretchr/testify/assert"
)
func
TestExtractFilenames
(
t
*
testing
.
T
)
{
// Unix style paths
input
:=
` some preamble
./relative\ path/one.png inbetween1 ./not a valid two.jpg inbetween2
/unescaped space /three.jpeg inbetween3 /valid\ path/dir/four.png "./quoted with spaces/five.svg`
res
:=
extractFileNames
(
input
)
assert
.
Len
(
t
,
res
,
5
)
assert
.
Contains
(
t
,
res
[
0
],
"one.png"
)
assert
.
Contains
(
t
,
res
[
1
],
"two.jpg"
)
assert
.
Contains
(
t
,
res
[
2
],
"three.jpeg"
)
assert
.
Contains
(
t
,
res
[
3
],
"four.png"
)
assert
.
Contains
(
t
,
res
[
4
],
"five.svg"
)
assert
.
NotContains
(
t
,
res
[
4
],
'"'
)
assert
.
NotContains
(
t
,
res
,
"inbtween"
)
// Windows style paths
input
=
` some preamble
c:/users/jdoe/one.png inbetween1 c:/program files/someplace/two.jpg inbetween2
/absolute/nospace/three.jpeg inbetween3 /absolute/with space/four.png inbetween4
./relative\ path/five.svg inbetween5 "./relative with/spaces/six.png inbetween6
d:\path with\spaces\seven.svg inbetween7 c:\users\jdoe\eight.png inbetween8
d:\program files\someplace\nine.png inbetween9 "E:\program files\someplace\ten.svg some ending
`
res
=
extractFileNames
(
input
)
assert
.
Len
(
t
,
res
,
10
)
assert
.
NotContains
(
t
,
res
,
"inbtween"
)
assert
.
Contains
(
t
,
res
[
0
],
"one.png"
)
assert
.
Contains
(
t
,
res
[
0
],
"c:"
)
assert
.
Contains
(
t
,
res
[
1
],
"two.jpg"
)
assert
.
Contains
(
t
,
res
[
1
],
"c:"
)
assert
.
Contains
(
t
,
res
[
2
],
"three.jpeg"
)
assert
.
Contains
(
t
,
res
[
3
],
"four.png"
)
assert
.
Contains
(
t
,
res
[
4
],
"five.svg"
)
assert
.
Contains
(
t
,
res
[
5
],
"six.png"
)
assert
.
Contains
(
t
,
res
[
6
],
"seven.svg"
)
assert
.
Contains
(
t
,
res
[
6
],
"d:"
)
assert
.
Contains
(
t
,
res
[
7
],
"eight.png"
)
assert
.
Contains
(
t
,
res
[
7
],
"c:"
)
assert
.
Contains
(
t
,
res
[
8
],
"nine.png"
)
assert
.
Contains
(
t
,
res
[
8
],
"d:"
)
assert
.
Contains
(
t
,
res
[
9
],
"ten.svg"
)
assert
.
Contains
(
t
,
res
[
9
],
"E:"
)
}
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