-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue where literal inptus are not typechecked correctly (#1121)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Fixes type checking for literal inputs by refining subtype logic and adding tests for literals and optional types. > > - **Behavior**: > - Fixes type checking for literal inputs in `distribute_type()` in `mod.rs` by refining subtype logic. > - Updates `coerce_arg()` in `to_baml_arg.rs` to handle literals and optional types more accurately. > - **Type System**: > - Refines `is_subtype_of()` in `field_type/mod.rs` and `types.rs` to improve handling of literals and optional types. > - Adds `is_subtype_of()` logic to `Type` and `FieldType` to handle nested and union types. > - **Tests**: > - Adds tests for literal handling in `test_runtime.rs` and `mod.rs`. > - Adds `prompt2.baml` for validation of function prompts with literals. > - **Dependencies**: > - Adds `log` and `minijinja` to `Cargo.toml` dependencies. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 7dae7e7. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
- Loading branch information
Showing
15 changed files
with
1,213 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
engine/baml-lib/baml/tests/validation_files/baml_cli_init.baml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Defining a data model. | ||
class Resume { | ||
name string | ||
email string | ||
experience string[] | ||
skills string[] | ||
} | ||
|
||
// Create a function to extract the resume from a string. | ||
function ExtractResume(resume: string) -> Resume { | ||
// Specify a client as provider/model-name | ||
// you can use custom LLM params with a custom client name from clients.baml like "client CustomHaiku" | ||
client "openai/gpt-4o" // Set OPENAI_API_KEY to use this client. | ||
prompt #" | ||
Extract from this content: | ||
{{ resume }} | ||
|
||
{{ ctx.output_format }} | ||
"# | ||
} | ||
|
||
// Test the function with a sample resume. Open the VSCode playground to run this. | ||
test vaibhav_resume { | ||
functions [ExtractResume] | ||
args { | ||
resume #" | ||
Vaibhav Gupta | ||
[email protected] | ||
|
||
Experience: | ||
- Founder at BoundaryML | ||
- CV Engineer at Google | ||
- CV Engineer at Microsoft | ||
|
||
Skills: | ||
- Rust | ||
- C++ | ||
"# | ||
} | ||
} | ||
|
||
// Learn more about clients at https://docs.boundaryml.com/docs/snippets/clients/overview | ||
|
||
client<llm> CustomGPT4o { | ||
provider openai | ||
options { | ||
model "gpt-4o" | ||
api_key env.OPENAI_API_KEY | ||
} | ||
} | ||
|
||
client<llm> CustomGPT4oMini { | ||
provider openai | ||
retry_policy Exponential | ||
options { | ||
model "gpt-4o-mini" | ||
api_key env.OPENAI_API_KEY | ||
} | ||
} | ||
|
||
client<llm> CustomSonnet { | ||
provider anthropic | ||
options { | ||
model "claude-3-5-sonnet-20241022" | ||
api_key env.ANTHROPIC_API_KEY | ||
} | ||
} | ||
|
||
|
||
client<llm> CustomHaiku { | ||
provider anthropic | ||
retry_policy Constant | ||
options { | ||
model "claude-3-haiku-20240307" | ||
api_key env.ANTHROPIC_API_KEY | ||
} | ||
} | ||
|
||
// https://docs.boundaryml.com/docs/snippets/clients/round-robin | ||
client<llm> CustomFast { | ||
provider round-robin | ||
options { | ||
// This will alternate between the two clients | ||
strategy [CustomGPT4oMini, CustomHaiku] | ||
} | ||
} | ||
|
||
// https://docs.boundaryml.com/docs/snippets/clients/fallback | ||
client<llm> OpenaiFallback { | ||
provider fallback | ||
options { | ||
// This will try the clients in order until one succeeds | ||
strategy [CustomGPT4oMini, CustomGPT4oMini] | ||
} | ||
} | ||
|
||
// https://docs.boundaryml.com/docs/snippets/clients/retry | ||
retry_policy Constant { | ||
max_retries 3 | ||
// Strategy is optional | ||
strategy { | ||
type constant_delay | ||
delay_ms 200 | ||
} | ||
} | ||
|
||
retry_policy Exponential { | ||
max_retries 2 | ||
// Strategy is optional | ||
strategy { | ||
type exponential_backoff | ||
delay_ms 300 | ||
mutliplier 1.5 | ||
max_delay_ms 10000 | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
engine/baml-lib/baml/tests/validation_files/functions_v2/prompt_errors/prompt2.baml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Message { | ||
role "user" | "assistant" | string | ||
message string | ||
} | ||
|
||
function Bot(convo: Message[]) -> string { | ||
client "openai/gpt-4o" | ||
prompt #" | ||
You are a helpful assistant. | ||
{{ ctx.output_format }} | ||
|
||
{% for m in convo %} | ||
{{ _.role(m.role) }} | ||
{{ m.message }} | ||
{% endfor %} | ||
"# | ||
} |
Oops, something went wrong.