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

chore: AI Add 'sbom-info' tool test #1001

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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-ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
ollama serve &
ollama pull llama3.1:8b
- name: Test
run: cargo test -p trustify-module-fundamental ai:: -- --nocapture
run: 'cargo test -p trustify-module-fundamental ai:: -- --nocapture'
env:
RUST_LOG: trustify_module_fundamental::ai=info,langchain_rust=info
OPENAI_API_KEY: ollama
Expand Down
103 changes: 103 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion modules/fundamental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ tokio-util = { workspace = true }
trustify-cvss = { workspace = true }
trustify-test-context = { workspace = true }
urlencoding = { workspace = true }
walkdir = { workspace = true }
walkdir = { workspace = true }
zip = { workspace = true }
termimad = "0.31.0"

[[bench]]
name = "bench"
Expand Down
9 changes: 7 additions & 2 deletions modules/fundamental/src/ai/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn configure(ctx: &TrustifyContext) -> anyhow::Result<()> {

let app = caller(ctx).await?;
let mut req = ChatState::new();
req.add_human_message("What is the latest version of Trusted Profile Analyzer?".into());
req.add_human_message("Give me information about the SBOMs available for quarkus reporting its name, SHA and URL.".into());

let request = TestRequest::post()
.uri("/api/v1/ai/completions")
Expand All @@ -36,7 +36,12 @@ async fn configure(ctx: &TrustifyContext) -> anyhow::Result<()> {

let result: ChatState = actix_web::test::read_body_json(response).await;
log::info!("result: {:?}", result);
assert!(result.messages.last().unwrap().content.contains("37.17.9"));
assert!(result
.messages
.last()
.unwrap()
.content
.contains("quarkus-bom"));

Ok(())
}
Expand Down
18 changes: 15 additions & 3 deletions modules/fundamental/src/ai/service/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub async fn ingest_fixtures(ctx: &TrustifyContext) -> Result<(), anyhow::Error>

ctx.ingest_documents(["osv/RUSTSEC-2021-0079.json", "cve/CVE-2021-32714.json"])
.await?;
ctx.ingest_document("quarkus/v1/quarkus-bom-2.13.8.Final-redhat-00004.json")
.await?;

Ok(())
}
Expand Down Expand Up @@ -70,12 +72,22 @@ async fn completions(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
ingest_fixtures(ctx).await?;

let mut req = ChatState::new();
req.add_human_message("What is the latest version of Trusted Profile Analyzer?".into());
req.add_human_message(
"Give me information about the SBOMs available for quarkus reporting its name, SHA and URL."
.into(),
);

let result = service.completions(&req, ()).await?;

log::info!("result: {:?}", result);
assert!(result.messages.last().unwrap().content.contains("37.17.9"));
log::info!("result: {:#?}", result);
let last_message_content = result.messages.last().unwrap().content.clone();
println!(
"Test formatted output:\n\n{}\n",
termimad::inline(last_message_content.as_str())
);
assert!(last_message_content.contains("quarkus-bom"));
assert!(last_message_content
.contains("5a370574a991aa42f7ecc5b7d88754b258f81c230a73bea247c0a6fcc6f608ab"));

Ok(())
}