Trait LanguageModel

Source
pub trait LanguageModel:
    Sized
    + Send
    + Sync
    + 'static {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn respond(&self, request: Request) -> impl TextStream<Error = Self::Error>;
    fn complete(&self, prefix: &str) -> impl TextStream<Error = Self::Error>;
    fn profile(&self) -> Profile;

    // Provided methods
    fn generate<T: JsonSchema + DeserializeOwned>(
        &self,
        request: Request,
    ) -> impl Future<Output = Result<T>> + Send { ... }
    fn summarize(&self, text: &str) -> impl TextStream<Error = Self::Error> { ... }
    fn categorize<T: JsonSchema + DeserializeOwned>(
        &self,
        text: &str,
    ) -> impl Future<Output = Result<T>> + Send { ... }
}
Expand description

Language models for text generation and conversation.

See the module documentation for examples and usage patterns.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

The error type returned by this language model.

Required Methods§

Source

fn respond(&self, request: Request) -> impl TextStream<Error = Self::Error>

Generates streaming response to conversation.

Source

fn complete(&self, prefix: &str) -> impl TextStream<Error = Self::Error>

Completes given text prefix.

Source

fn profile(&self) -> Profile

Returns model profile and capabilities.

See Profile for details on model metadata.

Provided Methods§

Source

fn generate<T: JsonSchema + DeserializeOwned>( &self, request: Request, ) -> impl Future<Output = Result<T>> + Send

Generates structured output conforming to JSON schema.

Source

fn summarize(&self, text: &str) -> impl TextStream<Error = Self::Error>

Summarizes text.

Source

fn categorize<T: JsonSchema + DeserializeOwned>( &self, text: &str, ) -> impl Future<Output = Result<T>> + Send

Categorizes text.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: LanguageModel> LanguageModel for Box<T>

Source§

type Error = <T as LanguageModel>::Error

Source§

fn respond(&self, request: Request) -> impl TextStream<Error = T::Error>

Source§

fn generate<U: JsonSchema + DeserializeOwned>( &self, request: Request, ) -> impl Future<Output = Result<U>> + Send

Source§

fn complete(&self, prefix: &str) -> impl TextStream<Error = T::Error>

Source§

fn summarize(&self, text: &str) -> impl TextStream<Error = T::Error>

Source§

fn categorize<U: JsonSchema + DeserializeOwned>( &self, text: &str, ) -> impl Future<Output = Result<U>> + Send

Source§

fn profile(&self) -> Profile

Source§

impl<T: LanguageModel> LanguageModel for Arc<T>

Source§

type Error = <T as LanguageModel>::Error

Source§

fn respond(&self, request: Request) -> impl TextStream<Error = T::Error>

Source§

fn generate<U: JsonSchema + DeserializeOwned>( &self, request: Request, ) -> impl Future<Output = Result<U>> + Send

Source§

fn complete(&self, prefix: &str) -> impl TextStream<Error = T::Error>

Source§

fn summarize(&self, text: &str) -> impl TextStream<Error = T::Error>

Source§

fn categorize<U: JsonSchema + DeserializeOwned>( &self, text: &str, ) -> impl Future<Output = Result<U>> + Send

Source§

fn profile(&self) -> Profile

Implementors§