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
8713ac23
Commit
8713ac23
authored
Aug 08, 2023
by
Jeffrey Morgan
Browse files
allow overriding `template` and `system` in `/api/generate`
Fixes #297 Fixes #296
parent
5eb712f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
api/types.go
api/types.go
+5
-3
server/images.go
server/images.go
+11
-2
No files found.
api/types.go
View file @
8713ac23
...
@@ -33,9 +33,11 @@ func (e StatusError) Error() string {
...
@@ -33,9 +33,11 @@ func (e StatusError) Error() string {
}
}
type
GenerateRequest
struct
{
type
GenerateRequest
struct
{
Model
string
`json:"model"`
Model
string
`json:"model"`
Prompt
string
`json:"prompt"`
Prompt
string
`json:"prompt"`
Context
[]
int
`json:"context,omitempty"`
System
string
`json:"system"`
Template
string
`json:"template"`
Context
[]
int
`json:"context,omitempty"`
Options
map
[
string
]
interface
{}
`json:"options"`
Options
map
[
string
]
interface
{}
`json:"options"`
}
}
...
...
server/images.go
View file @
8713ac23
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"html/template"
"io"
"io"
"log"
"log"
"net/http"
"net/http"
...
@@ -15,7 +16,6 @@ import (
...
@@ -15,7 +16,6 @@ import (
"reflect"
"reflect"
"strconv"
"strconv"
"strings"
"strings"
"text/template"
"github.com/jmorganca/ollama/api"
"github.com/jmorganca/ollama/api"
"github.com/jmorganca/ollama/parser"
"github.com/jmorganca/ollama/parser"
...
@@ -37,7 +37,12 @@ type Model struct {
...
@@ -37,7 +37,12 @@ type Model struct {
}
}
func
(
m
*
Model
)
Prompt
(
request
api
.
GenerateRequest
)
(
string
,
error
)
{
func
(
m
*
Model
)
Prompt
(
request
api
.
GenerateRequest
)
(
string
,
error
)
{
tmpl
,
err
:=
template
.
New
(
""
)
.
Parse
(
m
.
Template
)
t
:=
m
.
Template
if
request
.
Template
!=
""
{
t
=
request
.
Template
}
tmpl
,
err
:=
template
.
New
(
""
)
.
Parse
(
t
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -56,6 +61,10 @@ func (m *Model) Prompt(request api.GenerateRequest) (string, error) {
...
@@ -56,6 +61,10 @@ func (m *Model) Prompt(request api.GenerateRequest) (string, error) {
vars
.
Prompt
=
request
.
Prompt
vars
.
Prompt
=
request
.
Prompt
vars
.
Context
=
request
.
Context
vars
.
Context
=
request
.
Context
if
request
.
System
!=
""
{
vars
.
System
=
request
.
System
}
var
sb
strings
.
Builder
var
sb
strings
.
Builder
if
err
:=
tmpl
.
Execute
(
&
sb
,
vars
);
err
!=
nil
{
if
err
:=
tmpl
.
Execute
(
&
sb
,
vars
);
err
!=
nil
{
return
""
,
err
return
""
,
err
...
...
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