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
ccef9431
Unverified
Commit
ccef9431
authored
Jun 21, 2024
by
Daniel Hiltgen
Committed by
GitHub
Jun 21, 2024
Browse files
Merge pull request #5205 from dhiltgen/modelfile_use_mmap
Fix use_mmap parsing for modelfiles
parents
9a9e7d83
7e774922
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
api/types.go
api/types.go
+13
-0
api/types_test.go
api/types_test.go
+63
-0
No files found.
api/types.go
View file @
ccef9431
...
@@ -608,6 +608,19 @@ func FormatParams(params map[string][]string) (map[string]interface{}, error) {
...
@@ -608,6 +608,19 @@ func FormatParams(params map[string][]string) (map[string]interface{}, error) {
}
else
{
}
else
{
field
:=
valueOpts
.
FieldByName
(
opt
.
Name
)
field
:=
valueOpts
.
FieldByName
(
opt
.
Name
)
if
field
.
IsValid
()
&&
field
.
CanSet
()
{
if
field
.
IsValid
()
&&
field
.
CanSet
()
{
if
reflect
.
PointerTo
(
field
.
Type
())
==
reflect
.
TypeOf
((
*
TriState
)(
nil
))
{
boolVal
,
err
:=
strconv
.
ParseBool
(
vals
[
0
])
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid bool value %s"
,
vals
)
}
if
boolVal
{
out
[
key
]
=
TriStateTrue
}
else
{
out
[
key
]
=
TriStateFalse
}
continue
}
switch
field
.
Kind
()
{
switch
field
.
Kind
()
{
case
reflect
.
Float32
:
case
reflect
.
Float32
:
floatVal
,
err
:=
strconv
.
ParseFloat
(
vals
[
0
],
32
)
floatVal
,
err
:=
strconv
.
ParseFloat
(
vals
[
0
],
32
)
...
...
api/types_test.go
View file @
ccef9431
...
@@ -2,6 +2,7 @@ package api
...
@@ -2,6 +2,7 @@ package api
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"math"
"math"
"testing"
"testing"
"time"
"time"
...
@@ -141,3 +142,65 @@ func TestUseMmapParsingFromJSON(t *testing.T) {
...
@@ -141,3 +142,65 @@ func TestUseMmapParsingFromJSON(t *testing.T) {
})
})
}
}
}
}
func
TestUseMmapFormatParams
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
req
map
[
string
][]
string
exp
TriState
err
error
}{
{
name
:
"True"
,
req
:
map
[
string
][]
string
{
"use_mmap"
:
[]
string
{
"true"
},
},
exp
:
TriStateTrue
,
err
:
nil
,
},
{
name
:
"False"
,
req
:
map
[
string
][]
string
{
"use_mmap"
:
[]
string
{
"false"
},
},
exp
:
TriStateFalse
,
err
:
nil
,
},
{
name
:
"Numeric True"
,
req
:
map
[
string
][]
string
{
"use_mmap"
:
[]
string
{
"1"
},
},
exp
:
TriStateTrue
,
err
:
nil
,
},
{
name
:
"Numeric False"
,
req
:
map
[
string
][]
string
{
"use_mmap"
:
[]
string
{
"0"
},
},
exp
:
TriStateFalse
,
err
:
nil
,
},
{
name
:
"invalid string"
,
req
:
map
[
string
][]
string
{
"use_mmap"
:
[]
string
{
"foo"
},
},
exp
:
TriStateUndefined
,
err
:
fmt
.
Errorf
(
"invalid bool value [foo]"
),
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
resp
,
err
:=
FormatParams
(
test
.
req
)
require
.
Equal
(
t
,
err
,
test
.
err
)
respVal
,
ok
:=
resp
[
"use_mmap"
]
if
test
.
exp
!=
TriStateUndefined
{
assert
.
True
(
t
,
ok
,
"resp: %v"
,
resp
)
assert
.
Equal
(
t
,
test
.
exp
,
respVal
)
}
})
}
}
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