diff options
| author | Grail Finder <wohilas@gmail.com> | 2026-03-02 07:12:28 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2026-03-02 07:12:28 +0300 |
| commit | caac1d397ad8e21c22219708c070e5e6608b7859 (patch) | |
| tree | 503e677925292e8d4b763de8a14c5c6b90db3bdf /tools.go | |
| parent | 742f1ca838f97cf7deaae624d93f307632863460 (diff) | |
Feat: read img tool for chat endpoint
Diffstat (limited to 'tools.go')
| -rw-r--r-- | tools.go | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -469,6 +469,43 @@ func fileRead(args map[string]string) []byte { return jsonResult } +func fileReadImage(args map[string]string) []byte { + path, ok := args["path"] + if !ok || path == "" { + msg := "path not provided to file_read_image tool" + logger.Error(msg) + return []byte(msg) + } + path = resolvePath(path) + dataURL, err := models.CreateImageURLFromPath(path) + if err != nil { + msg := "failed to read image; error: " + err.Error() + logger.Error(msg) + return []byte(msg) + } + // result := map[string]any{ + // "type": "multimodal_content", + // "parts": []map[string]string{ + // {"type": "text", "text": "Image at " + path}, + // {"type": "image_url", "url": dataURL}, + // }, + // } + result := models.MultimodalToolResp{ + Type: "multimodal_content", + Parts: []map[string]string{ + {"type": "text", "text": "Image at " + path}, + {"type": "image_url", "url": dataURL}, + }, + } + jsonResult, err := json.Marshal(result) + if err != nil { + msg := "failed to marshal result; error: " + err.Error() + logger.Error(msg) + return []byte(msg) + } + return jsonResult +} + func fileWrite(args map[string]string) []byte { path, ok := args["path"] if !ok || path == "" { @@ -1101,6 +1138,7 @@ var fnMap = map[string]fnSig{ "read_url_raw": readURLRaw, "file_create": fileCreate, "file_read": fileRead, + "file_read_image": fileReadImage, "file_write": fileWrite, "file_write_append": fileWriteAppend, "file_edit": fileEdit, @@ -1327,6 +1365,24 @@ var baseTools = []models.Tool{ }, }, }, + // file_read_image + models.Tool{ + Type: "function", + Function: models.ToolFunc{ + Name: "file_read_image", + Description: "Read an image file and return it for multimodal LLM viewing. Supports png, jpg, jpeg, gif, webp formats. Use when you need the LLM to see and analyze an image.", + Parameters: models.ToolFuncParams{ + Type: "object", + Required: []string{"path"}, + Properties: map[string]models.ToolArgProps{ + "path": models.ToolArgProps{ + Type: "string", + Description: "path of the image file to read", + }, + }, + }, + }, + }, // file_write models.Tool{ Type: "function", |
