Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test command to include examples, add test config in ex #97

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
10 changes: 10 additions & 0 deletions rig-core/examples/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/agent_with_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/agent_with_loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/agent_with_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/anthropic_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
16 changes: 13 additions & 3 deletions rig-core/examples/calculator_chatbot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: <tool name>
Expand All @@ -281,3 +281,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/cohere_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/debate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
15 changes: 12 additions & 3 deletions rig-core/examples/gemini_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -47,3 +46,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/gemini_embeddings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/multi_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/perplexity_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/rag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/rag_dynamic_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,13 @@ async fn main() -> Result<(), anyhow::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn example() -> Result<(), anyhow::Error> {
main()
}
}
14 changes: 13 additions & 1 deletion rig-core/examples/sentiment_classifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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()
}
}
14 changes: 13 additions & 1 deletion rig-core/examples/simple_model.rs
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/vector_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
10 changes: 10 additions & 0 deletions rig-core/examples/vector_search_cohere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Loading