diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-08-01 16:59:13 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-08-01 16:59:48 -0400 |
| commit | 7041695d49386f6e2cf660179c55f7f8a93b5ed3 (patch) | |
| tree | f290993f702e99008a1fd38d89fca3915399ecaa /web | |
| parent | d0f792048d3ad14bd35feff87cd71e4303efa763 (diff) | |
| download | x-7041695d49386f6e2cf660179c55f7f8a93b5ed3.tar.xz x-7041695d49386f6e2cf660179c55f7f8a93b5ed3.zip | |
web/ollama: add function support
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'web')
| -rw-r--r-- | web/ollama/ollama.go | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/web/ollama/ollama.go b/web/ollama/ollama.go index 5825c2c..98b24ff 100644 --- a/web/ollama/ollama.go +++ b/web/ollama/ollama.go @@ -29,10 +29,45 @@ func NewLocalClient() *Client { return NewClient("http://localhost:11434") } +type Function struct { + Name string `json:"name"` + Description string `json:"description,omitempty"` + Parameters Param `json:"parameters"` +} + +type Param struct { + Type string `json:"type"` + Description string `json:"description,omitempty"` + Enum []string `json:"enum,omitempty"` + Properties Properties `json:"properties"` + Required []string `json:"required,omitempty"` +} + +type Properties map[string]Param + +func (p Properties) MarshalJSON() ([]byte, error) { + if len(p) == 0 { + return []byte("{}"), nil + } + + return json.Marshal(map[string]Param(p)) +} + +type ToolCall struct { + Name string `json:"name"` + Arguments json.RawMessage `json:"arguments"` +} + +type Tool struct { + Type string `json:"type"` // "function" + Function Function `json:"function"` +} + type Message struct { - Content string `json:"content"` - Role string `json:"role"` - Images [][]byte `json:"images"` + Content string `json:"content"` + Role string `json:"role"` + Images [][]byte `json:"images"` + ToolCalls []ToolCall `json:"tool_calls"` } type CompleteRequest struct { @@ -42,6 +77,7 @@ type CompleteRequest struct { Template *string `json:"template,omitempty"` Stream bool `json:"stream"` Options map[string]any `json:"options"` + Tools []Tool `json:"tools"` } type CompleteResponse struct { |
