adapter
ModuleThe provider interface every adapter implements, the state they share (token counts, timeout, HTTP client, stream buffer) and the HTTP client interface requests go through.
Contents
use utopia_agents::Base;pub struct BaseThe state every adapter keeps: token counts, the request timeout, the HTTP client, and the fragment of a streamed line still incomplete.
Debug, Default.use utopia_agents::Embedding;pub struct EmbeddingAn embedding of one text.
use utopia_agents::Embeddings;pub struct EmbeddingsEmbeddings of several texts, in order.
use utopia_agents::Usage;pub struct UsageTokens counted so far, by kind.
use utopia_agents::Adapter;pub trait Adapter: SendAn AI provider: sends a conversation and returns the answer (streamed token by token to a listener where the provider streams), or embeds texts. Implement it to add a provider.
Every adapter keeps a Base (token counts, timeout, HTTP client),
which the provided methods read.
use utopia_agents::Transport;pub trait Transport: Send + SyncThe HTTP client an adapter sends its requests through: any
utopia_client::Adapter (a Client, a utopia_client::Retry
decorator, ...), or a client of your own, such as one that records
requests in tests.
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>pub type Listener<'a> = &'a mut (dyn FnMut(&str) + Send)Receives each token of a streamed answer as it arrives.
pub const STREAM_BUFFER_MAX_BYTES: usize = 1_048_576Upper bound for retained incomplete SSE fragments.