Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ pub enum GeminiError {
EventSource(#[from] reqwest_eventsource::Error),
#[error("API Error: {0}")]
Api(Value),
#[error("JSON Error: {0}")]
Json(#[from] serde_json::Error),
#[error("JSON Error: {error} (payload: {data})")]
Json {
data: String,
#[source]
error: serde_json::Error,
},
#[error("Function execution error: {0}")]
FunctionExecution(String),
}
Expand Down Expand Up @@ -210,7 +214,10 @@ impl GeminiClient {
Event::Open => (),
Event::Message(event) => yield
serde_json::from_str::<types::GenerateContentResponse>(&event.data)
.map_err(Into::into),
.map_err(|error| GeminiError::Json {
data: event.data,
error,
}),
},
Err(e) => match e {
reqwest_eventsource::Error::StreamEnded => stream.close(),
Expand Down
21 changes: 21 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub enum FunctionCallingMode {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Content {
#[serde(default)]
pub parts: Vec<ContentPart>,
// Optional. The producer of the content. Must be either 'user' or 'model'.
// Useful to set for multi-turn conversations, otherwise can be left blank or unset.
Expand Down Expand Up @@ -171,6 +172,7 @@ pub struct FunctionDeclaration {
pub name: String,
pub description: String,
pub parameters: Option<FunctionParameters>,
pub parameters_json_schema: Option<serde_json::Value>,
pub response: Option<FunctionParameters>,
}

Expand Down Expand Up @@ -344,6 +346,25 @@ pub struct ThinkingConfig {
pub include_thoughts: bool,
/// The number of thoughts tokens that the model should generate.
pub thinking_budget: Option<u32>,
/// Controls the maximum depth of the model's internal reasoning process
/// before it produces a response. If not specified, the default is HIGH.
/// Recommended for Gemini 3 or later models. Use with earlier models
/// results in an error.
pub thinking_level: Option<ThinkingLevel>,
}

/// Allow user to specify how much to think using enum instead of integer
/// budget.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ThinkingLevel {
/// Unspecified thinking level.
#[default]
ThinkingLevelUnspecified,
/// High thinking level.
High,
/// Low thinking level.
Low,
}

/// A response candidate generated from the model.
Expand Down