Skip to content

Commit

Permalink
cmd/mimi: update tool logic, prepare for generic tool interface
Browse files Browse the repository at this point in the history
Signed-off-by: Xe Iaso <[email protected]>
  • Loading branch information
Xe committed Sep 7, 2024
1 parent 104aff4 commit 6bc0473
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/mimi/Modelfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM xe/hermes3
FROM hermes3

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."""

Expand Down
5 changes: 5 additions & 0 deletions cmd/mimi/modules/discord/jufra/jufra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion cmd/mimi/modules/discord/jufra/system-prompt.txt
Original file line number Diff line number Diff line change
@@ -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.
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
5 changes: 3 additions & 2 deletions cmd/mimi/modules/discord/jufra/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -44,6 +44,7 @@ var normalTools = []ollama.Function{
Description: "The prompt to use",
},
},
Required: []string{"prompt"},
},
},
// {
Expand Down Expand Up @@ -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,
Expand Down
64 changes: 64 additions & 0 deletions cmd/mimi/modules/discord/jufra/tools/reply.go
Original file line number Diff line number Diff line change
@@ -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{}
)
13 changes: 13 additions & 0 deletions cmd/mimi/modules/discord/jufra/tools/tools.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6bc0473

Please sign in to comment.