Implementing a Custom Client
This chapter is a placeholder. A detailed guide on implementing custom BotClient
implementations is coming soon.
All built-in clients implement the BotClient trait. You can implement it yourself to
support services that don't follow the OpenAI-compatible API, or to add custom logic
around AI interactions.
The BotClient trait
pub trait BotClient: Send {
fn send(
&mut self,
bot_id: &BotId,
messages: &[Message],
tools: &[Tool],
) -> BoxPlatformSendStream<'static, ClientResult<MessageContent>>;
fn bots(&mut self) -> BoxPlatformSendFuture<'static, ClientResult<Vec<Bot>>>;
fn clone_box(&self) -> Box<dyn BotClient>;
}
send()returns a stream ofClientResult<MessageContent>. Each yielded item should be a cumulative snapshot of the full response content built so far.bots()returns a future resolving to the list of available models.clone_box()enablesBox<dyn BotClient>to be cloned.
Any custom client you implement will work with RouterClient, ChatController, and
every other abstraction in aitk that accepts a BotClient.