Skip to content

Commit ffe81a3

Browse files
authored
[bug] Plumb type-builder to streaming during tests (#1660)
Type builder wasn't pushed down to streaming which caused deserialization errors. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Fixes deserialization errors by ensuring type builder is passed to streaming in `BamlRuntime`, adds `ExtractEntitiesTest`, and updates `Ollama` client model. > > - **Behavior**: > - Fixes deserialization errors by ensuring type builder is passed to streaming in `BamlRuntime` in `lib.rs`. > - Updates `stream.run()` call to include `type_builder`. > - **Tests**: > - Adds `ExtractEntitiesTest` in `dynamic_tests.baml` to verify type builder integration. > - Introduces `DynamicSchema` class for testing purposes. > - **Models**: > - Updates `Ollama` client model from `llama2` to `llama3.1` in `clients.baml`. > > <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 e5999eb. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent a760f84 commit ffe81a3

42 files changed

Lines changed: 1165 additions & 28 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

engine/baml-runtime/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,18 @@ impl BamlRuntime {
293293
ctx.create_ctx(type_builder.as_ref(), None, span.clone().map(|s| s.span_id))?;
294294
let (params, constraints) =
295295
self.get_test_params_and_constraints(function_name, test_name, &rctx, true)?;
296-
let rctx_stream =
297-
ctx.create_ctx(type_builder.as_ref(), None, span.clone().map(|s| s.span_id))?;
298296
let mut stream = self.inner.stream_function_impl(
299297
function_name.into(),
300298
&params,
301299
self.tracer.clone(),
302-
rctx_stream,
300+
rctx,
303301
#[cfg(not(target_arch = "wasm32"))]
304302
self.async_runtime.clone(),
305303
// TODO: collectors here?
306304
vec![],
307305
)?;
308-
let (response_res, span_uuid) = stream.run(on_event, ctx, None, None).await;
306+
let (response_res, span_uuid) =
307+
stream.run(on_event, ctx, type_builder.as_ref(), None).await;
309308
let res = response_res?;
310309
let (_, llm_resp, val) = res
311310
.event_chain()

integ-tests/baml_src/clients.baml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ client<llm> GPT35LegacyProvider {
6868
client<llm> Ollama {
6969
provider ollama
7070
options {
71-
model llama2
71+
model llama3.1
7272
}
7373
}
7474

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class DynamicSchema {
2+
@@dynamic
3+
}
4+
5+
function ExtractEntities(text: string) -> DynamicSchema {
6+
client Ollama
7+
prompt #"
8+
Parse the following text and return a structured representation of the data in the schema below.
9+
10+
text:
11+
---
12+
{{text}}
13+
---
14+
15+
{{ ctx.output_format }}
16+
"#
17+
}
18+
19+
20+
test ExtractEntitiesTest {
21+
functions [ExtractEntities]
22+
23+
type_builder {
24+
enum Gender {
25+
MALE
26+
FEMALE
27+
OTHER
28+
}
29+
enum PreferredContactInfo{
30+
EMAIL
31+
PHONE
32+
}
33+
class PersonalInfo{
34+
35+
first_name string?
36+
last_name string?
37+
gender Gender?
38+
39+
}
40+
class ContactInfo2 {
41+
email string? @description(#"The customer's email address"#)
42+
phone string? @description(#"The customer's phone number"#)
43+
preferred_contact_method PreferredContactInfo? @description(#"The customer's preferred method of contact"#)
44+
45+
}
46+
dynamic class DynamicSchema {
47+
personal_info PersonalInfo
48+
contact_info ContactInfo2
49+
}
50+
}
51+
52+
args {
53+
"text" "Agent: Good morning! Thank you for reaching out. I’ll need to collect some basic details to assist you better. Could you please provide your first and last name? Customer: Sure! My name is John Doe. Agent: Thank you, John. May I also ask for your gender? Customer: I'd prefer not to share that at the moment. Agent: No problem at all. Now, for contact purposes, could you share your email address? Customer: Yes, my email is johndo@example.com. Agent: Great! Do you have a phone number where we can reach you? Customer: I’d rather not provide that right now. Agent: That’s completely fine. How would you prefer us to contact you—by email or phone? Customer: Please contact me via Email. Agent: Understood! Lastly, can you share the reason for your call today? Customer: I’m not ready to specify that just yet. Agent: That’s okay, John! I’ve noted everything down. If you need any further assistance, feel free to reach out. Have a great day!"
54+
}
55+
56+
57+
}

integ-tests/openapi/baml_client/openapi.yaml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integ-tests/python/baml_client/async_client.py

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integ-tests/python/baml_client/async_request.py

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integ-tests/python/baml_client/inlinedbaml.py

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integ-tests/python/baml_client/parser.py

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integ-tests/python/baml_client/partial_types.py

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)