pub struct Endpoint {
pub address: String,
pub model: String,
pub key_header: String,
pub key: Option<Key>,
pub silence: Duration,
}Expand description
A provider speaking the Anthropic Messages shape.
Fields§
§address: StringThe address the API lives under, such as https://api.example.com/anthropic; requests go
to {address}/v1/messages.
model: StringThe model asked for.
key_header: StringThe header the key goes in: x-api-key for most, another name for some servers. For
authorization the key goes in as a bearer token.
key: Option<Key>The key, or None for a relay on this machine that adds the key itself: QCode’s, inside a
profile’s container, which the key never enters. Without one no key header is sent at all.
silence: DurationHow long the server may send nothing in the middle of a reply before it is given up on.
Implementations§
Source§impl Endpoint
impl Endpoint
Sourcepub const SILENCE: Duration
pub const SILENCE: Duration
How long a server may go quiet in the middle of a reply: generous, since a model can think a while between two pieces, and finite, since a reply that waits for ever is a stuck screen.
Sourcepub fn url(&self) -> String
pub fn url(&self) -> String
Where a message request goes. The key is never part of it, so it is safe to show.
Sourcepub fn stream(
&self,
body: &Value,
on_delta: &mut dyn FnMut(Delta),
cancelled: &dyn Fn() -> bool,
) -> Result<Reply, ProviderError>
pub fn stream( &self, body: &Value, on_delta: &mut dyn FnMut(Delta), cancelled: &dyn Fn() -> bool, ) -> Result<Reply, ProviderError>
Sends body (a Messages request without model and stream, which are added here) and
reads the streamed reply, handing each piece to on_delta as it arrives. cancelled is
asked between events.
§Errors
When the server cannot be reached, refuses, or answers with something that is not a Messages reply. No error carries the key.
Trait Implementations§
impl Eq for Endpoint
impl StructuralPartialEq for Endpoint
Auto Trait Implementations§
impl Freeze for Endpoint
impl RefUnwindSafe for Endpoint
impl Send for Endpoint
impl Sync for Endpoint
impl Unpin for Endpoint
impl UnsafeUnpin for Endpoint
impl UnwindSafe for Endpoint
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more