1
+ ###############################################################################
2
+ #
3
+ # Welcome to Baml! To use this generated code, please run the following:
4
+ #
5
+ # $ pip install baml-py
6
+ #
7
+ ###############################################################################
8
+
9
+ # This file was generated by BAML: please do not edit it. Instead, edit the
10
+ # BAML files and re-generate this code.
11
+ #
12
+ # ruff: noqa: E501,F401
13
+ # flake8: noqa: E501,F401
14
+ # pylint: disable=unused-import,line-too-long
15
+ # fmt: off
16
+ from typing import Any , Dict , List , Optional , TypeVar , Union , TypedDict , Type , cast
17
+ from typing_extensions import NotRequired , Literal
18
+ import pprint
19
+
20
+ import baml_py
21
+ from pydantic import BaseModel , ValidationError , create_model
22
+
23
+ from . import partial_types , types
24
+ from .types import Checked , Check
25
+ from .type_builder import TypeBuilder
26
+ from .parser import LlmResponseParser , LlmStreamParser
27
+ from .async_request import AsyncHttpRequest , AsyncHttpStreamRequest
28
+ from .globals import DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX , DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME
29
+
30
+ OutputType = TypeVar ('OutputType' )
31
+
32
+
33
+ # Define the TypedDict with optional parameters having default values
34
+ class BamlCallOptions (TypedDict , total = False ):
35
+ tb : NotRequired [TypeBuilder ]
36
+ client_registry : NotRequired [baml_py .baml_py .ClientRegistry ]
37
+ collector : NotRequired [Union [baml_py .baml_py .Collector , List [baml_py .baml_py .Collector ]]]
38
+
39
+
40
+ class BamlAsyncClient :
41
+ __runtime : baml_py .BamlRuntime
42
+ __ctx_manager : baml_py .BamlCtxManager
43
+ __stream_client : "BamlStreamClient"
44
+ __http_request : "AsyncHttpRequest"
45
+ __http_stream_request : "AsyncHttpStreamRequest"
46
+ __llm_response_parser : LlmResponseParser
47
+ __llm_stream_parser : LlmStreamParser
48
+ __baml_options : BamlCallOptions
49
+
50
+ def __init__ (self , runtime : baml_py .BamlRuntime , ctx_manager : baml_py .BamlCtxManager , baml_options : Optional [BamlCallOptions ] = None ):
51
+ self .__runtime = runtime
52
+ self .__ctx_manager = ctx_manager
53
+ self .__stream_client = BamlStreamClient (self .__runtime , self .__ctx_manager , baml_options )
54
+ self .__http_request = AsyncHttpRequest (self .__runtime , self .__ctx_manager )
55
+ self .__http_stream_request = AsyncHttpStreamRequest (self .__runtime , self .__ctx_manager )
56
+ self .__llm_response_parser = LlmResponseParser (self .__runtime , self .__ctx_manager )
57
+ self .__llm_stream_parser = LlmStreamParser (self .__runtime , self .__ctx_manager )
58
+ self .__baml_options = baml_options or {}
59
+
60
+ def with_options (
61
+ self ,
62
+ tb : Optional [TypeBuilder ] = None ,
63
+ client_registry : Optional [baml_py .baml_py .ClientRegistry ] = None ,
64
+ collector : Optional [Union [baml_py .baml_py .Collector , List [baml_py .baml_py .Collector ]]] = None ,
65
+ ) -> "BamlAsyncClient" :
66
+ """
67
+ Returns a new instance of BamlAsyncClient with explicitly typed baml options
68
+ for Python 3.8 compatibility.
69
+ """
70
+ new_options = self .__baml_options .copy ()
71
+
72
+ # Override if any keyword arguments were provided.
73
+ if tb is not None :
74
+ new_options ["tb" ] = tb
75
+ if client_registry is not None :
76
+ new_options ["client_registry" ] = client_registry
77
+ if collector is not None :
78
+ new_options ["collector" ] = collector
79
+
80
+ return BamlAsyncClient (self .__runtime , self .__ctx_manager , new_options )
81
+
82
+ @property
83
+ def stream (self ):
84
+ return self .__stream_client
85
+
86
+ @property
87
+ def request (self ):
88
+ return self .__http_request
89
+
90
+ @property
91
+ def stream_request (self ):
92
+ return self .__http_stream_request
93
+
94
+ @property
95
+ def parse (self ):
96
+ return self .__llm_response_parser
97
+
98
+ @property
99
+ def parse_stream (self ):
100
+ return self .__llm_stream_parser
101
+
102
+
103
+ async def ExtractKeywords (
104
+ self ,
105
+ taskDescription : str ,
106
+ baml_options : BamlCallOptions = {},
107
+ ) -> types .KeywordPhrase :
108
+ options : BamlCallOptions = {** self .__baml_options , ** (baml_options or {})}
109
+
110
+ __tb__ = options .get ("tb" , None )
111
+ if __tb__ is not None :
112
+ tb = __tb__ ._tb # type: ignore (we know how to use this private attribute)
113
+ else :
114
+ tb = None
115
+ __cr__ = options .get ("client_registry" , None )
116
+ collector = options .get ("collector" , None )
117
+ collectors = collector if isinstance (collector , list ) else [collector ] if collector is not None else []
118
+ raw = await self .__runtime .call_function (
119
+ "ExtractKeywords" ,
120
+ {
121
+ "taskDescription" : taskDescription ,
122
+ },
123
+ self .__ctx_manager .get (),
124
+ tb ,
125
+ __cr__ ,
126
+ collectors ,
127
+ )
128
+ return cast (types .KeywordPhrase , raw .cast_to (types , types , partial_types , False ))
129
+
130
+
131
+
132
+ class BamlStreamClient :
133
+ __runtime : baml_py .BamlRuntime
134
+ __ctx_manager : baml_py .BamlCtxManager
135
+ __baml_options : BamlCallOptions
136
+ def __init__ (self , runtime : baml_py .BamlRuntime , ctx_manager : baml_py .BamlCtxManager , baml_options : Optional [BamlCallOptions ] = None ):
137
+ self .__runtime = runtime
138
+ self .__ctx_manager = ctx_manager
139
+ self .__baml_options = baml_options or {}
140
+
141
+
142
+ def ExtractKeywords (
143
+ self ,
144
+ taskDescription : str ,
145
+ baml_options : BamlCallOptions = {},
146
+ ) -> baml_py .BamlStream [partial_types .KeywordPhrase , types .KeywordPhrase ]:
147
+ options : BamlCallOptions = {** self .__baml_options , ** (baml_options or {})}
148
+ __tb__ = options .get ("tb" , None )
149
+ if __tb__ is not None :
150
+ tb = __tb__ ._tb # type: ignore (we know how to use this private attribute)
151
+ else :
152
+ tb = None
153
+ __cr__ = options .get ("client_registry" , None )
154
+ collector = options .get ("collector" , None )
155
+ collectors = collector if isinstance (collector , list ) else [collector ] if collector is not None else []
156
+ raw = self .__runtime .stream_function (
157
+ "ExtractKeywords" ,
158
+ {
159
+ "taskDescription" : taskDescription ,
160
+ },
161
+ None ,
162
+ self .__ctx_manager .get (),
163
+ tb ,
164
+ __cr__ ,
165
+ collectors ,
166
+ )
167
+
168
+ return baml_py .BamlStream [partial_types .KeywordPhrase , types .KeywordPhrase ](
169
+ raw ,
170
+ lambda x : cast (partial_types .KeywordPhrase , x .cast_to (types , types , partial_types , True )),
171
+ lambda x : cast (types .KeywordPhrase , x .cast_to (types , types , partial_types , False )),
172
+ self .__ctx_manager .get (),
173
+ )
174
+
175
+
176
+
177
+ b = BamlAsyncClient (DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME , DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX )
178
+
179
+ __all__ = ["b" ]
0 commit comments