pub struct MockAI { /* private fields */ }Expand description
MockAI unified interface
Implementations§
Source§impl MockAI
impl MockAI
Sourcepub async fn from_openapi(
spec: &OpenApiSpec,
config: IntelligentBehaviorConfig,
) -> Result<Self>
pub async fn from_openapi( spec: &OpenApiSpec, config: IntelligentBehaviorConfig, ) -> Result<Self>
Create MockAI from OpenAPI specification
Automatically generates behavioral rules from the OpenAPI spec.
Sourcepub async fn from_examples(
examples: Vec<ExamplePair>,
config: IntelligentBehaviorConfig,
) -> Result<Self>
pub async fn from_examples( examples: Vec<ExamplePair>, config: IntelligentBehaviorConfig, ) -> Result<Self>
Create MockAI from example pairs
Learns behavioral patterns from provided examples.
Sourcepub fn new(config: IntelligentBehaviorConfig) -> Self
pub fn new(config: IntelligentBehaviorConfig) -> Self
Create a new MockAI instance (for testing or manual creation)
Sourcepub async fn process_request(&self, request: &Request) -> Result<Response>
pub async fn process_request(&self, request: &Request) -> Result<Response>
Process a request and generate a response
Convenience method that gets or creates a session context and generates a response. This is the main entry point for processing HTTP requests. Session ID is extracted from headers (X-Session-ID or Cookie) or generated if not present.
Sourcepub async fn generate_response(
&self,
request: &Request,
session_context: &StatefulAiContext,
) -> Result<Response>
pub async fn generate_response( &self, request: &Request, session_context: &StatefulAiContext, ) -> Result<Response>
Generate response for a request
Uses intelligent behavior to generate contextually appropriate responses based on request mutations, validation, and pagination needs.
Sourcepub async fn learn_from_example(&mut self, example: ExamplePair) -> Result<()>
pub async fn learn_from_example(&mut self, example: ExamplePair) -> Result<()>
Learn from an example pair
Updates behavioral rules based on a new example.
Sourcepub fn rules(&self) -> &BehaviorRules
pub fn rules(&self) -> &BehaviorRules
Get current behavior rules
Sourcepub fn update_rules(&mut self, rules: BehaviorRules)
pub fn update_rules(&mut self, rules: BehaviorRules)
Update behavior rules
Sourcepub fn update_config(&mut self, config: IntelligentBehaviorConfig)
pub fn update_config(&mut self, config: IntelligentBehaviorConfig)
Update configuration at runtime
This allows changing MockAI configuration without recreating the instance. Useful for hot-reloading reality level configurations.
Note: This updates the configuration but does not regenerate rules.
For rule updates, use update_rules() or learn_from_example().
Sourcepub async fn update_config_async(
this: &Arc<RwLock<Self>>,
config: IntelligentBehaviorConfig,
) -> Result<()>
pub async fn update_config_async( this: &Arc<RwLock<Self>>, config: IntelligentBehaviorConfig, ) -> Result<()>
Update configuration (async version for Arc
Convenience method for updating a MockAI instance wrapped in Arc
§Returns
Ok(()) on success, or an error if the update fails.
Sourcepub fn get_config(&self) -> &IntelligentBehaviorConfig
pub fn get_config(&self) -> &IntelligentBehaviorConfig
Get current configuration
Primarily for testing purposes to verify configuration updates.
Sourcepub fn extract_examples_from_openapi(
spec: &OpenApiSpec,
) -> Result<Vec<ExamplePair>>
pub fn extract_examples_from_openapi( spec: &OpenApiSpec, ) -> Result<Vec<ExamplePair>>
Extract examples from OpenAPI spec