pub trait LanguageModel:
Send
+ Sync
+ 'static {
// Required methods
fn provider(&self) -> &ProviderId;
fn model_id(&self) -> &ModelId;
fn supported_urls(&self) -> impl Future<Output = SupportedUrls> + Send;
fn do_generate(
&self,
options: CallOptions,
) -> impl Future<Output = Result<GenerateResult, ProviderError>> + Send;
fn do_stream(
&self,
options: CallOptions,
) -> impl Future<Output = Result<StreamResult, ProviderError>> + Send;
}Expand description
A text generation model.
Implement this trait in a provider crate for every language model API.
Implementations must be cheap to clone behind an Arc and safe to call
concurrently. See the adapter contract in the provider specification:
unsupported options produce warnings, tool input is passed through as raw
JSON text, streams start with StreamStart and end with Finish or
Error, and the cancellation token aborts the HTTP request.
Required Methods§
Sourcefn provider(&self) -> &ProviderId
fn provider(&self) -> &ProviderId
Provider identifier, for example openai.responses.
Sourcefn supported_urls(&self) -> impl Future<Output = SupportedUrls> + Send
fn supported_urls(&self) -> impl Future<Output = SupportedUrls> + Send
URL patterns (by media type) the provider can fetch itself.
Files whose URL does not match are downloaded by the core and inlined.
Sourcefn do_generate(
&self,
options: CallOptions,
) -> impl Future<Output = Result<GenerateResult, ProviderError>> + Send
fn do_generate( &self, options: CallOptions, ) -> impl Future<Output = Result<GenerateResult, ProviderError>> + Send
Generates a complete response.
Sourcefn do_stream(
&self,
options: CallOptions,
) -> impl Future<Output = Result<StreamResult, ProviderError>> + Send
fn do_stream( &self, options: CallOptions, ) -> impl Future<Output = Result<StreamResult, ProviderError>> + Send
Generates a streamed response.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".