mockforge_foundation/intelligent_behavior/
mod.rs1pub mod config;
10pub mod mockai;
11pub mod rule_types;
12pub mod session;
13pub mod session_state;
14pub mod types;
15
16pub use config::{
17 BehaviorModelConfig, IntelligentBehaviorConfig, PerformanceConfig, PersonasConfig,
18 VectorStoreConfig,
19};
20pub use mockai::MockAiBehavior;
21pub use session::{SessionManager, SessionTracking, SessionTrackingMethod};
22pub use session_state::{InteractionRecord, SessionState};
23pub use types::BehaviorRules;
24
25use chrono::{DateTime, Utc};
26use serde::{Deserialize, Serialize};
27use serde_json::Value;
28use std::collections::HashMap;
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
33pub struct Persona {
34 pub name: String,
36
37 #[serde(default)]
39 pub traits: HashMap<String, String>,
40}
41
42impl Persona {
43 pub fn get_numeric_trait(&self, key: &str) -> Option<u64> {
46 self.traits.get(key).and_then(|value| {
47 if let Some((min_str, max_str)) = value.split_once('-') {
48 if let (Ok(min), Ok(max)) =
49 (min_str.trim().parse::<u64>(), max_str.trim().parse::<u64>())
50 {
51 return Some((min + max) / 2);
52 }
53 }
54 value.parse::<u64>().ok()
55 })
56 }
57
58 pub fn get_trait(&self, key: &str) -> Option<&String> {
60 self.traits.get(key)
61 }
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct LlmGenerationRequest {
67 pub system_prompt: String,
69 pub user_prompt: String,
71 #[serde(default = "default_temperature")]
73 pub temperature: f64,
74 #[serde(default = "default_max_tokens")]
76 pub max_tokens: usize,
77 pub schema: Option<Value>,
79}
80
81impl LlmGenerationRequest {
82 pub fn new(system_prompt: impl Into<String>, user_prompt: impl Into<String>) -> Self {
84 Self {
85 system_prompt: system_prompt.into(),
86 user_prompt: user_prompt.into(),
87 temperature: default_temperature(),
88 max_tokens: default_max_tokens(),
89 schema: None,
90 }
91 }
92
93 #[must_use]
95 pub fn with_temperature(mut self, temperature: f64) -> Self {
96 self.temperature = temperature;
97 self
98 }
99
100 #[must_use]
102 pub fn with_max_tokens(mut self, max_tokens: usize) -> Self {
103 self.max_tokens = max_tokens;
104 self
105 }
106
107 #[must_use]
109 pub fn with_schema(mut self, schema: Value) -> Self {
110 self.schema = Some(schema);
111 self
112 }
113}
114
115fn default_temperature() -> f64 {
116 0.7
117}
118
119fn default_max_tokens() -> usize {
120 1024
121}
122
123#[derive(Debug, Clone)]
125pub struct Request {
126 pub method: String,
128 pub path: String,
130 pub body: Option<Value>,
132 pub query_params: HashMap<String, String>,
134 pub headers: HashMap<String, String>,
136}
137
138#[derive(Debug, Clone)]
140pub struct Response {
141 pub status_code: u16,
143 pub body: Value,
145 pub headers: HashMap<String, String>,
147}
148
149#[derive(Debug, Clone)]
151pub struct HttpExchange {
152 pub method: String,
154 pub path: String,
156 pub query_params: Option<String>,
158 pub headers: String,
160 pub body: Option<String>,
162 pub body_encoding: String,
164 pub status_code: Option<i32>,
166 pub response_headers: Option<String>,
168 pub response_body: Option<String>,
170 pub response_body_encoding: Option<String>,
172 pub timestamp: DateTime<Utc>,
174}