llm-worker-rs/worker/src/core.rs

38 lines
1.4 KiB
Rust

// Core types and traits for the worker crate
// This module contains the primary abstractions used throughout the crate
use worker_types::{DynamicToolDefinition, LlmProvider, Message, StreamEvent};
use crate::types::WorkerError;
use futures_util::Stream;
/// LlmClient trait - common interface for all LLM clients
///
/// This trait defines the common interface that all LLM client implementations must provide.
/// It's defined here in the core module so it can be imported early in the module hierarchy,
/// before the specific client implementations.
#[async_trait::async_trait]
pub trait LlmClientTrait: Send + Sync {
/// Send a chat message and get a stream of responses
async fn chat_stream<'a>(
&'a self,
messages: Vec<Message>,
tools: Option<&[DynamicToolDefinition]>,
llm_debug: Option<worker_types::LlmDebug>,
) -> Result<
Box<dyn Stream<Item = Result<StreamEvent, WorkerError>> + Unpin + Send + 'a>,
WorkerError,
>;
/// Check if the connection to the LLM provider is working
async fn check_connection(&self) -> Result<(), WorkerError>;
/// Get the provider type for this client
fn provider(&self) -> LlmProvider;
/// Get the model name being used
fn get_model_name(&self) -> String;
}
// The Worker struct and LlmClient enum are defined in lib.rs
// This file just provides the trait definition that's needed early in the module hierarchy