aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2024-08-01 16:59:13 -0400
committerXe Iaso <me@xeiaso.net>2024-08-01 16:59:48 -0400
commit7041695d49386f6e2cf660179c55f7f8a93b5ed3 (patch)
treef290993f702e99008a1fd38d89fca3915399ecaa /web
parentd0f792048d3ad14bd35feff87cd71e4303efa763 (diff)
downloadx-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.go42
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 {