pub struct InjectionEngine<P: AiProvider> { /* private fields */ }Expand description
The main engine for AI code injection.
§Example
ⓘ
use aether_core::{InjectionEngine, Template};
use aether_ai::OpenAiProvider;
let provider = OpenAiProvider::from_env()?;
let engine = InjectionEngine::new(provider);
let template = Template::new("<div>{{AI:content}}</div>")
.with_slot("content", "Generate a welcome message");
let result = engine.render(&template).await?;Implementations§
Source§impl<P: AiProvider + 'static> InjectionEngine<P>
impl<P: AiProvider + 'static> InjectionEngine<P>
Sourcepub fn with_cache(self, cache: impl Cache + 'static) -> Self
pub fn with_cache(self, cache: impl Cache + 'static) -> Self
Set the cache for performance optimization.
Sourcepub fn with_validator(self, validator: impl Validator + 'static) -> Self
pub fn with_validator(self, validator: impl Validator + 'static) -> Self
Set the validator for self-healing.
Sourcepub fn with_context(self, context: InjectionContext) -> Self
pub fn with_context(self, context: InjectionContext) -> Self
Set the global context.
Sourcepub fn max_retries(self, retries: u32) -> Self
pub fn max_retries(self, retries: u32) -> Self
Set maximum retries for failed generations.
Sourcepub async fn render(&self, template: &Template) -> Result<String>
pub async fn render(&self, template: &Template) -> Result<String>
Render a template with AI-generated code.
This method will generate code for all slots in the template and return the final rendered content.
Sourcepub async fn render_with_context(
&self,
template: &Template,
context: InjectionContext,
) -> Result<String>
pub async fn render_with_context( &self, template: &Template, context: InjectionContext, ) -> Result<String>
Render a template with additional context.
Sourcepub async fn generate_slot(
&self,
template: &Template,
slot_name: &str,
) -> Result<String>
pub async fn generate_slot( &self, template: &Template, slot_name: &str, ) -> Result<String>
Generate code for a single slot.
Sourcepub fn generate_slot_stream(
&self,
template: &Template,
slot_name: &str,
) -> Result<BoxStream<'static, Result<StreamResponse>>>
pub fn generate_slot_stream( &self, template: &Template, slot_name: &str, ) -> Result<BoxStream<'static, Result<StreamResponse>>>
Generate code for a single slot as a stream.
Auto Trait Implementations§
impl<P> Freeze for InjectionEngine<P>
impl<P> !RefUnwindSafe for InjectionEngine<P>
impl<P> Send for InjectionEngine<P>
impl<P> Sync for InjectionEngine<P>
impl<P> Unpin for InjectionEngine<P>
impl<P> !UnwindSafe for InjectionEngine<P>
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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