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 #[serde(default)]
83 pub seed: Option<i64>,
84}
85
86impl LlmGenerationRequest {
87 pub fn new(system_prompt: impl Into<String>, user_prompt: impl Into<String>) -> Self {
89 Self {
90 system_prompt: system_prompt.into(),
91 user_prompt: user_prompt.into(),
92 temperature: default_temperature(),
93 max_tokens: default_max_tokens(),
94 schema: None,
95 seed: None,
96 }
97 }
98
99 #[must_use]
101 pub fn with_temperature(mut self, temperature: f64) -> Self {
102 self.temperature = temperature;
103 self
104 }
105
106 #[must_use]
108 pub fn with_max_tokens(mut self, max_tokens: usize) -> Self {
109 self.max_tokens = max_tokens;
110 self
111 }
112
113 #[must_use]
115 pub fn with_schema(mut self, schema: Value) -> Self {
116 self.schema = Some(schema);
117 self
118 }
119}
120
121fn default_temperature() -> f64 {
122 0.7
123}
124
125fn default_max_tokens() -> usize {
126 1024
127}
128
129#[derive(Debug, Clone)]
131pub struct Request {
132 pub method: String,
134 pub path: String,
136 pub body: Option<Value>,
138 pub query_params: HashMap<String, String>,
140 pub headers: HashMap<String, String>,
142}
143
144#[derive(Debug, Clone)]
146pub struct Response {
147 pub status_code: u16,
149 pub body: Value,
151 pub headers: HashMap<String, String>,
153}
154
155#[derive(Debug, Clone)]
157pub struct HttpExchange {
158 pub method: String,
160 pub path: String,
162 pub query_params: Option<String>,
164 pub headers: String,
166 pub body: Option<String>,
168 pub body_encoding: String,
170 pub status_code: Option<i32>,
172 pub response_headers: Option<String>,
174 pub response_body: Option<String>,
176 pub response_body_encoding: Option<String>,
178 pub timestamp: DateTime<Utc>,
180}