Concurrent function calls

We’ll use function ClassifyMessage(input: string) -> Category for our example:

1enum Category {
2 Refund
3 CancelOrder
4 TechnicalSupport
5 AccountIssue
6 Question
7}
8
9function ClassifyMessage(input: string) -> Category {
10 client GPT4o
11 prompt #"
12 Classify the following INPUT into ONE
13 of the following categories:
14
15 INPUT: {{ input }}
16
17 {{ ctx.output_format }}
18
19 Response:
20 "#
21}

You can make concurrent b.ClassifyMessage() calls like so:

main.py
1import asyncio
2
3from baml_client.async_client import b
4from baml_client.types import Category
5
6async def main():
7 await asyncio.gather(
8 b.ClassifyMessage("I want to cancel my order"),
9 b.ClassifyMessage("I want a refund")
10 )
11
12if __name__ == '__main__':
13 asyncio.run(main())
Built with