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
5d75505e
Commit
5d75505e
authored
Dec 01, 2023
by
Michael Yang
Browse files
return model configuration in generate
parent
b9495ea1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
12 deletions
+39
-12
api/types.go
api/types.go
+10
-0
server/images.go
server/images.go
+19
-7
server/routes.go
server/routes.go
+10
-5
No files found.
api/types.go
View file @
5d75505e
...
@@ -203,12 +203,22 @@ type GenerateResponse struct {
...
@@ -203,12 +203,22 @@ type GenerateResponse struct {
CreatedAt
time
.
Time
`json:"created_at"`
CreatedAt
time
.
Time
`json:"created_at"`
Response
string
`json:"response"`
Response
string
`json:"response"`
ModelConfiguration
ModelConfiguration
`json:"model_configuration"`
Done
bool
`json:"done"`
Done
bool
`json:"done"`
Context
[]
int
`json:"context,omitempty"`
Context
[]
int
`json:"context,omitempty"`
Metrics
Metrics
}
}
type
ModelConfiguration
struct
{
ModelFormat
string
`json:"model_format"`
ModelFamily
string
`json:"model_family"`
ModelFamilies
[]
string
`json:"model_families"`
ModelType
string
`json:"model_type"`
FileType
string
`json:"file_type"`
}
func
(
m
*
Metrics
)
Summary
()
{
func
(
m
*
Metrics
)
Summary
()
{
if
m
.
TotalDuration
>
0
{
if
m
.
TotalDuration
>
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"total duration: %v
\n
"
,
m
.
TotalDuration
)
fmt
.
Fprintf
(
os
.
Stderr
,
"total duration: %v
\n
"
,
m
.
TotalDuration
)
...
...
server/images.go
View file @
5d75505e
...
@@ -36,6 +36,7 @@ type RegistryOptions struct {
...
@@ -36,6 +36,7 @@ type RegistryOptions struct {
type
Model
struct
{
type
Model
struct
{
Name
string
`json:"name"`
Name
string
`json:"name"`
Config
ConfigV2
ShortName
string
ShortName
string
ModelPath
string
ModelPath
string
OriginalModel
string
OriginalModel
string
...
@@ -137,16 +138,12 @@ type ManifestV2 struct {
...
@@ -137,16 +138,12 @@ type ManifestV2 struct {
}
}
type
ConfigV2
struct
{
type
ConfigV2
struct
{
ModelFormat
string
`json:"model_format"`
ModelFamily
string
`json:"model_family"`
ModelFamilies
[]
string
`json:"model_families"`
ModelType
string
`json:"model_type"`
FileType
string
`json:"file_type"`
RootFS
RootFS
`json:"rootfs"`
// required by spec
// required by spec
Architecture
string
`json:"architecture"`
Architecture
string
`json:"architecture"`
OS
string
`json:"os"`
OS
string
`json:"os"`
RootFS
RootFS
`json:"rootfs"`
api
.
ModelConfiguration
}
}
func
(
c
*
ConfigV2
)
SetModelFormat
(
format
string
)
{
func
(
c
*
ConfigV2
)
SetModelFormat
(
format
string
)
{
...
@@ -235,6 +232,21 @@ func GetModel(name string) (*Model, error) {
...
@@ -235,6 +232,21 @@ func GetModel(name string) (*Model, error) {
License
:
[]
string
{},
License
:
[]
string
{},
}
}
filename
,
err
:=
GetBlobsPath
(
manifest
.
Config
.
Digest
)
if
err
!=
nil
{
return
nil
,
err
}
configFile
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
return
nil
,
err
}
defer
configFile
.
Close
()
if
err
:=
json
.
NewDecoder
(
configFile
)
.
Decode
(
&
model
.
Config
);
err
!=
nil
{
return
nil
,
err
}
for
_
,
layer
:=
range
manifest
.
Layers
{
for
_
,
layer
:=
range
manifest
.
Layers
{
filename
,
err
:=
GetBlobsPath
(
layer
.
Digest
)
filename
,
err
:=
GetBlobsPath
(
layer
.
Digest
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
server/routes.go
View file @
5d75505e
...
@@ -198,7 +198,11 @@ func GenerateHandler(c *gin.Context) {
...
@@ -198,7 +198,11 @@ func GenerateHandler(c *gin.Context) {
// an empty request loads the model
// an empty request loads the model
if
req
.
Prompt
==
""
&&
req
.
Template
==
""
&&
req
.
System
==
""
{
if
req
.
Prompt
==
""
&&
req
.
Template
==
""
&&
req
.
System
==
""
{
c
.
JSON
(
http
.
StatusOK
,
api
.
GenerateResponse
{
CreatedAt
:
time
.
Now
()
.
UTC
(),
Model
:
req
.
Model
,
Done
:
true
})
c
.
JSON
(
http
.
StatusOK
,
api
.
GenerateResponse
{
CreatedAt
:
time
.
Now
()
.
UTC
(),
Model
:
req
.
Model
,
ModelConfiguration
:
model
.
Config
.
ModelConfiguration
,
Done
:
true
})
return
return
}
}
...
@@ -257,10 +261,11 @@ func GenerateHandler(c *gin.Context) {
...
@@ -257,10 +261,11 @@ func GenerateHandler(c *gin.Context) {
}
}
resp
:=
api
.
GenerateResponse
{
resp
:=
api
.
GenerateResponse
{
Model
:
r
.
Model
,
Model
:
r
.
Model
,
CreatedAt
:
r
.
CreatedAt
,
ModelConfiguration
:
model
.
Config
.
ModelConfiguration
,
Done
:
r
.
Done
,
CreatedAt
:
r
.
CreatedAt
,
Response
:
r
.
Content
,
Done
:
r
.
Done
,
Response
:
r
.
Content
,
Metrics
:
api
.
Metrics
{
Metrics
:
api
.
Metrics
{
TotalDuration
:
r
.
TotalDuration
,
TotalDuration
:
r
.
TotalDuration
,
LoadDuration
:
r
.
LoadDuration
,
LoadDuration
:
r
.
LoadDuration
,
...
...
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