Crates.io | openai_rust_sdk |
lib.rs | openai_rust_sdk |
version | 1.2.3 |
created_at | 2025-08-23 18:58:52.507994+00 |
updated_at | 2025-08-29 05:38:06.759914+00 |
description | Comprehensive OpenAI API SDK for Rust with YARA rule validation |
homepage | |
repository | https://github.com/threatflux/openai_rust_sdk |
max_upload_size | |
id | 1807789 |
size | 2,804,175 |
A comprehensive Rust SDK for the OpenAI API with integrated YARA-X rule validation testing. This library provides complete access to all OpenAI APIs including Chat, Assistants, Batch processing, and more, with special capabilities for testing AI models' ability to generate valid YARA rules.
Developed by Wyatt Roersma and Claude Code.
✅ Complete OpenAI API Support
✅ YARA-X Integration
✅ Testing Framework
Add to your Cargo.toml
:
[dependencies]
openai_rust_sdk = "0.1.0"
export OPENAI_API_KEY=your_api_key_here
cargo run -- generate-batch basic output.jsonl
cargo run -- validate-rule rule.yar
cargo run -- run-tests
use openai_rust_sdk::testing::{
batch_generator::BatchJobGenerator,
yara_validator::YaraValidator,
};
fn main() {
// Generate batch job
let generator = BatchJobGenerator::new(Some("gpt-5-nano".to_string()));
let batch_file = std::path::Path::new("test_batch.jsonl");
generator.generate_test_suite(batch_file, "basic").unwrap();
// Validate a YARA rule
let rule = r#"
rule DetectMalware {
strings:
$a = "malware"
condition:
$a
}
"#;
let validator = YaraValidator::new();
let result = validator.validate_rule(rule).unwrap();
if result.is_valid {
println!("✓ Rule is valid!");
}
}
The SDK includes three test suites for different complexity levels:
openai_rust_sdk/
├── src/
│ ├── lib.rs # Library entry point
│ ├── main.rs # CLI application
│ └── testing/
│ ├── mod.rs # Testing module exports
│ ├── yara_validator.rs # YARA-X validation
│ ├── test_cases.rs # Built-in test cases
│ └── batch_generator.rs # Batch job generation
├── examples/
│ └── full_integration.rs # Complete usage example
├── test_data/
│ ├── yara_x_questions.jsonl # Sample questions
│ └── simple_batch.jsonl # Basic test batch
└── tests/
└── integration_test.rs # Integration tests
# Validate a single YARA rule
cargo run -- validate-rule path/to/rule.yar
# Run the built-in test suite
cargo run -- run-tests
# Generate batch job for basic testing
cargo run -- generate-batch basic output.jsonl
# Generate batch job for malware detection
cargo run -- generate-batch malware output.jsonl
# Generate comprehensive test batch
cargo run -- generate-batch comprehensive output.jsonl
The SDK is configured to use gpt-5-nano
for testing, which provides fast and cost-effective rule generation. Example batch request:
{
"custom_id": "yara_001",
"method": "POST",
"url": "/v1/chat/completions",
"body": {
"model": "gpt-5-nano",
"messages": [
{
"role": "system",
"content": "You are an expert YARA rule developer."
},
{
"role": "user",
"content": "Create a YARA rule to detect UPX-packed PE files."
}
],
"max_tokens": 1000,
"temperature": 0.3
}
}
The validator provides comprehensive metrics:
cargo build --release
cargo test
cargo fmt
cargo clippy -- -D warnings
MIT
Contributions are welcome! Please ensure all tests pass and code is properly formatted before submitting PRs.