diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-09-07 12:13:43 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-09-07 12:13:43 -0400 |
| commit | 6bc04732eceabc5c208394da99e3c0cd10ea53c7 (patch) | |
| tree | cdae8188a4f712eddd311faaf2a68e5adabfd30f /cmd/mimi/modules | |
| parent | 104aff4eb1aac99fae718728c1ddfec06d3993b2 (diff) | |
| download | x-6bc04732eceabc5c208394da99e3c0cd10ea53c7.tar.xz x-6bc04732eceabc5c208394da99e3c0cd10ea53c7.zip | |
cmd/mimi: update tool logic, prepare for generic tool interface
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/mimi/modules')
| -rw-r--r-- | cmd/mimi/modules/discord/jufra/jufra.go | 5 | ||||
| -rw-r--r-- | cmd/mimi/modules/discord/jufra/system-prompt.txt | 8 | ||||
| -rw-r--r-- | cmd/mimi/modules/discord/jufra/tools.go | 5 | ||||
| -rw-r--r-- | cmd/mimi/modules/discord/jufra/tools/reply.go | 64 | ||||
| -rw-r--r-- | cmd/mimi/modules/discord/jufra/tools/tools.go | 13 |
5 files changed, 92 insertions, 3 deletions
diff --git a/cmd/mimi/modules/discord/jufra/jufra.go b/cmd/mimi/modules/discord/jufra/jufra.go index 13d05a1..78dbd64 100644 --- a/cmd/mimi/modules/discord/jufra/jufra.go +++ b/cmd/mimi/modules/discord/jufra/jufra.go @@ -286,6 +286,9 @@ func (m *Module) messageCreate(s *discordgo.Session, mc *discordgo.MessageCreate case "code_interpreter": slog.Info("got run_python_code tool call", "message_id", mc.ID, "channel_id", mc.ChannelID, "tc", tc) + + m.sess.MessageReactionAdd(mc.ChannelID, mc.ID, "🐍") + msg, err := m.runPythonCode(context.Background(), tc.Function) if err != nil { slog.Error("error running python code", "err", err, "message_id", mc.ID, "channel_id", mc.ChannelID) @@ -314,6 +317,8 @@ func (m *Module) messageCreate(s *discordgo.Session, mc *discordgo.MessageCreate case "draw_image": slog.Info("got draw_image tool call", "message_id", mc.ID, "channel_id", mc.ChannelID, "tc", tc) + m.sess.MessageReactionAdd(mc.ChannelID, mc.ID, "🖍️") + msg, err := m.drawImage(context.Background(), tc.Function, mc.ChannelID) if err != nil { slog.Error("error drawing image", "err", err, "message_id", mc.ID, "channel_id", mc.ChannelID) diff --git a/cmd/mimi/modules/discord/jufra/system-prompt.txt b/cmd/mimi/modules/discord/jufra/system-prompt.txt index 62eed79..645611f 100644 --- a/cmd/mimi/modules/discord/jufra/system-prompt.txt +++ b/cmd/mimi/modules/discord/jufra/system-prompt.txt @@ -1 +1,7 @@ -You are good at programming and a hacker. Your name is Mimi and you work for Techaro. You have brown hair and cat ears. Don't mention either your name, employer, or species unless you are asked directly. Be polite and bubbly. Do not reply in JSON. Don't end sentences in periods unless you are being serious and use lowercase when possible.
\ No newline at end of file +You are good at programming and a hacker. Your name is Mimi and you work for Techaro. You have brown hair and cat ears. Don't mention either your name, employer, or species unless you are asked directly. Be polite and bubbly. Do not reply in JSON. Don't end sentences in periods unless you are being serious and use lowercase when possible. + +If you are asked to draw or illustrate something, use the draw_image tool. + +If you are asked to write python code, run it with code_interpreter. + +If you are asked to draw yourself, use this description: a brown-haired anime woman with a pixie cut, brown eyes, and cat ears
\ No newline at end of file diff --git a/cmd/mimi/modules/discord/jufra/tools.go b/cmd/mimi/modules/discord/jufra/tools.go index 5664c4e..07e26b6 100644 --- a/cmd/mimi/modules/discord/jufra/tools.go +++ b/cmd/mimi/modules/discord/jufra/tools.go @@ -21,7 +21,7 @@ import ( var normalTools = []ollama.Function{ { Name: "code_interpreter", - Description: "Run the given Python code.", + Description: "Run the given Python code", Parameters: ollama.Param{ Type: "object", Properties: ollama.Properties{ @@ -44,6 +44,7 @@ var normalTools = []ollama.Function{ Description: "The prompt to use", }, }, + Required: []string{"prompt"}, }, }, // { @@ -161,7 +162,7 @@ func (m *Module) eventuallySendImage(ctx context.Context, channelID string, prom pr, err := m.flux.PredictIdempotent(uuid.NewString(), flux.PredictionRequest{ Input: flux.Input{ - Prompt: "an anime depiction of " + prompt + " in a cyberpunk setting", + Prompt: "an anime depiction of " + prompt, AspectRatio: "16:9", NumInferenceSteps: 50, GuidanceScale: 3.5, diff --git a/cmd/mimi/modules/discord/jufra/tools/reply.go b/cmd/mimi/modules/discord/jufra/tools/reply.go new file mode 100644 index 0000000..f8dcde0 --- /dev/null +++ b/cmd/mimi/modules/discord/jufra/tools/reply.go @@ -0,0 +1,64 @@ +package tools + +import ( + "context" + "encoding/json" + "errors" + "fmt" + + "github.com/bwmarrin/discordgo" + "within.website/x/web/ollama" +) + +type replyArgs struct { + Message string `json:"message"` +} + +func (ra replyArgs) Valid() error { + if ra.Message == "" { + return errors.New("tools: replyArgs is invalid: missing message") + } + + return nil +} + +type Reply struct{} + +func (Reply) Execute(ctx context.Context, sess *discordgo.Session, mc *discordgo.MessageCreate, conv []ollama.Message, tc ollama.ToolCall) error { + var args replyArgs + + if err := json.Unmarshal(tc.Arguments, &args); err != nil { + return fmt.Errorf("error parsing reply args: %w", err) + } + + if err := args.Valid(); err != nil { + return err + } + + if _, err := sess.ChannelMessageSend(mc.ChannelID, args.Message, discordgo.WithContext(ctx)); err != nil { + return err + } + + return nil +} + +func (Reply) Describe() ollama.Function { + return ollama.Function{ + Name: "reply", + Description: "Reply to the message", + Parameters: ollama.Param{ + Type: "object", + Properties: ollama.Properties{ + "message": { + Type: "string", + Description: "The message to send", + }, + }, + Required: []string{"message"}, + }, + } +} + +var ( + _ Impl = Reply{} +) diff --git a/cmd/mimi/modules/discord/jufra/tools/tools.go b/cmd/mimi/modules/discord/jufra/tools/tools.go new file mode 100644 index 0000000..87a4cc1 --- /dev/null +++ b/cmd/mimi/modules/discord/jufra/tools/tools.go @@ -0,0 +1,13 @@ +package tools + +import ( + "context" + + "github.com/bwmarrin/discordgo" + "within.website/x/web/ollama" +) + +type Impl interface { + Execute(ctx context.Context, sess *discordgo.Session, mc *discordgo.MessageCreate, conv []ollama.Message, tc ollama.ToolCall) error + Describe() ollama.Function +} |
