Rust

adapter

Module

The 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;
Rust
pub struct Base

The state every adapter keeps: token counts, the request timeout, the HTTP client, and the fragment of a streamed line still incomplete.

Also implements Debug, Default.
use utopia_agents::Embedding;
Rust
pub struct Embedding

An embedding of one text.

use utopia_agents::Embeddings;
Rust
pub struct Embeddings

Embeddings of several texts, in order.

use utopia_agents::Usage;
Rust
pub struct Usage

Tokens counted so far, by kind.

use utopia_agents::Adapter;
Rust
pub trait Adapter: Send

An 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;
Rust
pub trait Transport: Send + Sync

The 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.

Implemented byA
Rust
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>

A boxed future, as the object-safe Adapter and Transport return.

Rust
pub type Listener<'a> = &'a mut (dyn FnMut(&str) + Send)

Receives each token of a streamed answer as it arrives.

Rust
pub const STREAM_BUFFER_MAX_BYTES: usize = 1_048_576

Upper bound for retained incomplete SSE fragments.