summaryrefslogtreecommitdiff
path: root/tools.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2026-03-02 07:12:28 +0300
committerGrail Finder <wohilas@gmail.com>2026-03-02 07:12:28 +0300
commitcaac1d397ad8e21c22219708c070e5e6608b7859 (patch)
tree503e677925292e8d4b763de8a14c5c6b90db3bdf /tools.go
parent742f1ca838f97cf7deaae624d93f307632863460 (diff)
Feat: read img tool for chat endpoint
Diffstat (limited to 'tools.go')
-rw-r--r--tools.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools.go b/tools.go
index 04ba554..1e6cfb8 100644
--- a/tools.go
+++ b/tools.go
@@ -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",