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<MockAI, Error>
pub async fn from_openapi( spec: &OpenApiSpec, config: IntelligentBehaviorConfig, ) -> Result<MockAI, Error>
Create MockAI from OpenAPI specification
Automatically generates behavioral rules from the OpenAPI spec.
Sourcepub async fn from_examples(
examples: Vec<ExamplePair>,
config: IntelligentBehaviorConfig,
) -> Result<MockAI, Error>
pub async fn from_examples( examples: Vec<ExamplePair>, config: IntelligentBehaviorConfig, ) -> Result<MockAI, Error>
Create MockAI from example pairs
Learns behavioral patterns from provided examples.
Sourcepub fn new(config: IntelligentBehaviorConfig) -> MockAI
pub fn new(config: IntelligentBehaviorConfig) -> MockAI
Create a new MockAI instance (for testing or manual creation)
Sourcepub async fn process_request(
&self,
request: &Request,
) -> Result<Response, Error>
pub async fn process_request( &self, request: &Request, ) -> Result<Response, Error>
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, Error>
pub async fn generate_response( &self, request: &Request, session_context: &StatefulAiContext, ) -> Result<Response, Error>
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<(), Error>
pub async fn learn_from_example( &mut self, example: ExamplePair, ) -> Result<(), Error>
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<MockAI>>,
config: IntelligentBehaviorConfig,
) -> Result<(), Error>
pub async fn update_config_async( this: &Arc<RwLock<MockAI>>, config: IntelligentBehaviorConfig, ) -> Result<(), Error>
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>, Error>
pub fn extract_examples_from_openapi( spec: &OpenApiSpec, ) -> Result<Vec<ExamplePair>, Error>
Extract examples from OpenAPI spec
Trait Implementations§
Source§impl MockAiBehavior for MockAI
impl MockAiBehavior for MockAI
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Source§fn process_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 Request,
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MockAI: 'async_trait,
fn process_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 Request,
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MockAI: 'async_trait,
Auto Trait Implementations§
impl Freeze for MockAI
impl !RefUnwindSafe for MockAI
impl Send for MockAI
impl Sync for MockAI
impl Unpin for MockAI
impl UnsafeUnpin for MockAI
impl !UnwindSafe for MockAI
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more