pub struct ProductionSamplingHandler { /* private fields */ }
Expand description
Production-grade sampling handler with real LLM backend integration
This handler provides enterprise-ready LLM integration with:
- Multi-provider support (OpenAI, Anthropic)
- MCP protocol compliance
- Comprehensive error handling
- Conversation context management
- Retry logic and timeout handling
- Proper async patterns with Send + Sync
§Example Usage
use turbomcp_client::sampling::{ProductionSamplingHandler, LLMBackendConfig, LLMProvider};
let config = LLMBackendConfig {
provider: LLMProvider::OpenAI {
api_key: std::env::var("OPENAI_API_KEY")?,
base_url: None,
organization: None,
},
default_model: Some("gpt-4".to_string()),
timeout_seconds: 30,
max_retries: 3,
};
let handler = ProductionSamplingHandler::new(config)?;
Implementations§
Source§impl ProductionSamplingHandler
impl ProductionSamplingHandler
Sourcepub fn new(config: LLMBackendConfig) -> Result<Self, LLMBackendError>
pub fn new(config: LLMBackendConfig) -> Result<Self, LLMBackendError>
Create a new production sampling handler
Trait Implementations§
Source§impl Debug for ProductionSamplingHandler
impl Debug for ProductionSamplingHandler
Source§impl SamplingHandler for ProductionSamplingHandler
impl SamplingHandler for ProductionSamplingHandler
Source§fn handle_create_message<'life0, 'async_trait>(
&'life0 self,
request: CreateMessageRequest,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle_create_message<'life0, 'async_trait>(
&'life0 self,
request: CreateMessageRequest,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handle a sampling/createMessage request from the server
Auto Trait Implementations§
impl Freeze for ProductionSamplingHandler
impl !RefUnwindSafe for ProductionSamplingHandler
impl Send for ProductionSamplingHandler
impl Sync for ProductionSamplingHandler
impl Unpin for ProductionSamplingHandler
impl !UnwindSafe for ProductionSamplingHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more