integ-tests/baml_src/README.md
This directory contains the BAML source files used by all integration tests. It defines the clients, generators, and test cases that are used across all language implementations.
baml_src/
├── clients.baml # Main client definitions
├── generators.baml # Generator functions
├── test-files/ # Test-specific BAML files
│ ├── providers/ # Provider-specific tests
│ ├── testing_pipeline/ # Pipeline test cases
│ └── ...
├── formatter/ # Formatter-specific tests
└── fiddle-examples/ # Example BAML files for testing
Add new client tests in clients.baml:
client<llm> TestGPT {
provider openai
retry_policy TestRetry
options {
model gpt-4
api_key env.OPENAI_API_KEY
}
}
retry_policy TestRetry {
max_retries 3
strategy {
type exponential_backoff
}
}
Add provider-specific tests in test-files/providers/:
// 1. First, define your client
client<llm> TestAnthropic {
provider anthropic
options {
model claude-3-haiku-20240307
api_key env.ANTHROPIC_API_KEY
max_tokens 1000
}
}
// 2. Create a function that uses the client
function TestAnthropicCompletion(input: string) -> string {
client TestAnthropic
prompt #"""
Respond to this input with a simple response.
Input: {{input}}
"""#
}
// 3. Create a test for the function
test TestAnthropicCompletion {
functions [TestAnthropicCompletion]
args {
input #"What is the capital of France?"#
}
assert response == "Paris"
}
// You can also test error cases
function TestAnthropicError(input: string) -> string {
client TestAnthropic
prompt #"""
This is a test for error handling.
{{input}}
"""#
}
test TestAnthropicError {
functions [TestAnthropicError]
args {
input #"Test input"#
}
expect_error true
}
Generators in generators.baml are used to define language-specific output:
generator lang_typescript {
output_type typescript
output_dir "../typescript"
version "0.72.0"
}
generator lang_python {
output_type python/pydantic
output_dir "../python"
version "0.72.0"
}
generator lang_ruby {
output_type ruby/sorbet
output_dir "../ruby"
version "0.72.0"
}
Provider Tests
test-files/providers/Pipeline Tests
test-files/testing_pipeline/Formatter Tests
formatter/Organizing Tests
Writing Test Cases
Using Generators
Adding New Providers
test-files/providers/client<llm> Resilient {
provider baml-fallback
options {
strategy [
GPT4
GPT35
Claude
]
}
}
client<llm> RoundRobin {
provider baml-round-robin
options {
start 0
strategy [
GPT35
Claude
]
}
}
retry_policy TestRetry {
max_retries 3
strategy {
type exponential_backoff
}
}
client<llm> RetryTest {
provider openai
retry_policy TestRetry
options {
model gpt-4
api_key env.OPENAI_API_KEY
}
}