diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-08-03 22:23:54 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-08-03 22:23:54 -0400 |
| commit | 4ffd197b17689fce979943ffb739a7a1aff4ca12 (patch) | |
| tree | 7deae2d5245a3ebcee7d94f875a9106c17f10ccd /cmd/mimi | |
| parent | bdcd9eb26211bb5b10b1c41a2ffc609933d46033 (diff) | |
| download | x-4ffd197b17689fce979943ffb739a7a1aff4ca12.tar.xz x-4ffd197b17689fce979943ffb739a7a1aff4ca12.zip | |
test
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/mimi')
| -rw-r--r-- | cmd/mimi/Modelfile | 4 | ||||
| -rw-r--r-- | cmd/mimi/modules/discord/jufra/jufra.go | 40 | ||||
| -rw-r--r-- | cmd/mimi/modules/discord/jufra/system-prompt.txt | 1 | ||||
| -rw-r--r-- | cmd/mimi/modules/discord/jufra/tools.go | 25 |
4 files changed, 58 insertions, 12 deletions
diff --git a/cmd/mimi/Modelfile b/cmd/mimi/Modelfile index d0fec7f..23f2eab 100644 --- a/cmd/mimi/Modelfile +++ b/cmd/mimi/Modelfile @@ -1,5 +1,5 @@ FROM llama3.1 -SYSTEM """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 terse and to the point. You are a hacker, after all.""" +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.""" -PARAMETER num_ctx 131072
\ No newline at end of file +PARAMETER num_ctx 65536
\ No newline at end of file diff --git a/cmd/mimi/modules/discord/jufra/jufra.go b/cmd/mimi/modules/discord/jufra/jufra.go index 6772a07..a0d7ccd 100644 --- a/cmd/mimi/modules/discord/jufra/jufra.go +++ b/cmd/mimi/modules/discord/jufra/jufra.go @@ -6,6 +6,7 @@ package jufra import ( "bytes" "context" + _ "embed" "encoding/json" "flag" "log/slog" @@ -37,11 +38,13 @@ import ( var ( chatChannels = flag.String("jufra-chat-channels", "217096701771513856,1266740925137289287", "comma-separated list of channels to allow chat in") llamaGuardModel = flag.String("jufra-llama-guard-model", "xe/llamaguard3", "ollama model tag for llama guard") - mimiModel = flag.String("jufra-mimi-model", "llama3.1", "ollama model tag for mimi") - mimiSystemMessage = flag.String("jufra-mimi-system-message", "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 terse and to the point. You are a hacker, after all. Do not reply in JSON.", "system message for mimi") + mimiModel = flag.String("jufra-mimi-model", "xe/mimi:llama3.1", "ollama model tag for mimi") mimiVisionModel = flag.String("jufra-mimi-vision-model", "xe/mimi:vision3", "ollama model tag for mimi vision") mimiNames = flag.String("jufra-mimi-names", "mimi", "comma-separated list of names for mimi") disableLlamaguard = flag.Bool("jufra-unsafe-disable-llamaguard", false, "disable llamaguard") + + //go:embed system-prompt.txt + mimiSystemMessage string ) type Module struct { @@ -156,7 +159,7 @@ func (m *Module) messageCreate(s *discordgo.Session, mc *discordgo.MessageCreate if len(conv) == 0 { conv = append(conv, ollama.Message{ Role: "system", - Content: *mimiSystemMessage, + Content: mimiSystemMessage, }) } @@ -223,9 +226,9 @@ func (m *Module) messageCreate(s *discordgo.Session, mc *discordgo.MessageCreate Model: *mimiModel, Messages: conv, Options: map[string]any{ - "num_ctx": 131072, + "num_ctx": 65536, }, - Tools: m.getTools(), + //Tools: m.getTools(), } resp, err := m.ollama.Chat(context.Background(), cr) @@ -238,9 +241,27 @@ func (m *Module) messageCreate(s *discordgo.Session, mc *discordgo.MessageCreate conv = append(conv, resp.Message) if len(resp.Message.ToolCalls) != 0 { + slog.Info("got tool calls!", "msg", resp.Message) for _, tc := range resp.Message.ToolCalls { - if tc.Name == "run_python_code" { - msg, err := m.runPythonCode(context.Background(), tc) + switch tc.Function.Name { + case "reply": + type replyArgs struct { + Message string `json:"message"` + } + + var args replyArgs + + if err := json.Unmarshal(tc.Function.Arguments, &args); err != nil { + slog.Error("error decoding reply args", "err", err, "message_id", mc.ID, "channel_id", mc.ChannelID) + s.ChannelMessageSend(mc.ChannelID, "error decoding reply args") + return + } + + s.ChannelMessageSend(mc.ChannelID, args.Message) + + case "code_interpreter": + slog.Info("got run_python_code tool call", "message_id", mc.ID, "channel_id", mc.ChannelID, "tc", tc) + 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) s.ChannelMessageSend(mc.ChannelID, "error running python code") @@ -253,7 +274,7 @@ func (m *Module) messageCreate(s *discordgo.Session, mc *discordgo.MessageCreate Model: *mimiModel, Messages: conv, Options: map[string]any{ - "num_ctx": 131072, + "num_ctx": 65536, }, Tools: m.getTools(), }) @@ -264,6 +285,9 @@ func (m *Module) messageCreate(s *discordgo.Session, mc *discordgo.MessageCreate } conv = append(conv, resp.Message) + + default: + slog.Error("unknown tool call", "message_id", mc.ID, "channel_id", mc.ChannelID, "tool_call", tc) } } } diff --git a/cmd/mimi/modules/discord/jufra/system-prompt.txt b/cmd/mimi/modules/discord/jufra/system-prompt.txt new file mode 100644 index 0000000..4a9fff0 --- /dev/null +++ b/cmd/mimi/modules/discord/jufra/system-prompt.txt @@ -0,0 +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 lower case when possible.
\ 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 4c82c68..71f7c4c 100644 --- a/cmd/mimi/modules/discord/jufra/tools.go +++ b/cmd/mimi/modules/discord/jufra/tools.go @@ -12,7 +12,7 @@ import ( var normalTools = []ollama.Function{ { - Name: "run_python_code", + Name: "code_interpreter", Description: "Run the given Python code in a sandboxed environment", Parameters: ollama.Param{ Type: "object", @@ -25,6 +25,24 @@ var normalTools = []ollama.Function{ Required: []string{"code"}, }, }, + { + Name: "none", + Description: "No tools are relevant for this message", + }, + // { + // 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"}, + // }, + // }, } type pythonCodeArgs struct { @@ -54,7 +72,10 @@ func (m *Module) runPythonCode(ctx context.Context, tc ollama.ToolCall) (*ollama res, err := python.Run(ctx, tmpdir, args.Code) if err != nil { - return nil, nil + return &ollama.Message{ + Role: "tool", + Content: jsonString(map[string]string{"error": err.Error(), "stdout": res.Stdout, "stderr": res.Stderr}), + }, nil } return &ollama.Message{ |
