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
a30915bd
Commit
a30915bd
authored
Jun 11, 2024
by
Michael Yang
Browse files
add capabilities
parent
58e3fff3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
10 deletions
+26
-10
server/images.go
server/images.go
+18
-2
server/routes.go
server/routes.go
+4
-4
template/template_test.go
template/template_test.go
+4
-4
No files found.
server/images.go
View file @
a30915bd
...
...
@@ -34,6 +34,10 @@ import (
"github.com/ollama/ollama/version"
)
type
Capability
string
const
CapabilityCompletion
=
Capability
(
"completion"
)
type
registryOptions
struct
{
Insecure
bool
Username
string
...
...
@@ -58,8 +62,20 @@ type Model struct {
Template
*
template
.
Template
}
func
(
m
*
Model
)
IsEmbedding
()
bool
{
return
slices
.
Contains
(
m
.
Config
.
ModelFamilies
,
"bert"
)
||
slices
.
Contains
(
m
.
Config
.
ModelFamilies
,
"nomic-bert"
)
func
(
m
*
Model
)
Has
(
caps
...
Capability
)
bool
{
for
_
,
cap
:=
range
caps
{
switch
cap
{
case
CapabilityCompletion
:
if
slices
.
Contains
(
m
.
Config
.
ModelFamilies
,
"bert"
)
||
slices
.
Contains
(
m
.
Config
.
ModelFamilies
,
"nomic-bert"
)
{
return
false
}
default
:
slog
.
Error
(
"unknown capability"
,
"capability"
,
cap
)
return
false
}
}
return
true
}
func
(
m
*
Model
)
String
()
string
{
...
...
server/routes.go
View file @
a30915bd
...
...
@@ -122,8 +122,8 @@ func (s *Server) GenerateHandler(c *gin.Context) {
return
}
if
model
.
IsEmbedding
(
)
{
c
.
AbortWithStatus
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"embedding model
s do not support generate"
})
if
!
model
.
Has
(
CapabilityCompletion
)
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"%
s do
es
not support generate"
,
req
.
Model
)
})
return
}
...
...
@@ -1308,8 +1308,8 @@ func (s *Server) ChatHandler(c *gin.Context) {
return
}
if
model
.
IsEmbedding
(
)
{
c
.
AbortWithStatus
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"embedding model
s do not support chat"
})
if
!
model
.
Has
(
CapabilityCompletion
)
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"%
s do
es
not support chat"
,
req
.
Model
)
})
return
}
...
...
template/template_test.go
View file @
a30915bd
...
...
@@ -61,8 +61,8 @@ func TestNamed(t *testing.T) {
func
TestParse
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
template
string
capabilities
[]
string
template
string
vars
[]
string
}{
{
"{{ .Prompt }}"
,
[]
string
{
"prompt"
}},
{
"{{ .System }} {{ .Prompt }}"
,
[]
string
{
"prompt"
,
"system"
}},
...
...
@@ -81,8 +81,8 @@ func TestParse(t *testing.T) {
}
vars
:=
tmpl
.
Vars
()
if
!
slices
.
Equal
(
tt
.
capabilitie
s
,
vars
)
{
t
.
Errorf
(
"expected %v, got %v"
,
tt
.
capabilitie
s
,
vars
)
if
!
slices
.
Equal
(
tt
.
var
s
,
vars
)
{
t
.
Errorf
(
"expected %v, got %v"
,
tt
.
var
s
,
vars
)
}
})
}
...
...
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