Files
Synapse/crates/synapse-ai/src/provider.rs
T
dasemuandClaude Sonnet 5.5 6697924bf5 feat(ai): provider-agnostic AI crate (Anthropic, OpenAI, Gemini, compatible)
Streaming chat, embeddings (Embedder impl), key stores, retries/cancellation,
and graph features: ask_graph, summarize_journal, suggest_links_and_tags,
extract_tasks, consolidate_week.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-21 03:41:21 +02:00

27 lines
943 B
Rust

use async_trait::async_trait;
use tokio_util::sync::CancellationToken;
use crate::error::Result;
use crate::types::{ChatRequest, ChatResponse, EmbedResponse, TokenSink};
#[async_trait]
pub trait ChatProvider: Send + Sync {
/// Runs one chat completion. Text deltas are pushed to `sink` as they arrive; the full text
/// is also returned. Cancelling `cancel` aborts the request with `Error::Cancelled`.
async fn chat(
&self,
req: &ChatRequest,
sink: Option<TokenSink<'_>>,
cancel: &CancellationToken,
) -> Result<ChatResponse>;
}
#[async_trait]
pub trait EmbeddingProvider: Send + Sync {
/// `provider/model`, e.g. `openai/text-embedding-3-small`.
fn model_id(&self) -> String;
/// Known vector size, if it does not need a probe request.
fn known_dims(&self) -> Option<usize>;
async fn embed(&self, texts: &[String], cancel: &CancellationToken) -> Result<EmbedResponse>;
}