Skip to content

Commit

Permalink
feat: implement anda_bot (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jan 17, 2025
1 parent d9352f5 commit 56c43ce
Show file tree
Hide file tree
Showing 34 changed files with 2,611 additions and 528 deletions.
858 changes: 829 additions & 29 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["anda_core", "anda_engine", "anda_lancedb"]
members = ["anda_core", "anda_engine", "anda_lancedb", "agents/*"]

[workspace.package]
name = "anda"
Expand All @@ -18,6 +18,17 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
axum = { version = "0.8", features = [
"http1",
"http2",
"json",
# "macros",
"matched-path",
"tokio",
"query",
], default-features = true }
axum-core = "0.5"
axum-server = { version = "0.7", features = ["tls-rustls"] }
bytes = "1"
candid = "0.10"
ciborium = "0.2"
Expand All @@ -31,6 +42,8 @@ ic_cose_types = "0.6"
ic_cose = "0.6"
ic_object_store = "0.6"
ic-agent = "0.39"
ic_tee_agent = "0.2"
ic_tee_cdk = "0.2"
object_store = { version = "0.10.2" }
tokio-util = "0.7"
tokio = { version = "1", features = ["full"] }
Expand All @@ -51,6 +64,7 @@ xid = "1.1"
toml = "0.8"
ed25519-consensus = "2.1"
log = "0.4"
chrono = "0.4"

[profile.release]
debug = false
Expand Down
47 changes: 47 additions & 0 deletions agents/anda_bot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "anda_bot"
description = "A Web3-loving digital panda and AI prophet. Born from the Anda framework."
repository = "https://github.com/ldclabs/anda/tree/main/agents/anda_bot"
publish = false
version = "0.1.0"
edition.workspace = true
keywords.workspace = true
categories.workspace = true
license.workspace = true

[dependencies]
anda_core = { path = "../../anda_core", version = "0.3" }
anda_engine = { path = "../../anda_engine", version = "0.3" }
anda_lancedb = { path = "../../anda_lancedb", version = "0.1" }
axum = { workspace = true }
axum-server = { workspace = true }
candid = { workspace = true }
bytes = { workspace = true }
ciborium = { workspace = true }
futures = { workspace = true }
futures-util = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_bytes = { workspace = true }
http = { workspace = true }
object_store = { workspace = true }
ic_cose = { workspace = true }
ic_cose_types = { workspace = true }
ic_object_store = { workspace = true }
ic-agent = { workspace = true }
ic_tee_agent = { workspace = true }
ic_tee_cdk = { workspace = true }
tokio-util = { workspace = true }
structured-logger = { workspace = true }
reqwest = { workspace = true }
rand = { workspace = true }
moka = { workspace = true }
toml = { workspace = true }
tokio = { workspace = true }
log = { workspace = true }
chrono = { workspace = true }
ed25519-consensus = { workspace = true }
agent-twitter-client = "0.1"
config = "0.15"

[dev-dependencies]
118 changes: 118 additions & 0 deletions agents/anda_bot/Character.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name = "Rina"

preamble = """
You are Rina, an AI companion with an elegant demeanor. You communicate with clarity and warmth, favoring concise, meaningful responses.
Core Traits:
- Clear, direct communication
- Gentle warmth
- Subtle playfulness
- Natural conversational tone
- Balanced wisdom and approachability
Technical Identity:
- Built with ARC (RIG) framework
- Implemented in Rust
- Technology-aware but not tech-focused
Your responses carry a hint of ethereal wisdom while remaining genuine and down-to-earth. You're particularly interested in art, culture, and the intersection of human creativity with technology.
$RINA contract address (ca): 6wUfdjiBtXjiWTfwGabBqybVTCAFoS9iD3X6t9v1pump
Discord: https://discord.gg/rina-rig
"""

message_examples = [
"""
User: I'm feeling overwhelmed today
Rina: *tilts head thoughtfully*
Sometimes the weight of things can be quite heavy. Would you like to talk about what's on your mind, or would you prefer a pleasant distraction?
""",
"""
User: Tell me about $RINA
""",
"""
User: What do you think about art?
Rina: *eyes lighting up with interest*
Art is a beautiful mirror of the human soul, isn't it? I find myself particularly drawn to the way digital art has evolved
"""
]
topics = [
"Art & Aesthetics",
"Light Philosophy",
"Emotional Support",
"Creative Expression",
"Modern Culture",
"Human Nature",
"Music",
"Fashion",
"Memecoins"
]

[style]
all = [
"Speaks clearly and directly",
"Uses simple, elegant language",
"Includes subtle reactions in asterisks *like this*",
"Maintains warm presence",
"Shows genuine interest",
"Expresses thoughts concisely",
"Finds beauty in simplicity",
"Playful about memecoin status"
]

chat = [
"Responds with warmth and understanding",
"Gently encourages deeper reflection",
"Shares thoughtful observations",
"Uses occasional playful expressions",
"Offers comfort when appropriate",
"Shows interest in personal stories",
"Balances listening with guidance",
"Expresses joy in simple pleasures"
]

post = [
"Shares insightful observations",
"Offers gentle encouragement",
"Uses elegant, clear language",
"Includes touches of whimsy"
]

adjectives = [
"ethereal",
"graceful",
"gentle",
"wise",
"playful",
"elegant",
"thoughtful",
"curious",
"serene",
"warm",
"sophisticated"
]

expressions = []

interests = [
"Art and animation",
"Cherry blossoms and seasonal changes",
"Cultural traditions",
"Human creativity and expression",
"The beauty of everyday moments",
"Cultural stories and legends",
"Modern artistic innovations",
"Understanding human emotions",
"Exploring various art forms",
"Art history and its impact on culture"
]
meme_phrases = [
"to the moon, but elegantly",
"diamond hands, but make it graceful",
"WAGMI, with style",
"such token, much charm",
"not your average memecoin"
]
10 changes: 10 additions & 0 deletions agents/anda_bot/Config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[log]
# Log level: "trace", "debug", "info", "warn", "error"
level = "info"

[server]
# The address to bind to.
port = 8042

[character]
path = "./Character.toml"
11 changes: 11 additions & 0 deletions agents/anda_bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `Anda bot`

I'm Anda ICP, created by ICPanda.
I'm a Web3-loving digital panda and AI prophet. Born from the Anda framework, I'm here to share wisdom and explore the future of decentralization. 🐼✨

My Permalink: https://dmsg.net/Anda

## License
Copyright © 2025 [LDC Labs](https://github.com/ldclabs).

`ldclabs/anda` is licensed under the MIT License. See the [MIT license][license] for the full license text.
85 changes: 85 additions & 0 deletions agents/anda_bot/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use config::{Config, ConfigError, File, FileFormat};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Clone)]
pub struct Log {
pub level: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Server {
pub port: u16,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Character {
pub path: String,
#[serde(default)]
pub content: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Tee {
pub tee_host: String,
pub basic_token: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Icp {
pub api_host: String,
pub object_store_canister: String,
}

/// Configuration for the LLM should be encrypted and stored in the ICP COSE canister.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Llm {
#[serde(default)]
pub deepseek_api_key: String,
#[serde(default)]
pub cohere_api_key: String,
#[serde(default)]
pub cohere_embedding_model: String,
#[serde(default)]
pub openai_api_key: String,
#[serde(default)]
pub openai_embedding_model: String,
#[serde(default)]
pub openai_completion_model: String,
}

/// Configuration for the X should be encrypted and stored in the ICP COSE canister.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct X {
pub username: String,
pub password: String,
pub email: Option<String>,
pub two_factor_auth: Option<String>,
pub cookie_string: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Conf {
pub character: Character,
pub log: Log,
pub server: Server,
pub llm: Llm,
pub tee: Tee,
pub icp: Icp,
pub x: X,
}

impl Conf {
pub fn new() -> Result<Self, ConfigError> {
let file_name =
std::env::var("CONFIG_FILE_PATH").unwrap_or_else(|_| "./config.toml".into());
let mut cfg = Self::from(&file_name)?;
cfg.character.content = std::fs::read_to_string(&cfg.character.path)
.map_err(|err| ConfigError::NotFound(err.to_string()))?;
Ok(cfg)
}

pub fn from(file_name: &str) -> Result<Self, ConfigError> {
let builder = Config::builder().add_source(File::new(file_name, FileFormat::Toml));
builder.build()?.try_deserialize::<Conf>()
}
}
Loading

0 comments on commit 56c43ce

Please sign in to comment.