Added base64 encode tool
This commit is contained in:
parent
1c538067af
commit
b2e6d24fed
41
main.go
41
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -24,7 +25,12 @@ func main() {
|
||||||
}
|
}
|
||||||
return scanner.Text(), true
|
return scanner.Text(), true
|
||||||
}
|
}
|
||||||
tools := []ToolDefinition{ReadFileDefinition, ListFilesDefinition, EditFileDefinition}
|
tools := []ToolDefinition{
|
||||||
|
ReadFileDefinition,
|
||||||
|
ListFilesDefinition,
|
||||||
|
EditFileDefinition,
|
||||||
|
Base64EncodeFileDefinition,
|
||||||
|
}
|
||||||
|
|
||||||
agent := NewAgent(&client, getUserMessage, tools)
|
agent := NewAgent(&client, getUserMessage, tools)
|
||||||
err := agent.Run(context.TODO())
|
err := agent.Run(context.TODO())
|
||||||
|
@ -336,3 +342,36 @@ func createNewFile(filePath, content string) (string, error) {
|
||||||
|
|
||||||
return fmt.Sprintf("Successfully created file %s", filePath), nil
|
return fmt.Sprintf("Successfully created file %s", filePath), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Base64EncodeFileDefinition = ToolDefinition{
|
||||||
|
Name: "base64_encode",
|
||||||
|
Description: `Generates a base64 encoding of a file.
|
||||||
|
|
||||||
|
This is especially useful when asked to describe an image file (you can use
|
||||||
|
this get a base64 encoded representation of the image file).
|
||||||
|
`,
|
||||||
|
InputSchema: Base64EncodeFileInputSchema,
|
||||||
|
Function: Base64EncodeFile,
|
||||||
|
}
|
||||||
|
|
||||||
|
type Base64EncodeFileInput struct {
|
||||||
|
Path string `json:"path" jsonschema_description:"The path to the image"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var Base64EncodeFileInputSchema = GenerateSchema[EditFileInput]()
|
||||||
|
|
||||||
|
func Base64EncodeFile(input json.RawMessage) (string, error) {
|
||||||
|
analyzeImageInput := Base64EncodeFileInput{}
|
||||||
|
err := json.Unmarshal(input, &analyzeImageInput)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := os.ReadFile(analyzeImageInput.Path)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
encoded := base64.StdEncoding.EncodeToString([]byte(content))
|
||||||
|
|
||||||
|
return encoded, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue