pub struct AsyncSession<'s> { /* private fields */ }Available on crate feature
async only.Expand description
Async wrapper around crate::LanguageModelSession.
Borrows the session for its lifetime; the session itself must outlive all in-flight futures.
§Examples
use foundation_models::{LanguageModelSession, SystemLanguageModel};
use foundation_models::async_api::AsyncSession;
if !SystemLanguageModel::is_available() { return Ok(()); }
pollster::block_on(async {
let session = LanguageModelSession::new();
let reply = AsyncSession::new(&session).respond("Hi!")?.await?;
println!("{}", reply.content);
Ok::<(), Box<dyn std::error::Error>>(())
})Implementations§
Source§impl<'s> AsyncSession<'s>
impl<'s> AsyncSession<'s>
Sourcepub fn new(session: &'s LanguageModelSession) -> Self
pub fn new(session: &'s LanguageModelSession) -> Self
Wrap a crate::LanguageModelSession for async use.
Sourcepub fn respond_with_options(
&self,
prompt: impl ToPrompt,
options: GenerationOptions,
) -> Result<RespondFuture, FMError>
pub fn respond_with_options( &self, prompt: impl ToPrompt, options: GenerationOptions, ) -> Result<RespondFuture, FMError>
Async version of LanguageModelSession.respond(to:) with GenerationOptions.
§Errors
Returns an FMError if the model is unavailable or generation fails.
Sourcepub fn respond_generating(
&self,
prompt: impl ToPrompt,
schema: &GenerationSchema,
include_schema_in_prompt: bool,
options: GenerationOptions,
) -> Result<RespondGeneratingFuture, FMError>
pub fn respond_generating( &self, prompt: impl ToPrompt, schema: &GenerationSchema, include_schema_in_prompt: bool, options: GenerationOptions, ) -> Result<RespondGeneratingFuture, FMError>
Trait Implementations§
Auto Trait Implementations§
impl<'s> Freeze for AsyncSession<'s>
impl<'s> !RefUnwindSafe for AsyncSession<'s>
impl<'s> Send for AsyncSession<'s>
impl<'s> Sync for AsyncSession<'s>
impl<'s> Unpin for AsyncSession<'s>
impl<'s> UnsafeUnpin for AsyncSession<'s>
impl<'s> !UnwindSafe for AsyncSession<'s>
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