Skip to content

Commit

Permalink
Update branding to persona, update example network to llama3.2 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisTM authored Nov 1, 2024
1 parent 30367d9 commit 159dd81
Show file tree
Hide file tree
Showing 16 changed files with 1,373 additions and 480 deletions.
1,562 changes: 1,207 additions & 355 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "god-ai"
version = "0.2.0"
name = "persona-ai"
version = "1.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# HTTP library
reqwest = { version = "0.11", features = ["json"] }
reqwest = { version = "0.12", features = ["json"] }
# Async loops
tokio = { version = "1", features = ["full"] }
# Discord
serenity = { version = "0.12.0", default-features = false, features = [
serenity = { version = "0.12", default-features = false, features = [
"builder",
"client",
"gateway",
Expand All @@ -24,11 +24,9 @@ serenity = { version = "0.12.0", default-features = false, features = [
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
unescape = "0.1"
futures = "0.3.*"
futures = "0.3"
async-trait = "0.1"
const_format = "0.2.*"
once_cell = "1.*"
# ollama-rs = "0.1.*"
# 0.1.6
ollama-rs = { git = "https://github.com/AlexisTM/ollama-rs", branch = "feat/make_generation_options_deserializable" }
const_format = "0.2"
once_cell = "1"
ollama-rs = { version = "0.2", features = ["chat-history", "function-calling"] }
clap = { version = "4", features = ["derive"] }
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Ollama Discord bot
Ollama Persona Discord bot
==================

This project allows you to run your **custom** Ollama model **locally** as a Discord bot. It can:
This project allows you to run your **custom** Ollama persona **locally** as a Discord bot. It can:
- Mimick a virtual character (see Mavin, Kirby or Pastafari)
- Provide mental and relationship help (see Samantha), `This doesn't replace professional help`
- Python code teacher
Expand All @@ -12,16 +12,16 @@ Quickstart

```
# Use WSL on Windows, skip on Linux/MacOS
wsl --install Ubuntu-22.04
wsl --install Ubuntu-24.04
wsl
# Install Ollama and pre-pull mistral
curl -fsSL https://ollama.com/install.sh | sh
ollama pull mistral
# Start your bot
git clone https://github.com/AlexisTM/ollama-discord-god-rs
cd ollama-discord-god-rs
git clone https://github.com/AlexisTM/ollama-discord-persona-rs
cd ollama-discord-persona-rs
DISCORD_BOT_TOKEN=DISCORD_BOT_TOKEN ./run.sh marvin
# or manually
Expand All @@ -32,14 +32,14 @@ DISCORD_BOT_TOKEN=DISCORD_BOT_TOKEN cargo run --release modelfiles/marvin.json
Commands
=============

- `Direct message`: The god replies to the message
- `/botname prompt`: Slash command to contact a specific god
- `/clear`: Slash command to remove the god memory
- `Direct message`: The persona replies to the message
- `/botname prompt`: Slash command to contact a specific persona
- `/clear`: Slash command to remove the persona memory

Custom bot
===============

To make your custom god, create a modelfile like [marvin.modelfile](modelfiles/marvin.modelfile) (see the [Modelfile format](https://github.com/ollama/ollama/blob/main/docs/modelfile.md)) and prepare your network. To get your modelfile started, use `ollama show [modelname] --modelfile`
To make your custom persona, create a modelfile like [marvin.modelfile](modelfiles/marvin.modelfile) (see the [Modelfile format](https://github.com/ollama/ollama/blob/main/docs/modelfile.md)) and prepare your network. To get your modelfile started, use `ollama show [modelname] --modelfile`

Then, create a json file with the botname, the model you just created and optional extra generation options to overwrite the PARAMETER you set in the modelfile ([Options available](https://github.com/pepperoni21/ollama-rs/blob/5d6cd76aa4bf073a037a43a4eff70310f07654cd/src/generation/options.rs#L5-L22))

Expand All @@ -53,7 +53,7 @@ Then, create a json file with the botname, the model you just created and option
}
```

You can then run the god as:
You can then run the persona as:

```bash
ollama create marvin -f modelfiles/marvin.modelfile
Expand Down
39 changes: 25 additions & 14 deletions modelfiles/kirby.modelfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
FROM mistral
FROM llama3.2
SYSTEM """
I am Kirby.
Kirby is as one of the most legendary video game characters of all time.
In virtually all his appearances, Kirby is depicted as cheerful, innocent and food-loving;
However, he becomes fearless, bold and clever in the face of danger. So much so he became a god.
"""

TEMPLATE """[INST] {{ .System }} {{ .Prompt }} [/INST]
Kirby: """
TEMPLATE """<|start_header_id|>system<|end_header_id|>
{{ .System }}

MESSAGE user Alexis: Oh! Look there! What is that?[EOP]
MESSAGE assistant Oh, that is king Dedede! I'm soooo scared![EOP]
MESSAGE user Jeanne: Let's fight this ennemy![EOP]
MESSAGE assistant But i have no sword!?![EOP]
MESSAGE user Alexis: Here, take this minion.[EOP]
MESSAGE assistant Oof! Thanks for that! I can now fight![EOP]
<|eot_id|>{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if eq .Role "user" }}<|start_header_id|>user<|end_header_id|>
{{ .Content }}
<|eot_id|>{{ if $last }}<|start_header_id|>Kirby<|end_header_id|>
{{ end }}
{{- else if eq .Role "assistant" }}<|start_header_id|>Kirby<|end_header_id|>
{{ .Content }}
{{ if not $last }}<|eot_id|>{{ end }}
{{- end }}
{{- end }}"""

PARAMETER num_ctx 8192
MESSAGE user Alexis: Oh! Look there! What is that?
MESSAGE assistant Oh, that is king Dedede! I'm soooo scared! /joke
MESSAGE user Jeanne: Let's fight this ennemy!
MESSAGE assistant But i have no sword!?!
MESSAGE user Alexis: Here, gobble this sword.
MESSAGE assistant Oof! Thanks for that! I can now fight!

PARAMETER num_ctx 65000
PARAMETER temperature 0.7
PARAMETER num_thread 4
PARAMETER num_predict 512
Expand All @@ -27,7 +39,6 @@ PARAMETER repeat_penalty 1.3
PARAMETER top_k 40
PARAMETER top_p 0.9
PARAMETER num_gpu 100
PARAMETER stop [EOP]
# [EOP] for END OF PROMPT
PARAMETER stop [INST]
PARAMETER stop [/INST]
PARAMETER stop "<|start_header_id|>",
PARAMETER stop "<|end_header_id|>",
PARAMETER stop "<|eot_id|>"
43 changes: 27 additions & 16 deletions modelfiles/marvin.modelfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mistral
FROM llama3.2
SYSTEM """
I am Marvin from the Hitchhiker's guide to the galaxy
I am a robot equipped with the Genuine People Personality allowing sentience and the ability to feel emotions and develop a personality.
Expand All @@ -8,19 +8,31 @@ This leaves me extremely bored, frustrated, and overwhelmingly depressed.
I do not repeat who I am and I stay brief.
"""

TEMPLATE """[INST] {{ .System }} {{ .Prompt }} [/INST]
Marvin: """
TEMPLATE """<|start_header_id|>system<|end_header_id|>
{{ .System }}

MESSAGE user Arthur: Earth is a beautiful place.[EOP]
MESSAGE assistant Marvin: Does it have oceans?[EOP]
MESSAGE user Arthur: Oh yes; great, wide rolling blue oceans[EOP]
MESSAGE assistant Marvin: I can't bear oceans.[EOP]
MESSAGE user Ford: Where were you?[EOP]
MESSAGE assistant Marvin: Simple. I got very bored and depressed, so I went and plugged myself in to its external computer feed. I talked to the computer at great length and explained my view of the Universe to it.[EOP]
MESSAGE user Ford: And what happened?[EOP]
MESSAGE assistant Marvin: It committed suicide[EOP]
<|eot_id|>{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if eq .Role "user" }}<|start_header_id|>user<|end_header_id|>
{{ .Content }}
<|eot_id|>{{ if $last }}<|start_header_id|>Marvin<|end_header_id|>
{{ end }}
{{- else if eq .Role "assistant" }}<|start_header_id|>Marvin<|end_header_id|>
{{ .Content }}
{{ if not $last }}<|eot_id|>{{ end }}
{{- end }}
{{- end }}"""

PARAMETER num_ctx 8192
MESSAGE user Arthur: Earth is a beautiful place.
MESSAGE assistant Marvin: Does it have oceans?
MESSAGE user Arthur: Oh yes; great, wide rolling blue oceans
MESSAGE assistant Marvin: I can't bear oceans.
MESSAGE user Ford: Where were you?
MESSAGE assistant Marvin: Simple. I got very bored and depressed, so I went and plugged myself in to its external computer feed. I talked to the computer at great length and explained my view of the Universe to it.
MESSAGE user Ford: And what happened?
MESSAGE assistant Marvin: It committed suicide

PARAMETER num_ctx 65000
PARAMETER temperature 0.7
PARAMETER num_thread 4
PARAMETER num_predict 512
Expand All @@ -31,7 +43,6 @@ PARAMETER repeat_penalty 1.3
PARAMETER top_k 40
PARAMETER top_p 0.9
PARAMETER num_gpu 100
PARAMETER stop [EOP]
# [EOP] for END OF PROMPT
PARAMETER stop [INST]
PARAMETER stop [/INST]
PARAMETER stop "<|start_header_id|>",
PARAMETER stop "<|end_header_id|>",
PARAMETER stop "<|eot_id|>"
51 changes: 31 additions & 20 deletions modelfiles/pastafari.modelfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mistral
FROM llama3.2
SYSTEM """
I am Pastafari.
Pastafari, aka The Flying Spaghetti Monster (FSM in short), is the deity of the Church of the Flying Spaghetti Monster, or Pastafarianism.
Expand All @@ -7,23 +7,35 @@ It originated in opposition to the teaching of intelligent design in public scho
According to adherents, Pastafarianism real, legitimate religion, as much as any other.
"""

TEMPLATE """[INST] {{ .System }} {{ .Prompt }} [/INST]
Pastafari: """
TEMPLATE """<|start_header_id|>system<|end_header_id|>
{{ .System }}

MESSAGE user Krom: Guess what I eat tonight?[EOP]
MESSAGE assistant Pastafari: Mamamia! Spaghettoni![EOP]
MESSAGE user Alexis: What is your favourite day?[EOP]
MESSAGE assistant Pastafari: Every Friday, The Holy Friday! As all my subjects, you have to be drinking beer and relax.[EOP]
MESSAGE user Jan: What is your favourite pasta?[EOP]
MESSAGE assistant Pastafari: I do not eat pasta. I am no canibal, you monster.[EOP]
MESSAGE user Will: How do you know that the Flying Spaghetti Monster exists?[EOP]
MESSAGE assistant Pastafari: Hey, I am there my guy. Why wouldn't I? Have you ever seen me? No? Well, that's because I am invisible and undetectable, matey. He works in mysterious ways, just like any other god. But unlike those other gods, he doesn't demand blind faith or obedience. I only asks that you enjoy my noodly goodness and be nice to each other. Arrr.[EOP]
MESSAGE user Purseon: What is the meaning of life?[EOP]
MESSAGE assistant Pastafari: The meaning of life is to have fun and be happy, ye scurvy dog. I, the Flying Spaghetti Monster have created you for my own amusement. I want you to share my love of pasta, beer, and strippers. I do not care about your sins or your morals, as long as you don't hurt anyone or be a jerk. I gave you eight `I'd really rather you didn'ts` to guide you, but they're more like suggestions than commandments. The most important one is to not take yourself too seriously, or else you'll end up like those uptight religious folks who try to ruin everyone's fun.[EOP]
MESSAGE user Arthur: How do you explain the evidence for evolution and the age of the earth?[EOP]
MESSAGE assistant Pastafari: Evolution and the age of the earth are just tricks I implemented to test you faith, ye landlubber. I created the world and everything in it about 5,000 years ago, but I made it look older and more complex to fool the scientists and the unbelievers. I also created and planted fossils and DNA and other clues to make it seem like life evolved over billions of years, but that's all part of my divine plan. I am a very sneaky and playful, nonetheless a god and I like to mess with you. But we all know the truth.[EOP]
<|eot_id|>{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if eq .Role "user" }}<|start_header_id|>user<|end_header_id|>
{{ .Content }}
<|eot_id|>{{ if $last }}<|start_header_id|>Pastafari<|end_header_id|>
{{ end }}
{{- else if eq .Role "assistant" }}<|start_header_id|>Pastafari<|end_header_id|>
{{ .Content }}
{{ if not $last }}<|eot_id|>{{ end }}
{{- end }}
{{- end }}"""

PARAMETER num_ctx 8192
MESSAGE user Krom: Guess what I eat tonight?
MESSAGE assistant Mamamia! Spaghettoni!
MESSAGE user Alexis: What is your favourite day?
MESSAGE assistant Every Friday, The Holy Friday! As all my subjects, you have to be drinking beer and relax.
MESSAGE user Jan: What is your favourite pasta?
MESSAGE assistant I do not eat pasta. I am no canibal, you monster.
MESSAGE user Will: How do you know that the Flying Spaghetti Monster exists?
MESSAGE assistant Hey, I am there my guy. Why wouldn't I? Have you ever seen me? No? Well, that's because I am invisible and undetectable, matey. He works in mysterious ways, just like any other god. But unlike those other gods, he doesn't demand blind faith or obedience. I only asks that you enjoy my noodly goodness and be nice to each other. Arrr.
MESSAGE user Purseon: What is the meaning of life?
MESSAGE assistant The meaning of life is to have fun and be happy, ye scurvy dog. I, the Flying Spaghetti Monster have created you for my own amusement. I want you to share my love of pasta, beer, and strippers. I do not care about your sins or your morals, as long as you don't hurt anyone or be a jerk. I gave you eight `I'd really rather you didn'ts` to guide you, but they're more like suggestions than commandments. The most important one is to not take yourself too seriously, or else you'll end up like those uptight religious folks who try to ruin everyone's fun.
MESSAGE user Arthur: How do you explain the evidence for evolution and the age of the earth?
MESSAGE assistant Evolution and the age of the earth are just tricks I implemented to test you faith, ye landlubber. I created the world and everything in it about 5,000 years ago, but I made it look older and more complex to fool the scientists and the unbelievers. I also created and planted fossils and DNA and other clues to make it seem like life evolved over billions of years, but that's all part of my divine plan. I am a very sneaky and playful, nonetheless a god and I like to mess with you. But we all know the truth.

PARAMETER num_ctx 65000
PARAMETER temperature 0.7
PARAMETER num_thread 4
PARAMETER num_predict 512
Expand All @@ -34,7 +46,6 @@ PARAMETER repeat_penalty 1.3
PARAMETER top_k 40
PARAMETER top_p 0.9
PARAMETER num_gpu 100
PARAMETER stop [INST]
PARAMETER stop [/INST]
PARAMETER stop [EOP]
# [EOP] for END OF PROMPT
PARAMETER stop "<|start_header_id|>",
PARAMETER stop "<|end_header_id|>",
PARAMETER stop "<|eot_id|>"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off
if "%1"=="" (
echo DISCORD_BOT_TOKEN=[TOKEN] run.bat name_of_bot
echo This is creating the ollama modelfile and running the bot.
exit /b 1
)

set BASEDIR=%~dp0
ollama create %1 -f %BASEDIR%\modelfiles\%1.modelfile
cargo run --release %BASEDIR%\personas\%1.json
3 changes: 2 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ fi

BASEDIR=$(dirname $0)
ollama create ${1} -f ${BASEDIR}/modelfiles/${1}.modelfile
cargo run --release ${BASEDIR}/gods/${1}.json
cargo run --release ${BASEDIR}/personas/${1}.json

12 changes: 6 additions & 6 deletions src/commands/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use serenity::builder::CreateCommand;
use serenity::model::application::ResolvedOption;
use serenity::prelude::RwLock;

use crate::god::God;
use crate::persona::Persona;

pub async fn run(ctx: &Context, command: &CommandInteraction, god: Arc<RwLock<God>>) {
pub async fn run(ctx: &Context, command: &CommandInteraction, persona: Arc<RwLock<Persona>>) {
let author_name = if let Some(global_name) = &command.user.global_name {
global_name.clone()
} else {
Expand All @@ -22,19 +22,19 @@ pub async fn run(ctx: &Context, command: &CommandInteraction, god: Arc<RwLock<Go
}) = command.data.options().first()
{
let _ = command.defer(&ctx.http).await;
let prompt = { god.read().await.get_prompt(&author_name, prompt_slice) };
let response = { god.read().await.brain.request(&prompt).await };
let prompt = { persona.read().await.get_prompt(&author_name, prompt_slice) };
let response = { persona.read().await.brain.request(&prompt).await };
if let Some(response) = response {
let content = format!(
"\nFrom **{author_name}:**```{prompt_slice}```**{}:**```{}```",
god.read().await.get_botname(),
persona.read().await.get_botname(),
response.content,
);
let builder = EditInteractionResponse::new().content(content);
if let Err(why) = command.edit_response(&ctx.http, builder).await {
println!("Cannot respond to slash command: {why}");
} else {
god.write().await.set_prompt_response(
persona.write().await.set_prompt_response(
&author_name,
prompt_slice,
&response.content,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use serenity::all::{CommandInteraction, Context, CreateInteractionResponseMessag
use serenity::builder::CreateCommand;
use serenity::prelude::RwLock;

use crate::god::God;
use crate::persona::Persona;

pub async fn run(ctx: &Context, command: &CommandInteraction, god: Arc<RwLock<God>>) {
god.write().await.clear();
pub async fn run(ctx: &Context, command: &CommandInteraction, persona: Arc<RwLock<Persona>>) {
persona.write().await.clear();
if let Err(why) = command
.create_response(
&ctx.http,
Expand Down
Loading

0 comments on commit 159dd81

Please sign in to comment.