Skip to main content

Gemini

Struct Gemini 

Source
pub struct Gemini { /* private fields */ }
Expand description

Calls the Gemini Developer API.

The key is held here and never journaled — transport metadata in exactly the sense a peer credential is, and the same rule applies: a secret in a hash-chained record cannot be redacted afterwards, only discovered.

Implementations§

Source§

impl Gemini

Source

pub const DEFAULT_TIMEOUT: Duration

Source

pub const DEFAULT_BASE: &'static str = "https://generativelanguage.googleapis.com"

The default endpoint.

Source

pub const VERSION: &'static str = "v1beta"

The API version this driver speaks.

Pinned rather than tracking the newest, for the reason every version here is pinned: a provider that changes its response shape under a running plane changes what replay reads back.

Source

pub fn new(key: impl Into<String>) -> Result<Self, ModelError>

Build with a key.

§Errors

If the HTTP client cannot be built.

Source

pub fn from_env() -> Result<Self, ModelError>

Take the key from GEMINI_API_KEY, falling back to GOOGLE_API_KEY.

Both are read because both are in wide use and a deployment that exported the other one would otherwise get an authentication failure naming neither.

§Errors

If neither variable is set, or the HTTP client cannot be built.

Source

pub fn base(self, base: impl Into<String>) -> Self

Point at another endpoint — a regional host, or a test double.

Source

pub const fn timeout(self, timeout: Duration) -> Self

Bound connection, generation, and response streaming as one operation.

Source

pub fn structured_via(self, mode: SchemaMode) -> Self

How to obtain a schema-conforming answer from every model.

Source

pub fn structured_via_for( self, model: impl Into<String>, mode: SchemaMode, ) -> Self

How to obtain a schema-conforming answer from one model.

Source

pub fn safety(self, safety: SafetySettings) -> Self

Apply the deployment’s own safety thresholds to every call.

See SafetySettings for the posture. In short: this crate ships no classifier, Google’s is configured here, and what the runtime owns is that the choice is effect identity and that an intervention is a metered refusal rather than an answer.

Source

pub fn egress(self, egress: Egress) -> Self

Restrict where this driver may connect.

Deny-by-default once set — see Egress.

Source

pub const fn buffered(self) -> Self

Ask for the whole response at once instead of streaming it.

Streaming is the default for the reason it is elsewhere in this crate: Gemini reports usageMetadata in the stream, so a severed connection can say what it burned rather than being billed as zero and retried for free.

Trait Implementations§

Source§

impl Debug for Gemini

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Redacts the key. Deriving Debug would print it into every log line and span that touches the provider.

Source§

impl ModelProvider for Gemini

Source§

fn request_profile(&self, model: &ModelId) -> Value

Stable, non-secret configuration that changes the provider wire request. Read more
Source§

fn complete<'life0, 'life1, 'async_trait>( &'life0 self, request: Request<'life1>, ) -> Pin<Box<dyn Future<Output = Result<Completion, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Complete a prompt. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more