use std::pin::Pin;
use crate::llm_client::{
ClientError, LlmClient, Request, event::Event, providers::openai::OpenAIClient,
scheme::openai::OpenAIScheme,
};
use async_trait::async_trait;
use futures::Stream;
pub struct OllamaClient {
inner: OpenAIClient,
}
impl OllamaClient {
pub fn new(model: impl Into<String>) -> Self {
let base_url = "http://localhost:11434";
let scheme = OpenAIScheme::new().with_legacy_max_tokens(true);
let client = OpenAIClient::new("ollama", model)
.with_base_url(base_url)
.with_scheme(scheme);
Self { inner: client }
}
pub fn with_base_url(mut self, url: impl Into<String>) -> Self {
self.inner = self.inner.with_base_url(url);
self
}
pub fn with_http_client(mut self, client: reqwest::Client) -> Self {
self.inner = self.inner.with_http_client(client);
self
}
}
#[async_trait]
impl LlmClient for OllamaClient {
async fn stream(
&self,
request: Request,
) -> Result<Pin<Box<dyn Stream<Item = Result<Event, ClientError>> + Send>>, ClientError> {
self.inner.stream(request).await
}
}