Skip to content

Commit 77acdcc

Browse files
committed
update to latest versions
1 parent 7c33542 commit 77acdcc

Some content is hidden

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

43 files changed

+902
-1397
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ This repository contains BAML example code used in the Documentation [Tutorials]
55
Clone the repo to see syntax highlights using the BAML VSCode extension!
66

77
### Requirements
8+
89
1. BAML CLI, BAML VSCode extension
9-
1. This repository uses ⚠️⚠️⚠️ Poetry ⚠️⚠️⚠️ as the python environment manager.
10-
2. Python >=3.9 (Contact us if you have an older version).
10+
2. This repository uses ⚠️⚠️⚠️ Poetry ⚠️⚠️⚠️ as the python environment manager. If you want to use Conda, pip or another dependency mgmt, run `baml init` to get yourself setup properly.
11+
3. Python >=3.9 (Contact us if you have an older version).
1112

1213
**Contact us on Discord if you need help running the examples using Conda, pip or another dependency mgmt**.
1314

1415
### Setup
16+
17+
Note: You can always just copy the `.baml` files you want into your own project that you have initialized with `baml init`.
18+
1519
1. Clone the repo
1620
2. Install [poetry](https://python-poetry.org/docs/)
1721
3. Run `poetry shell` in the root
@@ -23,8 +27,9 @@ Clone the repo to see syntax highlights using the BAML VSCode extension!
2327
If you're having issues, reach out to us on Discord (https://discord.gg/yzaTpQ3tdT).
2428

2529
Some common steps that help fix things:
30+
2631
1. Make sure you also add `baml` pip package to the project dependencies if you are not using poetry (see pyproject.toml for dependency list).
2732
1. Make sure you're in a poetry shell when you run the python main.py files.
28-
2. Make sure environment variables are set (some baml files use an env.OPEN_AI_KEY). Add a .env file to the root dir, with the key set to fix this.
29-
3. Restart VScode if the playground isn't working
30-
4. Restart VSCode if you're not getting error highlights for baml-generated code, or ensure the right Python interpreter is set (Command + Shift + P -> Select interpreter)
33+
1. Make sure environment variables are set (some baml files use an env.OPEN_AI_KEY). Add a .env file to the root dir with the appropriate api key set to fix this.
34+
1. Restart VScode if the playground isn't working
35+
1. Restart VSCode if you're not getting error highlights for baml-generated code, or ensure the right Python interpreter is set (Command + Shift + P -> Select interpreter)

chatbot/baml_client/__do_not_import/functions/fx_classifyintent.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
# fmt: off
99

1010
from ..types.enums.enm_intent import Intent
11+
from baml_core.stream import AsyncStream
1112
from baml_lib._impl.functions import BaseBAMLFunction
12-
from typing import List, Protocol, runtime_checkable
13+
from typing import AsyncIterator, Callable, List, Protocol, runtime_checkable
1314

1415

1516
IClassifyIntentOutput = List[Intent]
@@ -29,8 +30,24 @@ class IClassifyIntent(Protocol):
2930
async def __call__(self, *, query: str) -> List[Intent]:
3031
...
3132

33+
3234

33-
class IBAMLClassifyIntent(BaseBAMLFunction[List[Intent]]):
35+
@runtime_checkable
36+
class IClassifyIntentStream(Protocol):
37+
"""
38+
This is the interface for a stream function.
39+
40+
Args:
41+
query: str
42+
43+
Returns:
44+
AsyncStream[List[Intent], List[Intent]]
45+
"""
46+
47+
def __call__(self, *, query: str
48+
) -> AsyncStream[List[Intent], List[Intent]]:
49+
...
50+
class IBAMLClassifyIntent(BaseBAMLFunction[List[Intent], List[Intent]]):
3451
def __init__(self) -> None:
3552
super().__init__(
3653
"ClassifyIntent",
@@ -40,6 +57,10 @@ def __init__(self) -> None:
4057

4158
async def __call__(self, *args, **kwargs) -> List[Intent]:
4259
return await self.get_impl("simple").run(*args, **kwargs)
60+
61+
def stream(self, *args, **kwargs) -> AsyncStream[List[Intent], List[Intent]]:
62+
res = self.get_impl("simple").stream(*args, **kwargs)
63+
return res
4364

4465
BAMLClassifyIntent = IBAMLClassifyIntent()
4566

chatbot/baml_client/__do_not_import/functions/fx_classifyintent.pyi

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
# fmt: off
99

1010
from ..types.enums.enm_intent import Intent
11-
from typing import List, Protocol, runtime_checkable
11+
from baml_core.stream import AsyncStream
12+
from typing import Callable, List, Protocol, runtime_checkable
1213

1314

1415
import typing
@@ -40,20 +41,44 @@ class IClassifyIntent(Protocol):
4041
async def __call__(self, *, query: str) -> List[Intent]:
4142
...
4243

44+
4345

46+
@runtime_checkable
47+
class IClassifyIntentStream(Protocol):
48+
"""
49+
This is the interface for a stream function.
50+
51+
Args:
52+
query: str
53+
54+
Returns:
55+
AsyncStream[List[Intent], List[Intent]]
56+
"""
57+
58+
def __call__(self, *, query: str
59+
) -> AsyncStream[List[Intent], List[Intent]]:
60+
...
4461
class BAMLClassifyIntentImpl:
4562
async def run(self, *, query: str) -> List[Intent]:
4663
...
64+
65+
def stream(self, *, query: str
66+
) -> AsyncStream[List[Intent], List[Intent]]:
67+
...
4768

4869
class IBAMLClassifyIntent:
4970
def register_impl(
5071
self, name: ImplName
51-
) -> typing.Callable[[IClassifyIntent], IClassifyIntent]:
72+
) -> typing.Callable[[IClassifyIntent, IClassifyIntentStream], None]:
5273
...
5374

5475
async def __call__(self, *, query: str) -> List[Intent]:
5576
...
5677

78+
def stream(self, *, query: str
79+
) -> AsyncStream[List[Intent], List[Intent]]:
80+
...
81+
5782
def get_impl(self, name: ImplName) -> BAMLClassifyIntentImpl:
5883
...
5984

@@ -97,23 +122,34 @@ class IBAMLClassifyIntent:
97122
...
98123

99124
@typing.overload
100-
def test(self, *, exclude_impl: typing.Iterable[ImplName]) -> pytest.MarkDecorator:
125+
def test(self, *, exclude_impl: typing.Iterable[ImplName] = [], stream: bool = False) -> pytest.MarkDecorator:
101126
"""
102127
Provides a pytest.mark.parametrize decorator to facilitate testing different implementations of
103128
the ClassifyIntentInterface.
104129
105130
Args:
106131
exclude_impl : Iterable[ImplName]
107132
The names of the implementations to exclude from testing.
133+
stream: bool
134+
If set, will return a streamable version of the test function.
108135
109136
Usage:
110137
```python
111-
# All implementations except "simple" will be tested.
138+
# All implementations except the given impl will be tested.
112139
113-
@baml.ClassifyIntent.test(exclude_impl=["simple"])
140+
@baml.ClassifyIntent.test(exclude_impl=["implname"])
114141
async def test_logic(ClassifyIntentImpl: IClassifyIntent) -> None:
115142
result = await ClassifyIntentImpl(...)
116143
```
144+
145+
```python
146+
# Streamable version of the test function.
147+
148+
@baml.ClassifyIntent.test(stream=True)
149+
async def test_logic(ClassifyIntentImpl: IClassifyIntentStream) -> None:
150+
async for result in ClassifyIntentImpl(...):
151+
...
152+
```
117153
"""
118154
...
119155

chatbot/baml_client/__do_not_import/functions/fx_extractmeetingrequestinfo.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
from ..types.classes.cls_meetingrequest import MeetingRequest
1313
from ..types.classes.cls_message import Message
1414
from ..types.enums.enm_usertype import UserType
15+
from ..types.partial.classes.cls_attendee import PartialAttendee
16+
from ..types.partial.classes.cls_conversation import PartialConversation
17+
from ..types.partial.classes.cls_meetingrequest import PartialMeetingRequest
18+
from ..types.partial.classes.cls_message import PartialMessage
19+
from baml_core.stream import AsyncStream
1520
from baml_lib._impl.functions import BaseBAMLFunction
16-
from typing import Protocol, runtime_checkable
21+
from typing import AsyncIterator, Callable, Protocol, runtime_checkable
1722

1823

1924
IExtractMeetingRequestInfoOutput = MeetingRequest
@@ -34,8 +39,25 @@ class IExtractMeetingRequestInfo(Protocol):
3439
async def __call__(self, *, convo: Conversation, now: str) -> MeetingRequest:
3540
...
3641

42+
3743

38-
class IBAMLExtractMeetingRequestInfo(BaseBAMLFunction[MeetingRequest]):
44+
@runtime_checkable
45+
class IExtractMeetingRequestInfoStream(Protocol):
46+
"""
47+
This is the interface for a stream function.
48+
49+
Args:
50+
convo: Conversation
51+
now: str
52+
53+
Returns:
54+
AsyncStream[MeetingRequest, PartialMeetingRequest]
55+
"""
56+
57+
def __call__(self, *, convo: Conversation, now: str
58+
) -> AsyncStream[MeetingRequest, PartialMeetingRequest]:
59+
...
60+
class IBAMLExtractMeetingRequestInfo(BaseBAMLFunction[MeetingRequest, PartialMeetingRequest]):
3961
def __init__(self) -> None:
4062
super().__init__(
4163
"ExtractMeetingRequestInfo",
@@ -45,6 +67,10 @@ def __init__(self) -> None:
4567

4668
async def __call__(self, *args, **kwargs) -> MeetingRequest:
4769
return await self.get_impl("simple").run(*args, **kwargs)
70+
71+
def stream(self, *args, **kwargs) -> AsyncStream[MeetingRequest, PartialMeetingRequest]:
72+
res = self.get_impl("simple").stream(*args, **kwargs)
73+
return res
4874

4975
BAMLExtractMeetingRequestInfo = IBAMLExtractMeetingRequestInfo()
5076

chatbot/baml_client/__do_not_import/functions/fx_extractmeetingrequestinfo.pyi

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ from ..types.classes.cls_conversation import Conversation
1212
from ..types.classes.cls_meetingrequest import MeetingRequest
1313
from ..types.classes.cls_message import Message
1414
from ..types.enums.enm_usertype import UserType
15-
from typing import Protocol, runtime_checkable
15+
from ..types.partial.classes.cls_attendee import PartialAttendee
16+
from ..types.partial.classes.cls_conversation import PartialConversation
17+
from ..types.partial.classes.cls_meetingrequest import PartialMeetingRequest
18+
from ..types.partial.classes.cls_message import PartialMessage
19+
from baml_core.stream import AsyncStream
20+
from typing import Callable, Protocol, runtime_checkable
1621

1722

1823
import typing
@@ -45,20 +50,45 @@ class IExtractMeetingRequestInfo(Protocol):
4550
async def __call__(self, *, convo: Conversation, now: str) -> MeetingRequest:
4651
...
4752

53+
4854

55+
@runtime_checkable
56+
class IExtractMeetingRequestInfoStream(Protocol):
57+
"""
58+
This is the interface for a stream function.
59+
60+
Args:
61+
convo: Conversation
62+
now: str
63+
64+
Returns:
65+
AsyncStream[MeetingRequest, PartialMeetingRequest]
66+
"""
67+
68+
def __call__(self, *, convo: Conversation, now: str
69+
) -> AsyncStream[MeetingRequest, PartialMeetingRequest]:
70+
...
4971
class BAMLExtractMeetingRequestInfoImpl:
5072
async def run(self, *, convo: Conversation, now: str) -> MeetingRequest:
5173
...
74+
75+
def stream(self, *, convo: Conversation, now: str
76+
) -> AsyncStream[MeetingRequest, PartialMeetingRequest]:
77+
...
5278

5379
class IBAMLExtractMeetingRequestInfo:
5480
def register_impl(
5581
self, name: ImplName
56-
) -> typing.Callable[[IExtractMeetingRequestInfo], IExtractMeetingRequestInfo]:
82+
) -> typing.Callable[[IExtractMeetingRequestInfo, IExtractMeetingRequestInfoStream], None]:
5783
...
5884

5985
async def __call__(self, *, convo: Conversation, now: str) -> MeetingRequest:
6086
...
6187

88+
def stream(self, *, convo: Conversation, now: str
89+
) -> AsyncStream[MeetingRequest, PartialMeetingRequest]:
90+
...
91+
6292
def get_impl(self, name: ImplName) -> BAMLExtractMeetingRequestInfoImpl:
6393
...
6494

@@ -102,23 +132,34 @@ class IBAMLExtractMeetingRequestInfo:
102132
...
103133

104134
@typing.overload
105-
def test(self, *, exclude_impl: typing.Iterable[ImplName]) -> pytest.MarkDecorator:
135+
def test(self, *, exclude_impl: typing.Iterable[ImplName] = [], stream: bool = False) -> pytest.MarkDecorator:
106136
"""
107137
Provides a pytest.mark.parametrize decorator to facilitate testing different implementations of
108138
the ExtractMeetingRequestInfoInterface.
109139
110140
Args:
111141
exclude_impl : Iterable[ImplName]
112142
The names of the implementations to exclude from testing.
143+
stream: bool
144+
If set, will return a streamable version of the test function.
113145
114146
Usage:
115147
```python
116-
# All implementations except "simple" will be tested.
148+
# All implementations except the given impl will be tested.
117149
118-
@baml.ExtractMeetingRequestInfo.test(exclude_impl=["simple"])
150+
@baml.ExtractMeetingRequestInfo.test(exclude_impl=["implname"])
119151
async def test_logic(ExtractMeetingRequestInfoImpl: IExtractMeetingRequestInfo) -> None:
120152
result = await ExtractMeetingRequestInfoImpl(...)
121153
```
154+
155+
```python
156+
# Streamable version of the test function.
157+
158+
@baml.ExtractMeetingRequestInfo.test(stream=True)
159+
async def test_logic(ExtractMeetingRequestInfoImpl: IExtractMeetingRequestInfoStream) -> None:
160+
async for result in ExtractMeetingRequestInfoImpl(...):
161+
...
162+
```
122163
"""
123164
...
124165

chatbot/baml_client/__do_not_import/functions/fx_extractmeetingrequestinfopartial.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
from ..types.classes.cls_meetingrequestpartial import MeetingRequestPartial
1212
from ..types.classes.cls_message import Message
1313
from ..types.enums.enm_usertype import UserType
14+
from ..types.partial.classes.cls_conversation import PartialConversation
15+
from ..types.partial.classes.cls_meetingrequestpartial import PartialMeetingRequestPartial
16+
from ..types.partial.classes.cls_message import PartialMessage
17+
from baml_core.stream import AsyncStream
1418
from baml_lib._impl.functions import BaseBAMLFunction
15-
from typing import Protocol, runtime_checkable
19+
from typing import AsyncIterator, Callable, Protocol, runtime_checkable
1620

1721

1822
IExtractMeetingRequestInfoPartialOutput = MeetingRequestPartial
@@ -33,8 +37,25 @@ class IExtractMeetingRequestInfoPartial(Protocol):
3337
async def __call__(self, *, convo: Conversation, now: str) -> MeetingRequestPartial:
3438
...
3539

40+
3641

37-
class IBAMLExtractMeetingRequestInfoPartial(BaseBAMLFunction[MeetingRequestPartial]):
42+
@runtime_checkable
43+
class IExtractMeetingRequestInfoPartialStream(Protocol):
44+
"""
45+
This is the interface for a stream function.
46+
47+
Args:
48+
convo: Conversation
49+
now: str
50+
51+
Returns:
52+
AsyncStream[MeetingRequestPartial, PartialMeetingRequestPartial]
53+
"""
54+
55+
def __call__(self, *, convo: Conversation, now: str
56+
) -> AsyncStream[MeetingRequestPartial, PartialMeetingRequestPartial]:
57+
...
58+
class IBAMLExtractMeetingRequestInfoPartial(BaseBAMLFunction[MeetingRequestPartial, PartialMeetingRequestPartial]):
3859
def __init__(self) -> None:
3960
super().__init__(
4061
"ExtractMeetingRequestInfoPartial",
@@ -44,6 +65,10 @@ def __init__(self) -> None:
4465

4566
async def __call__(self, *args, **kwargs) -> MeetingRequestPartial:
4667
return await self.get_impl("v1").run(*args, **kwargs)
68+
69+
def stream(self, *args, **kwargs) -> AsyncStream[MeetingRequestPartial, PartialMeetingRequestPartial]:
70+
res = self.get_impl("v1").stream(*args, **kwargs)
71+
return res
4772

4873
BAMLExtractMeetingRequestInfoPartial = IBAMLExtractMeetingRequestInfoPartial()
4974

0 commit comments

Comments
 (0)