AsyncChatbot

Struct AsyncChatbot 

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

Async chatbot client for interacting with Google Gemini.

§Example

use gemini_chat_api::{AsyncChatbot, Model};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let chatbot = AsyncChatbot::new(
        "your_psid",
        "your_psidts",
        Model::default(),
        None,
        30,
    ).await?;

    let response = chatbot.ask("Hello!", None).await?;
    println!("{}", response.content);
    Ok(())
}

Implementations§

Source§

impl AsyncChatbot

Source

pub async fn new( secure_1psid: &str, secure_1psidts: &str, model: Model, proxy: Option<&str>, timeout: u64, ) -> Result<Self>

Creates a new AsyncChatbot instance.

§Arguments
  • secure_1psid - The __Secure-1PSID cookie value
  • secure_1psidts - The __Secure-1PSIDTS cookie value
  • model - The Gemini model to use
  • proxy - Optional proxy URL
  • timeout - Request timeout in seconds
§Returns

A new initialized AsyncChatbot

§Errors

Returns an error if authentication fails or network is unavailable.

Source

pub async fn ask( &mut self, message: &str, image: Option<&[u8]>, ) -> Result<ChatResponse>

Sends a message to Gemini and returns the response.

§Arguments
  • message - The message text to send
  • image - Optional image data to include
§Returns

A ChatResponse containing the Gemini reply and metadata

Source

pub async fn save_conversation( &self, file_path: &str, conversation_name: &str, ) -> Result<()>

Saves the current conversation to a file.

Source

pub async fn load_conversations( &self, file_path: &str, ) -> Result<Vec<SavedConversation>>

Loads all saved conversations from a file.

Source

pub async fn load_conversation( &mut self, file_path: &str, conversation_name: &str, ) -> Result<bool>

Loads a specific conversation by name.

Source

pub fn conversation_id(&self) -> &str

Gets the current conversation ID.

Source

pub fn model(&self) -> &Model

Gets the current model.

Source

pub fn reset(&mut self)

Resets the conversation state (IDs) to start a fresh conversation session. This keeps authentication valid (SNlM0e, cookies) but generates new conversation IDs.

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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