pub struct GenerateContent {
pub provider: GeminiConfig,
pub model: String,
pub cached_content: Option<String>,
pub thought_replay: ThoughtReplay,
}Expand description
Completion wire for unary generateContent and SSE streamGenerateContent.
Both modes use GenerateContentDecoder.
Fields§
§provider: GeminiConfigThe key and the API root.
model: StringThe model to address, e.g. GEMINI_2_5_FLASH.
cached_content: Option<String>Handle of a cachedContents resource every request reads its prefix
from. See Self::with_cached_content.
thought_replay: ThoughtReplayWhich thought signatures requests re-send. See ThoughtReplay.
Implementations§
Source§impl GenerateContent
impl GenerateContent
Sourcepub fn new(provider: GeminiConfig, model: impl Into<String>) -> Self
pub fn new(provider: GeminiConfig, model: impl Into<String>) -> Self
The wire for model.
Sourcepub fn thought_replay(self, replay: ThoughtReplay) -> Self
pub fn thought_replay(self, replay: ThoughtReplay) -> Self
Re-send thought signatures as replay says. See ThoughtReplay.
Sourcepub fn with_cached_content(self, name: impl Into<String>) -> Self
pub fn with_cached_content(self, name: impl Into<String>) -> Self
Use an explicit cachedContents/<id> handle as every request’s prefix.
Encoding rejects requests with their own system instruction, tools, or
tool choice. See crate::providers::gemini::cached_content for cache ownership.
Trait Implementations§
Source§impl Clone for GenerateContent
impl Clone for GenerateContent
Source§impl Debug for GenerateContent
impl Debug for GenerateContent
Source§impl<'de> Deserialize<'de> for GenerateContent
impl<'de> Deserialize<'de> for GenerateContent
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 GenerateContent
impl PartialEq for GenerateContent
Source§impl ReplayTarget for GenerateContent
impl ReplayTarget for GenerateContent
Source§fn later_system(&self, _model: &str) -> LaterSystem
fn later_system(&self, _model: &str) -> LaterSystem
Gemini takes system text only in systemInstruction: later system
messages fold into the leading one, as pi’s collapseSystemMessages.
Source§fn map_options(
&self,
request: &CompletionRequest,
fields: OptionFields<'_>,
) -> OptionMap
fn map_options( &self, request: &CompletionRequest, fields: OptionFields<'_>, ) -> OptionMap
Section 6.4 of the typed-options design, for the Gemini API.
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 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 call_id_slot(&self) -> Option<&'static str>
fn call_id_slot(&self) -> Option<&'static str>
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 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 identity(&self, item: &Value) -> Map<String, Value>
fn identity(&self, item: &Value) -> Map<String, Value>
Replay::Identity).
By default none do.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 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 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 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 GenerateContent
impl Serialize for GenerateContent
impl StructuralPartialEq for GenerateContent
Source§impl<T> Transport<GenerateContent> for Caching<T>where
T: Transport<GenerateContent>,
impl<T> Transport<GenerateContent> for Caching<T>where
T: Transport<GenerateContent>,
Source§impl Wire for GenerateContent
impl Wire for GenerateContent
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> = GenerateContentDecoder
type Decoder<'id> = GenerateContentDecoder
Source§type Reassembler = GenerateContentResponse
type Reassembler = GenerateContentResponse
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 describe(&self) -> Descriptor<'_>
fn describe(&self) -> Descriptor<'_>
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 GenerateContent
impl RefUnwindSafe for GenerateContent
impl Send for GenerateContent
impl Sync for GenerateContent
impl Unpin for GenerateContent
impl UnsafeUnpin for GenerateContent
impl UnwindSafe for GenerateContent
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