pub struct CohereChat {
pub compatibility_api: Chat,
pub native_api: NativeChat,
pub route: ChatRoute,
}Expand description
Cohere chat: each request goes to the OpenAI Compatibility API or the
native chat API, as ChatRoute says. Requests stay on the
Compatibility API unless with_route opts in to
the native one.
The two are different APIs to history replay. A turn made on one route
replays on the other from its canonical fields only, so its citations
and tool plan stay behind. ChatRoute::Native keeps a whole
conversation on the native API.
Fields§
§compatibility_api: ChatThe Compatibility API’s wire.
native_api: NativeChatThe native API’s wire.
route: ChatRouteWhich API each request goes to.
Implementations§
Source§impl CohereChat
impl CohereChat
Sourcepub fn with_route(self, route: ChatRoute) -> Self
pub fn with_route(self, route: ChatRoute) -> Self
Send requests by route.
Sourcepub fn with_strict_tools(self) -> Self
pub fn with_strict_tools(self) -> Self
Ask both APIs to hold every tool call to its tool’s schema.
Trait Implementations§
Source§impl Clone for CohereChat
impl Clone for CohereChat
Source§impl Debug for CohereChat
impl Debug for CohereChat
Source§impl<'de> Deserialize<'de> for CohereChat
impl<'de> Deserialize<'de> for CohereChat
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for CohereChat
impl PartialEq for CohereChat
Source§impl ReplayTarget for CohereChat
Every request names its route, so these are only what the replay of a
history adapted to the wire as a whole reads: the Compatibility API’s.
impl ReplayTarget for CohereChat
Every request names its route, so these are only what the replay of a history adapted to the wire as a whole reads: the Compatibility API’s.
Source§fn map_options(
&self,
request: &CompletionRequest,
fields: OptionFields<'_>,
) -> OptionMap
fn map_options( &self, request: &CompletionRequest, fields: OptionFields<'_>, ) -> OptionMap
The answer of the API request goes to.
Source§fn accepts(&self, model: &str) -> Accepts
fn accepts(&self, model: &str) -> Accepts
model, the model a request addresses on this wire, reads.
adapt downgrades everything else, so the encoder never sees it.Source§fn route(&self, request: &CompletionRequest) -> Option<&dyn ReplayTarget>
fn route(&self, request: &CompletionRequest) -> Option<&dyn ReplayTarget>
request is sent to, for a wire that picks its API per
request. Preparing the request and folding its reply both read the
target this names, so a turn records the API it was made on. None,
the default, is this target.Source§fn encodes(&self, model: &str, media: Media<'_>) -> bool
fn encodes(&self, model: &str, media: Media<'_>) -> bool
media to model: its source (data,
URL, file id or string), its media type, and where it sits. adapt
replaces every part this refuses with a placeholder, or a text
document with its text, so the encoder never refuses canonical
content. Row H9 of the history conformance suite holds every wire to
it. By default every form is carried.Source§fn normalize_tool_call_id(
&self,
id: &str,
model: &str,
source: Option<&Origin>,
) -> String
fn normalize_tool_call_id( &self, id: &str, model: &str, source: Option<&Origin>, ) -> String
id takes when a call another model made is sent to model
on this wire. source is the call’s origin, None for a hand-built
turn. Results answering the call are rewritten to match, and an id
another call already took is made distinct.Source§fn continues_stored(&self, request: &CompletionRequest) -> bool
fn continues_stored(&self, request: &CompletionRequest) -> bool
request continues a conversation the provider stores, such
as one naming a previous interaction. Results before the history’s
first turn then answer calls the provider holds, so adapt keeps
them.Source§fn declares_tools(&self, request: &CompletionRequest) -> bool
fn declares_tools(&self, request: &CompletionRequest) -> bool
request declares tools to the provider, in tools, in the
tools of its additional_params, or through tools the wire adds.
A request that declares none gets its history’s calls and results as
text. ToolChoice::None still declares them: the wire sends its own
none choice beside the tool history.Source§fn identity(&self, item: &Value) -> Map<String, Value>
fn identity(&self, item: &Value) -> Map<String, Value>
Replay::Identity).
By default none do.Source§fn call_id_slot(&self) -> Option<&'static str>
fn call_id_slot(&self) -> Option<&'static str>
Source§fn states_finish_reason(&self) -> bool
fn states_finish_reason(&self) -> bool
supportsFinishReason); a wire
with no finish vocabulary, such as a local runtime, says false.Source§fn binds_context(&self, model: &str) -> bool
fn binds_context(&self, model: &str) -> bool
model binds its provider items to the request’s tools and
system prompt, so a turn made under another context replays as if
from another model.Source§fn drops_unbound_items(&self, request: &CompletionRequest) -> bool
fn drops_unbound_items(&self, request: &CompletionRequest) -> bool
request asks the provider to drop an item bound to another
context itself (Anthropic’s drop_block), so a turn made under
another context replays verbatim rather than as another model’s.Source§fn takes_documents(&self) -> bool
fn takes_documents(&self) -> bool
Source§fn needs_next(&self, item: &Value) -> bool
fn needs_next(&self, item: &Value) -> bool
Source§fn hosted_pair(&self, item: &Value) -> Option<(Pairing, String)>
fn hosted_pair(&self, item: &Value) -> Option<(Pairing, String)>
Source§fn starts_with_user(&self) -> bool
fn starts_with_user(&self) -> bool
adapt then drops the
assistant turns before the first user message, with their results.Source§fn later_system(&self, model: &str) -> LaterSystem
fn later_system(&self, model: &str) -> LaterSystem
model takes system messages that come after the
conversation begins (LaterSystem). By default where the history
has them.Source§fn alternates_roles(&self) -> bool
fn alternates_roles(&self) -> bool
adapt then joins two messages of one role that only system
messages separate, which move after them.Source§fn hosted_needs_tools(&self) -> bool
fn hosted_needs_tools(&self) -> bool
Source§fn result_parts(&self, model: &str) -> bool
fn result_parts(&self, model: &str) -> bool
model reads a tool result as several parts. When it reads
neither parts nor result images, adapt joins a result’s text
parts into one.Source§fn sends_alone(&self, block: &AssistantContent) -> bool
fn sends_alone(&self, block: &AssistantContent) -> bool
block on its own makes an assistant message this wire
sends. A turn with no such block carries nothing, so adapt drops
it and the user messages around it become one. By default every
block does.Source§impl Serialize for CohereChat
impl Serialize for CohereChat
impl StructuralPartialEq for CohereChat
Source§impl Wire for CohereChat
impl Wire for CohereChat
Source§fn describe(&self) -> Descriptor<'_>
fn describe(&self) -> Descriptor<'_>
The Compatibility API’s description, naming this wire as the replay target that routes each request.
Source§type Op = Completion
type Op = Completion
Source§type Payload = Encoded
type Payload = Encoded
Self::encode produces for the transport to send.Source§type Decoder<'id> = CohereDecoder
type Decoder<'id> = CohereDecoder
Source§type Reassembler = Routed
type Reassembler = Routed
raw.
A wire whose operation’s decoders record raw themselves names
document::Unreassembled; a completion wire cannot, because it
does not Serve completions.Source§fn encode(
&self,
request: CompletionRequest,
mode: Mode,
) -> Result<Encoded, EncodeError>
fn encode( &self, request: CompletionRequest, mode: Mode, ) -> Result<Encoded, EncodeError>
self, request and mode,
and nothing else. A request that cannot be built is an
EncodeError, which always reports as a request failure.Source§fn reassembler(&self) -> Self::Reassembler
fn reassembler(&self) -> Self::Reassembler
Auto Trait Implementations§
impl Freeze for CohereChat
impl RefUnwindSafe for CohereChat
impl Send for CohereChat
impl Sync for CohereChat
impl Unpin for CohereChat
impl UnsafeUnpin for CohereChat
impl UnwindSafe for CohereChat
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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