diff options
author | Grail Finder <wohilas@gmail.com> | 2024-11-21 20:16:47 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2024-11-21 20:16:47 +0300 |
commit | cc84c037ece2a89424d490d9ee819f06cf4bb347 (patch) | |
tree | c2248cc666884bc475c32970a13d086b9aec159d /tools.go | |
parent | c35af037203ac5c39a4f704d5343bc2b5cc56a0c (diff) |
Enha: match tool call with regexp; clear panics
Diffstat (limited to 'tools.go')
-rw-r--r-- | tools.go | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -3,6 +3,7 @@ package main import ( "elefant/models" "encoding/json" + "regexp" "time" ) @@ -29,7 +30,8 @@ var ( // When making function call avoid typing anything else. 'tool' user will respond with the results of the call. // After that you are free to respond to the user. // ` - systemMsg = `You're a helpful assistant. + toolCallRE = regexp.MustCompile(`__tool_call__\s*([\s\S]*?)__tool_call__`) + systemMsg = `You're a helpful assistant. # Tools You can do functions call if needed. Your current tools: @@ -75,8 +77,8 @@ also: */ func memorise(args ...string) []byte { agent := assistantRole - if len(args) < 1 { - // TODO: log + if len(args) < 2 { + logger.Warn("not enough args to call memorise tool") return nil } memory := &models.Memory{ @@ -92,12 +94,13 @@ func memorise(args ...string) []byte { func recall(args ...string) []byte { agent := assistantRole if len(args) < 1 { - // TODO: log + logger.Warn("not enough args to call recall tool") return nil } mind, err := store.Recall(agent, args[0]) if err != nil { - panic(err) + logger.Error("failed to use tool", "error", err, "args", args) + return nil } return []byte(mind) } @@ -106,11 +109,13 @@ func recallTopics(args ...string) []byte { agent := assistantRole topics, err := store.RecallTopics(agent) if err != nil { - panic(err) + logger.Error("failed to use tool", "error", err, "args", args) + return nil } data, err := json.Marshal(topics) if err != nil { - panic(err) + logger.Error("failed to use tool", "error", err, "args", args) + return nil } return data } @@ -118,7 +123,7 @@ func recallTopics(args ...string) []byte { func fullMemoryLoad() {} // predifine funcs -func getUserDetails(id ...string) []byte { +func getUserDetails(args ...string) []byte { // db query // return DB[id[0]] m := map[string]any{ @@ -129,7 +134,8 @@ func getUserDetails(id ...string) []byte { } data, err := json.Marshal(m) if err != nil { - panic(err) + logger.Error("failed to use tool", "error", err, "args", args) + return nil } return data } |