This commit is contained in:
2025-05-19 21:07:36 +09:00
commit fa7d52e7e8
14 changed files with 335 additions and 0 deletions

8
ai-messenger/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "ai-messenger"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -0,0 +1,26 @@
{
"personality": {
"kind": "positive",
"strength": 0.8
},
"relationship": {
"trust": 0.7,
"intimacy": 0.6,
"curiosity": 0.5,
"threshold": 1.5
},
"environment": {
"luck_today": 0.9,
"luck_history": [0.9, 0.9, 0.9],
"level": 1
},
"messaging": {
"enabled": true,
"schedule_time": "08:00",
"decay_rate": 0.1,
"templates": [
"おはよう!今日もがんばろう!",
"ねえ、話したいことがあるの。"
]
}
}

11
ai-messenger/src/logic.rs Normal file
View File

@ -0,0 +1,11 @@
use crate::model::AiSystem;
pub fn should_send(ai: &AiSystem) -> bool {
let r = &ai.relationship;
let env = &ai.environment;
let score = r.trust + r.intimacy + r.curiosity;
let relationship_ok = score >= r.threshold;
let luck_ok = env.luck_today > 0.5;
ai.messaging.enabled && relationship_ok && luck_ok
}

38
ai-messenger/src/main.rs Normal file
View File

@ -0,0 +1,38 @@
mod model;
use model::{AiSystem, Environment, Messaging, Personality, Relationship};
use serde_json;
fn main() {
// テスト用のAIシステム初期化
let ai = AiSystem {
personality: Personality {
kind: "positive".to_string(),
strength: 0.8,
},
relationship: Relationship {
trust: 0.7,
intimacy: 0.6,
curiosity: 0.5,
threshold: 1.5,
},
environment: Environment {
luck_today: 0.9,
luck_history: vec![0.9, 0.9, 0.9],
level: 1,
},
messaging: Messaging {
enabled: true,
schedule_time: Some("08:00".to_string()),
decay_rate: 0.1,
templates: vec![
"ねえねえ、今日もがんばろうね!".to_string(),
"そろそろ話したくなっちゃった...".to_string(),
],
},
};
// JSONにシリアライズして表示
let json = serde_json::to_string_pretty(&ai).unwrap();
println!("{}", json);
}

38
ai-messenger/src/model.rs Normal file
View File

@ -0,0 +1,38 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct AiSystem {
pub personality: Personality,
pub relationship: Relationship,
pub environment: Environment,
pub messaging: Messaging,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Personality {
pub kind: String, // e.g., "positive", "negative", "neutral"
pub strength: f32, // 0.0 - 1.0
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Relationship {
pub trust: f32, // 0.0 - 1.0
pub intimacy: f32, // 0.0 - 1.0
pub curiosity: f32, // 0.0 - 1.0
pub threshold: f32, // if sum > threshold, allow messaging
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Environment {
pub luck_today: f32, // 0.1 - 1.0
pub luck_history: Vec<f32>, // last 3 values
pub level: i32, // current mental strength level
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Messaging {
pub enabled: bool,
pub schedule_time: Option<String>, // e.g., "08:00"
pub decay_rate: f32, // how quickly emotion fades (0.0 - 1.0)
pub templates: Vec<String>, // message template variations
}