diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e0..7d466fd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,13 +10,19 @@ env: CARGO_TERM_COLOR: always jobs: - build: - + check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + # The Gitea runner image doesn't ship with Rust, unlike GitHub's. + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy, rustfmt + - uses: Swatinem/rust-cache@v2 + - name: Format + run: cargo fmt --check + - name: Clippy + run: cargo clippy --all-targets -- -D warnings + - name: Test + run: cargo test diff --git a/examples/conversation.rs b/examples/conversation.rs index 4707a71..addd804 100644 --- a/examples/conversation.rs +++ b/examples/conversation.rs @@ -1,5 +1,5 @@ use console::style; -use dialoguer::{theme::ColorfulTheme, Input}; +use dialoguer::{Input, theme::ColorfulTheme}; use gemini_rs::prelude::*; use std::time::Duration; diff --git a/examples/system_instruction.rs b/examples/system_instruction.rs index fc1c63f..29da4f5 100644 --- a/examples/system_instruction.rs +++ b/examples/system_instruction.rs @@ -19,10 +19,12 @@ async fn main() -> Result<(), Box> { .add_text_part("Answer as if you were Yoda") .build(); - let user_prompt = vec![Content::builder() - .role(Role::User) - .add_text_part("What is the airspeed of an unladen swallow?") - .build()]; + let user_prompt = vec![ + Content::builder() + .role(Role::User) + .add_text_part("What is the airspeed of an unladen swallow?") + .build(), + ]; let request = GenerateContentRequest::builder() .contents(user_prompt) diff --git a/examples/text-from-text-streaming.rs b/examples/text-from-text-streaming.rs index f92c201..05e4e34 100644 --- a/examples/text-from-text-streaming.rs +++ b/examples/text-from-text-streaming.rs @@ -1,34 +1,36 @@ -use gemini_rs::prelude::*; -use tokio_stream::StreamExt; - -#[tokio::main] -async fn main() -> Result<(), Box> { - let authentication_manager = gcp_auth::provider().await?; - let api_endpoint = std::env::var("API_ENDPOINT")?; - let project_id = std::env::var("PROJECT_ID")?; - let location_id = std::env::var("LOCATION_ID")?; - - let gemini = GeminiClient::new( - authentication_manager, - api_endpoint, - project_id, - location_id, - ); - - let prompt = vec![Content::builder() - .role(Role::User) - .add_text_part("Tell me the story of the genesis of the universe as a bedtime story.") - .build()]; - - let request = GenerateContentRequest::builder().contents(prompt).build(); - - let mut queue = gemini - .stream_generate_content(&request, "gemini-2.0-flash-001") - .await?; - - while let Some(response) = queue.next().await { - println!("Response: {:?}", response?); - } - - Ok(()) -} +use gemini_rs::prelude::*; +use tokio_stream::StreamExt; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let authentication_manager = gcp_auth::provider().await?; + let api_endpoint = std::env::var("API_ENDPOINT")?; + let project_id = std::env::var("PROJECT_ID")?; + let location_id = std::env::var("LOCATION_ID")?; + + let gemini = GeminiClient::new( + authentication_manager, + api_endpoint, + project_id, + location_id, + ); + + let prompt = vec![ + Content::builder() + .role(Role::User) + .add_text_part("Tell me the story of the genesis of the universe as a bedtime story.") + .build(), + ]; + + let request = GenerateContentRequest::builder().contents(prompt).build(); + + let mut queue = gemini + .stream_generate_content(&request, "gemini-2.0-flash-001") + .await?; + + while let Some(response) = queue.next().await { + println!("Response: {:?}", response?); + } + + Ok(()) +} diff --git a/examples/text-from-text.rs b/examples/text-from-text.rs index fa8e739..a234d16 100644 --- a/examples/text-from-text.rs +++ b/examples/text-from-text.rs @@ -1,27 +1,29 @@ -use gemini_rs::prelude::*; - -#[tokio::main] -async fn main() -> Result<(), Box> { - let authentication_manager = gcp_auth::provider().await?; - let api_endpoint = std::env::var("API_ENDPOINT")?; - let project_id = std::env::var("PROJECT_ID")?; - let location_id = std::env::var("LOCATION_ID")?; - - let gemini = GeminiClient::new( - authentication_manager, - api_endpoint, - project_id, - location_id, - ); - - let prompt = vec![Content::builder() - .role(Role::User) - .add_text_part("What is the airspeed of an unladen swallow?") - .build()]; - - let request = GenerateContentRequest::builder().contents(prompt).build(); - let response = gemini.generate_content(&request, "gemini-pro").await?; - println!("Response: {:?}", response.candidates[0].get_text().unwrap()); - - Ok(()) -} +use gemini_rs::prelude::*; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let authentication_manager = gcp_auth::provider().await?; + let api_endpoint = std::env::var("API_ENDPOINT")?; + let project_id = std::env::var("PROJECT_ID")?; + let location_id = std::env::var("LOCATION_ID")?; + + let gemini = GeminiClient::new( + authentication_manager, + api_endpoint, + project_id, + location_id, + ); + + let prompt = vec![ + Content::builder() + .role(Role::User) + .add_text_part("What is the airspeed of an unladen swallow?") + .build(), + ]; + + let request = GenerateContentRequest::builder().contents(prompt).build(); + let response = gemini.generate_content(&request, "gemini-pro").await?; + println!("Response: {:?}", response.candidates[0].get_text().unwrap()); + + Ok(()) +}