pub struct AnthropicWorker { /* private fields */ }Expand description
Anthropic Claude API worker
Requires ANTHROPIC_API_KEY environment variable.
§Example
let worker = Arc::new(
AnthropicWorker::new("claude-3-5-sonnet-20241022")?
.with_max_tokens(1024)
.with_temperature(1.0)
);§Resilience
AnthropicWorker does not retry internally. Retry logic is handled by the
pipeline’s inference stage. See ModelWorker for details.
Implementations§
Source§impl AnthropicWorker
impl AnthropicWorker
Sourcepub fn new(model: impl Into<String>) -> Result<Self, OrchestratorError>
pub fn new(model: impl Into<String>) -> Result<Self, OrchestratorError>
Create a new AnthropicWorker for the given model.
Reads the API key from the ANTHROPIC_API_KEY environment variable and
constructs an HTTP client configured for the Anthropic Messages API.
Default settings: 1024 max tokens, temperature 1.0, 60 s timeout. All
defaults are overridable via the builder methods.
§Environment Variables
| Variable | Required | Description |
|---|---|---|
ANTHROPIC_API_KEY | Yes | API key sent via x-api-key header |
§Errors
Returns OrchestratorError::ConfigError if ANTHROPIC_API_KEY is
not set in the environment.
§Examples
use tokio_prompt_orchestrator::AnthropicWorker;
use std::sync::Arc;
// ANTHROPIC_API_KEY must be set in the environment.
let worker = Arc::new(
AnthropicWorker::new("claude-3-5-sonnet-20241022")
.expect("ANTHROPIC_API_KEY must be set")
.with_max_tokens(1024)
.with_temperature(1.0),
);Sourcepub fn with_max_tokens(self, max_tokens: u32) -> Self
pub fn with_max_tokens(self, max_tokens: u32) -> Self
Set maximum tokens to generate
Sourcepub fn with_temperature(self, temperature: f32) -> Self
pub fn with_temperature(self, temperature: f32) -> Self
Set temperature (0.0 – 1.0 for Anthropic).
Values outside [0.0, 1.0] are clamped and a WARN-level log line is
emitted. The Anthropic API rejects values outside this range with HTTP 400.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set request timeout
Sourcepub fn with_base_url(self, url: impl Into<String>) -> Self
pub fn with_base_url(self, url: impl Into<String>) -> Self
Override the API base URL.
Useful for Anthropic-compatible endpoints or for pointing at a mock server
in tests. Default: "https://api.anthropic.com/v1".
Trait Implementations§
Source§impl Debug for AnthropicWorker
impl Debug for AnthropicWorker
Source§impl ModelWorker for AnthropicWorker
impl ModelWorker for AnthropicWorker
Source§fn infer<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, OrchestratorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn infer<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, OrchestratorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn infer_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<TokenStream, OrchestratorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn infer_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<TokenStream, OrchestratorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for AnthropicWorker
impl !UnwindSafe for AnthropicWorker
impl Freeze for AnthropicWorker
impl Send for AnthropicWorker
impl Sync for AnthropicWorker
impl Unpin for AnthropicWorker
impl UnsafeUnpin for AnthropicWorker
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request