From 13355cba05d52a25824c050114c3c67a31de2cad Mon Sep 17 00:00:00 2001 From: Mathieu Date: Tue, 12 Nov 2024 19:30:11 +0100 Subject: [PATCH] test: add test command to include examples, add test config in ex --- .github/workflows/ci.yaml | 2 +- rig-core/examples/agent.rs | 10 ++++++++++ rig-core/examples/agent_with_context.rs | 10 ++++++++++ rig-core/examples/agent_with_loaders.rs | 10 ++++++++++ rig-core/examples/agent_with_tools.rs | 10 ++++++++++ rig-core/examples/anthropic_agent.rs | 10 ++++++++++ rig-core/examples/calculator_chatbot.rs | 16 +++++++++++++--- rig-core/examples/cohere_connector.rs | 10 ++++++++++ rig-core/examples/debate.rs | 10 ++++++++++ rig-core/examples/extractor.rs | 10 ++++++++++ rig-core/examples/gemini_agent.rs | 15 ++++++++++++--- rig-core/examples/gemini_embeddings.rs | 10 ++++++++++ rig-core/examples/loaders.rs | 10 ++++++++++ rig-core/examples/multi_agent.rs | 10 ++++++++++ rig-core/examples/perplexity_agent.rs | 10 ++++++++++ rig-core/examples/rag.rs | 10 ++++++++++ rig-core/examples/rag_dynamic_tools.rs | 10 ++++++++++ rig-core/examples/sentiment_classifier.rs | 14 +++++++++++++- rig-core/examples/simple_model.rs | 14 +++++++++++++- rig-core/examples/vector_search.rs | 10 ++++++++++ rig-core/examples/vector_search_cohere.rs | 10 ++++++++++ 21 files changed, 212 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b65da281..3ec3bb9e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -78,7 +78,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: nextest - args: run --all-features + args: run --all-features --tests --examples env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} diff --git a/rig-core/examples/agent.rs b/rig-core/examples/agent.rs index 9f68f8bc..a7e0df21 100644 --- a/rig-core/examples/agent.rs +++ b/rig-core/examples/agent.rs @@ -21,3 +21,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/agent_with_context.rs b/rig-core/examples/agent_with_context.rs index 7e98351b..7d2b942e 100644 --- a/rig-core/examples/agent_with_context.rs +++ b/rig-core/examples/agent_with_context.rs @@ -26,3 +26,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/agent_with_loaders.rs b/rig-core/examples/agent_with_loaders.rs index 9ddf22de..dd431f9a 100644 --- a/rig-core/examples/agent_with_loaders.rs +++ b/rig-core/examples/agent_with_loaders.rs @@ -36,3 +36,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/agent_with_tools.rs b/rig-core/examples/agent_with_tools.rs index 915c4d52..47916af8 100644 --- a/rig-core/examples/agent_with_tools.rs +++ b/rig-core/examples/agent_with_tools.rs @@ -111,3 +111,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/anthropic_agent.rs b/rig-core/examples/anthropic_agent.rs index 9e3ea255..dcf2cfca 100644 --- a/rig-core/examples/anthropic_agent.rs +++ b/rig-core/examples/anthropic_agent.rs @@ -29,3 +29,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/calculator_chatbot.rs b/rig-core/examples/calculator_chatbot.rs index 04d26dc3..06b0de70 100644 --- a/rig-core/examples/calculator_chatbot.rs +++ b/rig-core/examples/calculator_chatbot.rs @@ -260,10 +260,10 @@ async fn main() -> Result<(), anyhow::Error> { .agent("gpt-4") .preamble( "You are an assistant here to help the user select which tool is most appropriate to perform arithmetic operations. - Follow these instructions closely. + Follow these instructions closely. 1. Consider the user's request carefully and identify the core elements of the request. - 2. Select which tool among those made available to you is appropriate given the context. - 3. This is very important: never perform the operation yourself and never give me the direct result. + 2. Select which tool among those made available to you is appropriate given the context. + 3. This is very important: never perform the operation yourself and never give me the direct result. Always respond with the name of the tool that should be used and the appropriate inputs in the following format: Tool: @@ -281,3 +281,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/cohere_connector.rs b/rig-core/examples/cohere_connector.rs index 607d9eb6..a3c3504e 100644 --- a/rig-core/examples/cohere_connector.rs +++ b/rig-core/examples/cohere_connector.rs @@ -48,3 +48,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/debate.rs b/rig-core/examples/debate.rs index 81e81265..38466a04 100644 --- a/rig-core/examples/debate.rs +++ b/rig-core/examples/debate.rs @@ -98,3 +98,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/extractor.rs b/rig-core/examples/extractor.rs index 15389a2e..09b64085 100644 --- a/rig-core/examples/extractor.rs +++ b/rig-core/examples/extractor.rs @@ -29,3 +29,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/gemini_agent.rs b/rig-core/examples/gemini_agent.rs index 785309a3..5f786db7 100644 --- a/rig-core/examples/gemini_agent.rs +++ b/rig-core/examples/gemini_agent.rs @@ -2,10 +2,9 @@ use rig::{ completion::Prompt, providers::gemini::{self, completion::gemini_api_types::GenerationConfig}, }; -#[tracing::instrument(ret)] -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { +#[tokio::main] +pub async fn main() -> Result<(), anyhow::Error> { tracing_subscriber::fmt() .with_max_level(tracing::Level::DEBUG) .with_target(false) @@ -47,3 +46,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/gemini_embeddings.rs b/rig-core/examples/gemini_embeddings.rs index 4ce24636..6f9c7223 100644 --- a/rig-core/examples/gemini_embeddings.rs +++ b/rig-core/examples/gemini_embeddings.rs @@ -18,3 +18,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/loaders.rs b/rig-core/examples/loaders.rs index e4670a71..0fbb14af 100644 --- a/rig-core/examples/loaders.rs +++ b/rig-core/examples/loaders.rs @@ -12,3 +12,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/multi_agent.rs b/rig-core/examples/multi_agent.rs index e6e9ef75..8456fde5 100644 --- a/rig-core/examples/multi_agent.rs +++ b/rig-core/examples/multi_agent.rs @@ -68,3 +68,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/perplexity_agent.rs b/rig-core/examples/perplexity_agent.rs index a8ae8d96..2059fcf2 100644 --- a/rig-core/examples/perplexity_agent.rs +++ b/rig-core/examples/perplexity_agent.rs @@ -32,3 +32,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/rag.rs b/rig-core/examples/rag.rs index 3abd8ee9..246ea774 100644 --- a/rig-core/examples/rag.rs +++ b/rig-core/examples/rag.rs @@ -45,3 +45,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/rag_dynamic_tools.rs b/rig-core/examples/rag_dynamic_tools.rs index 6e45730b..fdde7dca 100644 --- a/rig-core/examples/rag_dynamic_tools.rs +++ b/rig-core/examples/rag_dynamic_tools.rs @@ -183,3 +183,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/sentiment_classifier.rs b/rig-core/examples/sentiment_classifier.rs index 4ac0688d..5216335f 100644 --- a/rig-core/examples/sentiment_classifier.rs +++ b/rig-core/examples/sentiment_classifier.rs @@ -17,7 +17,7 @@ struct DocumentSentiment { } #[tokio::main] -async fn main() { +async fn main() -> Result<(), anyhow::Error> { // Create OpenAI client let openai_client = openai::Client::from_env(); @@ -32,4 +32,16 @@ async fn main() { .expect("Failed to extract sentiment"); println!("GPT-4: {:?}", sentiment); + + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } } diff --git a/rig-core/examples/simple_model.rs b/rig-core/examples/simple_model.rs index 164dee09..e32b935f 100644 --- a/rig-core/examples/simple_model.rs +++ b/rig-core/examples/simple_model.rs @@ -1,7 +1,7 @@ use rig::{completion::Prompt, providers::openai}; #[tokio::main] -async fn main() { +async fn main() -> Result<(), anyhow::Error> { // Create OpenAI client and model let openai_client = openai::Client::from_env(); @@ -14,4 +14,16 @@ async fn main() { .expect("Failed to prompt GPT-4"); println!("GPT-4: {response}"); + + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example() -> Result<(), anyhow::Error> { + main() + } } diff --git a/rig-core/examples/vector_search.rs b/rig-core/examples/vector_search.rs index ec6aabd5..82283f4e 100644 --- a/rig-core/examples/vector_search.rs +++ b/rig-core/examples/vector_search.rs @@ -42,3 +42,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn example() -> Result<(), anyhow::Error> { + main() + } +} diff --git a/rig-core/examples/vector_search_cohere.rs b/rig-core/examples/vector_search_cohere.rs index a49ac231..196f60b6 100644 --- a/rig-core/examples/vector_search_cohere.rs +++ b/rig-core/examples/vector_search_cohere.rs @@ -39,3 +39,13 @@ async fn main() -> Result<(), anyhow::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn example() -> Result<(), anyhow::Error> { + main() + } +}