rig_core/providers/gemini/mod.rs
1//! Google Gemini API client and Rig integration
2//!
3//! # Example
4//! ```no_run
5//! use rig_core::{client::EmbeddingsClient, providers::gemini};
6//!
7//! # fn run() -> Result<(), Box<dyn std::error::Error>> {
8//! let client = gemini::Client::new("YOUR_API_KEY")?;
9//!
10//! let gemini_embedding_model = client.embedding_model(gemini::EMBEDDING_001);
11//! # Ok(())
12//! # }
13//! ```
14
15pub mod client;
16pub mod completion;
17pub mod embedding;
18#[cfg(feature = "image")]
19#[cfg_attr(docsrs, doc(cfg(feature = "image")))]
20pub mod image_generation;
21pub mod interactions_api;
22pub mod model_listing;
23pub mod streaming;
24pub mod transcription;
25
26pub use client::{Client, InteractionsClient};
27pub use completion::CompletionModel;
28pub use embedding::{EMBEDDING_001, EMBEDDING_004, EmbeddingModel};
29#[cfg(feature = "image")]
30pub use image_generation::{GEMINI_2_5_FLASH_IMAGE, ImageGenerationModel};
31pub use model_listing::*;
32
33pub mod gemini_api_types {
34 use serde::{Deserialize, Serialize};
35
36 #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
37 #[serde(rename_all = "SCREAMING_SNAKE_CASE")]
38 pub enum ExecutionLanguage {
39 /// Unspecified language. This value should not be used.
40 LanguageUnspecified,
41 /// Python >= 3.10, with numpy and simply available.
42 Python,
43 }
44
45 /// Code generated by the model that is meant to be executed, and the result returned to the model.
46 /// Only generated when using the CodeExecution tool, in which the code will be automatically executed,
47 /// and a corresponding CodeExecutionResult will also be generated.
48 #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
49 pub struct ExecutableCode {
50 /// Programming language of the code.
51 pub language: ExecutionLanguage,
52 /// The code to be executed.
53 pub code: String,
54 }
55 #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
56 pub struct CodeExecutionResult {
57 /// Outcome of the code execution.
58 pub outcome: CodeExecutionOutcome,
59 /// Contains stdout when code execution is successful, stderr or other description otherwise.
60 #[serde(skip_serializing_if = "Option::is_none")]
61 pub output: Option<String>,
62 }
63
64 #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
65 pub enum CodeExecutionOutcome {
66 /// Unspecified status. This value should not be used.
67 #[serde(rename = "OUTCOME_UNSPECIFIED")]
68 Unspecified,
69 /// Code execution completed successfully.
70 #[serde(rename = "OUTCOME_OK")]
71 Ok,
72 /// Code execution finished but with a failure. stderr should contain the reason.
73 #[serde(rename = "OUTCOME_FAILED")]
74 Failed,
75 /// Code execution ran for too long, and was cancelled. There may or may not be a partial output present.
76 #[serde(rename = "OUTCOME_DEADLINE_EXCEEDED")]
77 DeadlineExceeded,
78 }
79}