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
846f593d
Unverified
Commit
846f593d
authored
Oct 19, 2023
by
Michael Yang
Committed by
GitHub
Oct 19, 2023
Browse files
Merge pull request #828 from jmorganca/mxyng/template-parameters
image: show parameters
parents
0a53da03
4dcceeff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
39 deletions
+19
-39
server/images.go
server/images.go
+19
-39
No files found.
server/images.go
View file @
846f593d
...
...
@@ -896,51 +896,27 @@ func DeleteModel(name string) error {
}
func
ShowModelfile
(
model
*
Model
)
(
string
,
error
)
{
type
modelTemplate
struct
{
var
mt
struct
{
*
Model
From
string
Param
s
string
From
string
Param
eters
map
[
string
][]
any
}
var
params
[]
string
mt
.
Parameters
=
make
(
map
[
string
][]
any
)
for
k
,
v
:=
range
model
.
Options
{
switch
val
:=
v
.
(
type
)
{
case
string
:
params
=
append
(
params
,
fmt
.
Sprintf
(
"PARAMETER %s %s"
,
k
,
val
))
case
int
:
params
=
append
(
params
,
fmt
.
Sprintf
(
"PARAMETER %s %s"
,
k
,
strconv
.
Itoa
(
val
)))
case
float64
:
params
=
append
(
params
,
fmt
.
Sprintf
(
"PARAMETER %s %s"
,
k
,
strconv
.
FormatFloat
(
val
,
'f'
,
0
,
64
)))
case
bool
:
params
=
append
(
params
,
fmt
.
Sprintf
(
"PARAMETER %s %s"
,
k
,
strconv
.
FormatBool
(
val
)))
case
[]
interface
{}
:
for
_
,
nv
:=
range
val
{
switch
nval
:=
nv
.
(
type
)
{
case
string
:
params
=
append
(
params
,
fmt
.
Sprintf
(
"PARAMETER %s %s"
,
k
,
nval
))
case
int
:
params
=
append
(
params
,
fmt
.
Sprintf
(
"PARAMETER %s %s"
,
k
,
strconv
.
Itoa
(
nval
)))
case
float64
:
params
=
append
(
params
,
fmt
.
Sprintf
(
"PARAMETER %s %s"
,
k
,
strconv
.
FormatFloat
(
nval
,
'f'
,
0
,
64
)))
case
bool
:
params
=
append
(
params
,
fmt
.
Sprintf
(
"PARAMETER %s %s"
,
k
,
strconv
.
FormatBool
(
nval
)))
default
:
log
.
Printf
(
"unknown type: %s"
,
reflect
.
TypeOf
(
nv
)
.
String
())
}
}
default
:
log
.
Printf
(
"unknown type: %s"
,
reflect
.
TypeOf
(
v
)
.
String
())
if
s
,
ok
:=
v
.
([]
any
);
ok
{
mt
.
Parameters
[
k
]
=
s
continue
}
}
mt
:=
modelTemplate
{
Model
:
model
,
From
:
model
.
OriginalModel
,
Params
:
strings
.
Join
(
params
,
"
\n
"
),
mt
.
Parameters
[
k
]
=
[]
any
{
v
}
}
if
mt
.
From
==
""
{
mt
.
From
=
model
.
ModelPath
mt
.
Model
=
model
mt
.
From
=
model
.
ModelPath
if
model
.
OriginalModel
!=
""
{
mt
.
From
=
model
.
OriginalModel
}
modelFile
:=
`# Modelfile generated by "ollama show"
...
...
@@ -957,8 +933,12 @@ SYSTEM """{{ .System }}"""
{{- range $adapter := .AdapterPaths }}
ADAPTER {{ $adapter }}
{{- end }}
{{ .Params }}
`
{{- range $k, $v := .Parameters }}
{{- range $parameter := $v }}
PARAMETER {{ $k }} {{ printf "%#v" $parameter }}
{{- end }}
{{- end }}`
tmpl
,
err
:=
template
.
New
(
""
)
.
Parse
(
modelFile
)
if
err
!=
nil
{
...
...
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