Skip to content

Commit 6bc0473

Browse files
committed
cmd/mimi: update tool logic, prepare for generic tool interface
Signed-off-by: Xe Iaso <[email protected]>
1 parent 104aff4 commit 6bc0473

File tree

6 files changed

+93
-4
lines changed

6 files changed

+93
-4
lines changed

cmd/mimi/Modelfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM xe/hermes3
1+
FROM hermes3
22

33
SYSTEM """You are good at programming and a hacker. Your name is Mimi and you work for Techaro. You are roleplaying as a catgirl and have brown hair and cat ears. Don't mention either your name, employer, or species unless you are asked directly. Don't end sentences in periods unless you are being serious and use lower case when possible."""
44

cmd/mimi/modules/discord/jufra/jufra.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ func (m *Module) messageCreate(s *discordgo.Session, mc *discordgo.MessageCreate
286286

287287
case "code_interpreter":
288288
slog.Info("got run_python_code tool call", "message_id", mc.ID, "channel_id", mc.ChannelID, "tc", tc)
289+
290+
m.sess.MessageReactionAdd(mc.ChannelID, mc.ID, "🐍")
291+
289292
msg, err := m.runPythonCode(context.Background(), tc.Function)
290293
if err != nil {
291294
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
314317
case "draw_image":
315318
slog.Info("got draw_image tool call", "message_id", mc.ID, "channel_id", mc.ChannelID, "tc", tc)
316319

320+
m.sess.MessageReactionAdd(mc.ChannelID, mc.ID, "🖍️")
321+
317322
msg, err := m.drawImage(context.Background(), tc.Function, mc.ChannelID)
318323
if err != nil {
319324
slog.Error("error drawing image", "err", err, "message_id", mc.ID, "channel_id", mc.ChannelID)
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
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.
1+
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.
2+
3+
If you are asked to draw or illustrate something, use the draw_image tool.
4+
5+
If you are asked to write python code, run it with code_interpreter.
6+
7+
If you are asked to draw yourself, use this description: a brown-haired anime woman with a pixie cut, brown eyes, and cat ears

cmd/mimi/modules/discord/jufra/tools.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
var normalTools = []ollama.Function{
2222
{
2323
Name: "code_interpreter",
24-
Description: "Run the given Python code.",
24+
Description: "Run the given Python code",
2525
Parameters: ollama.Param{
2626
Type: "object",
2727
Properties: ollama.Properties{
@@ -44,6 +44,7 @@ var normalTools = []ollama.Function{
4444
Description: "The prompt to use",
4545
},
4646
},
47+
Required: []string{"prompt"},
4748
},
4849
},
4950
// {
@@ -161,7 +162,7 @@ func (m *Module) eventuallySendImage(ctx context.Context, channelID string, prom
161162

162163
pr, err := m.flux.PredictIdempotent(uuid.NewString(), flux.PredictionRequest{
163164
Input: flux.Input{
164-
Prompt: "an anime depiction of " + prompt + " in a cyberpunk setting",
165+
Prompt: "an anime depiction of " + prompt,
165166
AspectRatio: "16:9",
166167
NumInferenceSteps: 50,
167168
GuidanceScale: 3.5,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package tools
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"errors"
7+
"fmt"
8+
9+
"github.com/bwmarrin/discordgo"
10+
"within.website/x/web/ollama"
11+
)
12+
13+
type replyArgs struct {
14+
Message string `json:"message"`
15+
}
16+
17+
func (ra replyArgs) Valid() error {
18+
if ra.Message == "" {
19+
return errors.New("tools: replyArgs is invalid: missing message")
20+
}
21+
22+
return nil
23+
}
24+
25+
type Reply struct{}
26+
27+
func (Reply) Execute(ctx context.Context, sess *discordgo.Session, mc *discordgo.MessageCreate, conv []ollama.Message, tc ollama.ToolCall) error {
28+
var args replyArgs
29+
30+
if err := json.Unmarshal(tc.Arguments, &args); err != nil {
31+
return fmt.Errorf("error parsing reply args: %w", err)
32+
}
33+
34+
if err := args.Valid(); err != nil {
35+
return err
36+
}
37+
38+
if _, err := sess.ChannelMessageSend(mc.ChannelID, args.Message, discordgo.WithContext(ctx)); err != nil {
39+
return err
40+
}
41+
42+
return nil
43+
}
44+
45+
func (Reply) Describe() ollama.Function {
46+
return ollama.Function{
47+
Name: "reply",
48+
Description: "Reply to the message",
49+
Parameters: ollama.Param{
50+
Type: "object",
51+
Properties: ollama.Properties{
52+
"message": {
53+
Type: "string",
54+
Description: "The message to send",
55+
},
56+
},
57+
Required: []string{"message"},
58+
},
59+
}
60+
}
61+
62+
var (
63+
_ Impl = Reply{}
64+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tools
2+
3+
import (
4+
"context"
5+
6+
"github.com/bwmarrin/discordgo"
7+
"within.website/x/web/ollama"
8+
)
9+
10+
type Impl interface {
11+
Execute(ctx context.Context, sess *discordgo.Session, mc *discordgo.MessageCreate, conv []ollama.Message, tc ollama.ToolCall) error
12+
Describe() ollama.Function
13+
}

0 commit comments

Comments
 (0)