python-fastllm 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fastllm/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
fastllm/_modidx.py ADDED
@@ -0,0 +1,245 @@
1
+ # Autogenerated by nbdev
2
+
3
+ d = { 'settings': { 'branch': 'main',
4
+ 'doc_baseurl': '/',
5
+ 'doc_host': '',
6
+ 'git_url': 'https://github.com/AnswerDotAI/fastllm',
7
+ 'lib_path': 'fastllm'},
8
+ 'syms': { 'fastllm.acomplete': { 'fastllm.acomplete.ContextWindowExceededError': ( 'acomplete.html#contextwindowexceedederror',
9
+ 'fastllm/acomplete.py'),
10
+ 'fastllm.acomplete._classify_error': ('acomplete.html#_classify_error', 'fastllm/acomplete.py'),
11
+ 'fastllm.acomplete._classify_error_stream': ( 'acomplete.html#_classify_error_stream',
12
+ 'fastllm/acomplete.py'),
13
+ 'fastllm.acomplete._is_ctx_exceeded': ('acomplete.html#_is_ctx_exceeded', 'fastllm/acomplete.py'),
14
+ 'fastllm.acomplete.acomplete': ('acomplete.html#acomplete', 'fastllm/acomplete.py'),
15
+ 'fastllm.acomplete.mk_client': ('acomplete.html#mk_client', 'fastllm/acomplete.py')},
16
+ 'fastllm.anthropic': { 'fastllm.anthropic._ant_cc': ('anthropic.html#_ant_cc', 'fastllm/anthropic.py'),
17
+ 'fastllm.anthropic._ant_part_type': ('anthropic.html#_ant_part_type', 'fastllm/anthropic.py'),
18
+ 'fastllm.anthropic.acollect_stream': ('anthropic.html#acollect_stream', 'fastllm/anthropic.py'),
19
+ 'fastllm.anthropic.cost': ('anthropic.html#cost', 'fastllm/anthropic.py'),
20
+ 'fastllm.anthropic.delta_index_fn': ('anthropic.html#delta_index_fn', 'fastllm/anthropic.py'),
21
+ 'fastllm.anthropic.denorm_assistant': ('anthropic.html#denorm_assistant', 'fastllm/anthropic.py'),
22
+ 'fastllm.anthropic.denorm_file': ('anthropic.html#denorm_file', 'fastllm/anthropic.py'),
23
+ 'fastllm.anthropic.denorm_image': ('anthropic.html#denorm_image', 'fastllm/anthropic.py'),
24
+ 'fastllm.anthropic.denorm_msgs': ('anthropic.html#denorm_msgs', 'fastllm/anthropic.py'),
25
+ 'fastllm.anthropic.denorm_reasoning': ('anthropic.html#denorm_reasoning', 'fastllm/anthropic.py'),
26
+ 'fastllm.anthropic.denorm_system': ('anthropic.html#denorm_system', 'fastllm/anthropic.py'),
27
+ 'fastllm.anthropic.denorm_tool': ('anthropic.html#denorm_tool', 'fastllm/anthropic.py'),
28
+ 'fastllm.anthropic.denorm_tool_choice': ('anthropic.html#denorm_tool_choice', 'fastllm/anthropic.py'),
29
+ 'fastllm.anthropic.denorm_tool_result': ('anthropic.html#denorm_tool_result', 'fastllm/anthropic.py'),
30
+ 'fastllm.anthropic.denorm_tool_schs': ('anthropic.html#denorm_tool_schs', 'fastllm/anthropic.py'),
31
+ 'fastllm.anthropic.denorm_tool_use': ('anthropic.html#denorm_tool_use', 'fastllm/anthropic.py'),
32
+ 'fastllm.anthropic.denorm_user': ('anthropic.html#denorm_user', 'fastllm/anthropic.py'),
33
+ 'fastllm.anthropic.denorm_web_search': ('anthropic.html#denorm_web_search', 'fastllm/anthropic.py'),
34
+ 'fastllm.anthropic.get_hdrs': ('anthropic.html#get_hdrs', 'fastllm/anthropic.py'),
35
+ 'fastllm.anthropic.mk_payload': ('anthropic.html#mk_payload', 'fastllm/anthropic.py'),
36
+ 'fastllm.anthropic.norm_finish': ('anthropic.html#norm_finish', 'fastllm/anthropic.py'),
37
+ 'fastllm.anthropic.norm_parts': ('anthropic.html#norm_parts', 'fastllm/anthropic.py'),
38
+ 'fastllm.anthropic.norm_sse_event': ('anthropic.html#norm_sse_event', 'fastllm/anthropic.py'),
39
+ 'fastllm.anthropic.norm_tool_call': ('anthropic.html#norm_tool_call', 'fastllm/anthropic.py'),
40
+ 'fastllm.anthropic.norm_tool_calls': ('anthropic.html#norm_tool_calls', 'fastllm/anthropic.py'),
41
+ 'fastllm.anthropic.norm_usage': ('anthropic.html#norm_usage', 'fastllm/anthropic.py')},
42
+ 'fastllm.chat': { 'fastllm.chat.AsyncChat': ('chat.html#asyncchat', 'fastllm/chat.py'),
43
+ 'fastllm.chat.AsyncChat.__call__': ('chat.html#asyncchat.__call__', 'fastllm/chat.py'),
44
+ 'fastllm.chat.AsyncChat.__init__': ('chat.html#asyncchat.__init__', 'fastllm/chat.py'),
45
+ 'fastllm.chat.AsyncChat._call': ('chat.html#asyncchat._call', 'fastllm/chat.py'),
46
+ 'fastllm.chat.AsyncChat._prep_call': ('chat.html#asyncchat._prep_call', 'fastllm/chat.py'),
47
+ 'fastllm.chat.AsyncChat._prep_msg': ('chat.html#asyncchat._prep_msg', 'fastllm/chat.py'),
48
+ 'fastllm.chat.AsyncChat._track': ('chat.html#asyncchat._track', 'fastllm/chat.py'),
49
+ 'fastllm.chat.AsyncChat.print_hist': ('chat.html#asyncchat.print_hist', 'fastllm/chat.py'),
50
+ 'fastllm.chat.AsyncChat.tcdict': ('chat.html#asyncchat.tcdict', 'fastllm/chat.py'),
51
+ 'fastllm.chat.AsyncStreamFormatter': ('chat.html#asyncstreamformatter', 'fastllm/chat.py'),
52
+ 'fastllm.chat.AsyncStreamFormatter.format_stream': ( 'chat.html#asyncstreamformatter.format_stream',
53
+ 'fastllm/chat.py'),
54
+ 'fastllm.chat.FullResponse': ('chat.html#fullresponse', 'fastllm/chat.py'),
55
+ 'fastllm.chat.StopResponse': ('chat.html#stopresponse', 'fastllm/chat.py'),
56
+ 'fastllm.chat.StreamFormatter': ('chat.html#streamformatter', 'fastllm/chat.py'),
57
+ 'fastllm.chat.StreamFormatter.__init__': ('chat.html#streamformatter.__init__', 'fastllm/chat.py'),
58
+ 'fastllm.chat.StreamFormatter.format_item': ('chat.html#streamformatter.format_item', 'fastllm/chat.py'),
59
+ 'fastllm.chat.StreamFormatter.format_stream': ('chat.html#streamformatter.format_stream', 'fastllm/chat.py'),
60
+ 'fastllm.chat.ToolResponse': ('chat.html#toolresponse', 'fastllm/chat.py'),
61
+ 'fastllm.chat.UsageStats': ('chat.html#usagestats', 'fastllm/chat.py'),
62
+ 'fastllm.chat.UsageStats.__add__': ('chat.html#usagestats.__add__', 'fastllm/chat.py'),
63
+ 'fastllm.chat.UsageStats.__init__': ('chat.html#usagestats.__init__', 'fastllm/chat.py'),
64
+ 'fastllm.chat.UsageStats.__radd__': ('chat.html#usagestats.__radd__', 'fastllm/chat.py'),
65
+ 'fastllm.chat.UsageStats.__repr__': ('chat.html#usagestats.__repr__', 'fastllm/chat.py'),
66
+ 'fastllm.chat.UsageStats.fmt': ('chat.html#usagestats.fmt', 'fastllm/chat.py'),
67
+ 'fastllm.chat.UsageStats.from_response': ('chat.html#usagestats.from_response', 'fastllm/chat.py'),
68
+ 'fastllm.chat._add_cache_control': ('chat.html#_add_cache_control', 'fastllm/chat.py'),
69
+ 'fastllm.chat._alite_call_func': ('chat.html#_alite_call_func', 'fastllm/chat.py'),
70
+ 'fastllm.chat._apply_cache_idxs': ('chat.html#_apply_cache_idxs', 'fastllm/chat.py'),
71
+ 'fastllm.chat._bytes2content': ('chat.html#_bytes2content', 'fastllm/chat.py'),
72
+ 'fastllm.chat._call_func': ('chat.html#_call_func', 'fastllm/chat.py'),
73
+ 'fastllm.chat._extract_tool_parts': ('chat.html#_extract_tool_parts', 'fastllm/chat.py'),
74
+ 'fastllm.chat._handle_stop_reason': ('chat.html#_handle_stop_reason', 'fastllm/chat.py'),
75
+ 'fastllm.chat._has_cache': ('chat.html#_has_cache', 'fastllm/chat.py'),
76
+ 'fastllm.chat._has_search': ('chat.html#_has_search', 'fastllm/chat.py'),
77
+ 'fastllm.chat._has_stop': ('chat.html#_has_stop', 'fastllm/chat.py'),
78
+ 'fastllm.chat._inject_tool_reminder': ('chat.html#_inject_tool_reminder', 'fastllm/chat.py'),
79
+ 'fastllm.chat._lite_call_func': ('chat.html#_lite_call_func', 'fastllm/chat.py'),
80
+ 'fastllm.chat._mk_content': ('chat.html#_mk_content', 'fastllm/chat.py'),
81
+ 'fastllm.chat._mk_prefill': ('chat.html#_mk_prefill', 'fastllm/chat.py'),
82
+ 'fastllm.chat._mk_tool_result': ('chat.html#_mk_tool_result', 'fastllm/chat.py'),
83
+ 'fastllm.chat._srv_tc_summary': ('chat.html#_srv_tc_summary', 'fastllm/chat.py'),
84
+ 'fastllm.chat._srvtools': ('chat.html#_srvtools', 'fastllm/chat.py'),
85
+ 'fastllm.chat._tc_summary': ('chat.html#_tc_summary', 'fastllm/chat.py'),
86
+ 'fastllm.chat._think_kw': ('chat.html#_think_kw', 'fastllm/chat.py'),
87
+ 'fastllm.chat._trunc_content': ('chat.html#_trunc_content', 'fastllm/chat.py'),
88
+ 'fastllm.chat._trunc_param': ('chat.html#_trunc_param', 'fastllm/chat.py'),
89
+ 'fastllm.chat._trunc_str': ('chat.html#_trunc_str', 'fastllm/chat.py'),
90
+ 'fastllm.chat._usrtools': ('chat.html#_usrtools', 'fastllm/chat.py'),
91
+ 'fastllm.chat.add_warning': ('chat.html#add_warning', 'fastllm/chat.py'),
92
+ 'fastllm.chat.adisplay_stream': ('chat.html#adisplay_stream', 'fastllm/chat.py'),
93
+ 'fastllm.chat.astream_with_complete': ('chat.html#astream_with_complete', 'fastllm/chat.py'),
94
+ 'fastllm.chat.cite_footnote': ('chat.html#cite_footnote', 'fastllm/chat.py'),
95
+ 'fastllm.chat.contents': ('chat.html#contents', 'fastllm/chat.py'),
96
+ 'fastllm.chat.fmt2hist': ('chat.html#fmt2hist', 'fastllm/chat.py'),
97
+ 'fastllm.chat.lite_mk_func': ('chat.html#lite_mk_func', 'fastllm/chat.py'),
98
+ 'fastllm.chat.mk_msg': ('chat.html#mk_msg', 'fastllm/chat.py'),
99
+ 'fastllm.chat.mk_msgs': ('chat.html#mk_msgs', 'fastllm/chat.py'),
100
+ 'fastllm.chat.mk_srv_tc_details': ('chat.html#mk_srv_tc_details', 'fastllm/chat.py'),
101
+ 'fastllm.chat.mk_tr_details': ('chat.html#mk_tr_details', 'fastllm/chat.py'),
102
+ 'fastllm.chat.postproc': ('chat.html#postproc', 'fastllm/chat.py'),
103
+ 'fastllm.chat.remove_cache_ckpts': ('chat.html#remove_cache_ckpts', 'fastllm/chat.py'),
104
+ 'fastllm.chat.search_count': ('chat.html#search_count', 'fastllm/chat.py'),
105
+ 'fastllm.chat.split_tools': ('chat.html#split_tools', 'fastllm/chat.py'),
106
+ 'fastllm.chat.stop_reason': ('chat.html#stop_reason', 'fastllm/chat.py'),
107
+ 'fastllm.chat.structured': ('chat.html#structured', 'fastllm/chat.py')},
108
+ 'fastllm.gemini': { 'fastllm.gemini._gem_filter_sch': ('gemini.html#_gem_filter_sch', 'fastllm/gemini.py'),
109
+ 'fastllm.gemini._gem_part_type': ('gemini.html#_gem_part_type', 'fastllm/gemini.py'),
110
+ 'fastllm.gemini.acollect_stream': ('gemini.html#acollect_stream', 'fastllm/gemini.py'),
111
+ 'fastllm.gemini.cost': ('gemini.html#cost', 'fastllm/gemini.py'),
112
+ 'fastllm.gemini.delta_index_fn': ('gemini.html#delta_index_fn', 'fastllm/gemini.py'),
113
+ 'fastllm.gemini.denorm_assistant': ('gemini.html#denorm_assistant', 'fastllm/gemini.py'),
114
+ 'fastllm.gemini.denorm_audio': ('gemini.html#denorm_audio', 'fastllm/gemini.py'),
115
+ 'fastllm.gemini.denorm_file': ('gemini.html#denorm_file', 'fastllm/gemini.py'),
116
+ 'fastllm.gemini.denorm_image': ('gemini.html#denorm_image', 'fastllm/gemini.py'),
117
+ 'fastllm.gemini.denorm_msgs': ('gemini.html#denorm_msgs', 'fastllm/gemini.py'),
118
+ 'fastllm.gemini.denorm_reasoning': ('gemini.html#denorm_reasoning', 'fastllm/gemini.py'),
119
+ 'fastllm.gemini.denorm_system': ('gemini.html#denorm_system', 'fastllm/gemini.py'),
120
+ 'fastllm.gemini.denorm_tool': ('gemini.html#denorm_tool', 'fastllm/gemini.py'),
121
+ 'fastllm.gemini.denorm_tool_choice': ('gemini.html#denorm_tool_choice', 'fastllm/gemini.py'),
122
+ 'fastllm.gemini.denorm_tool_result': ('gemini.html#denorm_tool_result', 'fastllm/gemini.py'),
123
+ 'fastllm.gemini.denorm_tool_schs': ('gemini.html#denorm_tool_schs', 'fastllm/gemini.py'),
124
+ 'fastllm.gemini.denorm_tool_use': ('gemini.html#denorm_tool_use', 'fastllm/gemini.py'),
125
+ 'fastllm.gemini.denorm_user': ('gemini.html#denorm_user', 'fastllm/gemini.py'),
126
+ 'fastllm.gemini.denorm_video': ('gemini.html#denorm_video', 'fastllm/gemini.py'),
127
+ 'fastllm.gemini.denorm_web_search': ('gemini.html#denorm_web_search', 'fastllm/gemini.py'),
128
+ 'fastllm.gemini.get_hdrs': ('gemini.html#get_hdrs', 'fastllm/gemini.py'),
129
+ 'fastllm.gemini.mk_payload': ('gemini.html#mk_payload', 'fastllm/gemini.py'),
130
+ 'fastllm.gemini.norm_finish': ('gemini.html#norm_finish', 'fastllm/gemini.py'),
131
+ 'fastllm.gemini.norm_parts': ('gemini.html#norm_parts', 'fastllm/gemini.py'),
132
+ 'fastllm.gemini.norm_sse_event': ('gemini.html#norm_sse_event', 'fastllm/gemini.py'),
133
+ 'fastllm.gemini.norm_tool_calls': ('gemini.html#norm_tool_calls', 'fastllm/gemini.py'),
134
+ 'fastllm.gemini.norm_usage': ('gemini.html#norm_usage', 'fastllm/gemini.py')},
135
+ 'fastllm.openai_chat': { 'fastllm.openai_chat.acollect_stream': ('oai_chat.html#acollect_stream', 'fastllm/openai_chat.py'),
136
+ 'fastllm.openai_chat.cost': ('oai_chat.html#cost', 'fastllm/openai_chat.py'),
137
+ 'fastllm.openai_chat.delta_index_fn': ('oai_chat.html#delta_index_fn', 'fastllm/openai_chat.py'),
138
+ 'fastllm.openai_chat.denorm_assistant': ('oai_chat.html#denorm_assistant', 'fastllm/openai_chat.py'),
139
+ 'fastllm.openai_chat.denorm_audio': ('oai_chat.html#denorm_audio', 'fastllm/openai_chat.py'),
140
+ 'fastllm.openai_chat.denorm_file': ('oai_chat.html#denorm_file', 'fastllm/openai_chat.py'),
141
+ 'fastllm.openai_chat.denorm_image': ('oai_chat.html#denorm_image', 'fastllm/openai_chat.py'),
142
+ 'fastllm.openai_chat.denorm_msgs': ('oai_chat.html#denorm_msgs', 'fastllm/openai_chat.py'),
143
+ 'fastllm.openai_chat.denorm_reasoning': ('oai_chat.html#denorm_reasoning', 'fastllm/openai_chat.py'),
144
+ 'fastllm.openai_chat.denorm_system': ('oai_chat.html#denorm_system', 'fastllm/openai_chat.py'),
145
+ 'fastllm.openai_chat.denorm_tool': ('oai_chat.html#denorm_tool', 'fastllm/openai_chat.py'),
146
+ 'fastllm.openai_chat.denorm_tool_choice': ( 'oai_chat.html#denorm_tool_choice',
147
+ 'fastllm/openai_chat.py'),
148
+ 'fastllm.openai_chat.denorm_tool_result': ( 'oai_chat.html#denorm_tool_result',
149
+ 'fastllm/openai_chat.py'),
150
+ 'fastllm.openai_chat.denorm_tool_schs': ('oai_chat.html#denorm_tool_schs', 'fastllm/openai_chat.py'),
151
+ 'fastllm.openai_chat.denorm_tool_use': ('oai_chat.html#denorm_tool_use', 'fastllm/openai_chat.py'),
152
+ 'fastllm.openai_chat.denorm_user': ('oai_chat.html#denorm_user', 'fastllm/openai_chat.py'),
153
+ 'fastllm.openai_chat.denorm_web_search': ('oai_chat.html#denorm_web_search', 'fastllm/openai_chat.py'),
154
+ 'fastllm.openai_chat.get_hdrs': ('oai_chat.html#get_hdrs', 'fastllm/openai_chat.py'),
155
+ 'fastllm.openai_chat.mk_payload': ('oai_chat.html#mk_payload', 'fastllm/openai_chat.py'),
156
+ 'fastllm.openai_chat.norm_finish': ('oai_chat.html#norm_finish', 'fastllm/openai_chat.py'),
157
+ 'fastllm.openai_chat.norm_parts': ('oai_chat.html#norm_parts', 'fastllm/openai_chat.py'),
158
+ 'fastllm.openai_chat.norm_sse_event': ('oai_chat.html#norm_sse_event', 'fastllm/openai_chat.py'),
159
+ 'fastllm.openai_chat.norm_tool_calls': ('oai_chat.html#norm_tool_calls', 'fastllm/openai_chat.py')},
160
+ 'fastllm.openai_responses': { 'fastllm.openai_responses.acollect_stream': ( 'oai_responses.html#acollect_stream',
161
+ 'fastllm/openai_responses.py'),
162
+ 'fastllm.openai_responses.cost': ('oai_responses.html#cost', 'fastllm/openai_responses.py'),
163
+ 'fastllm.openai_responses.delta_index_fn': ( 'oai_responses.html#delta_index_fn',
164
+ 'fastllm/openai_responses.py'),
165
+ 'fastllm.openai_responses.denorm_assistant': ( 'oai_responses.html#denorm_assistant',
166
+ 'fastllm/openai_responses.py'),
167
+ 'fastllm.openai_responses.denorm_file': ( 'oai_responses.html#denorm_file',
168
+ 'fastllm/openai_responses.py'),
169
+ 'fastllm.openai_responses.denorm_image': ( 'oai_responses.html#denorm_image',
170
+ 'fastllm/openai_responses.py'),
171
+ 'fastllm.openai_responses.denorm_msgs': ( 'oai_responses.html#denorm_msgs',
172
+ 'fastllm/openai_responses.py'),
173
+ 'fastllm.openai_responses.denorm_reasoning': ( 'oai_responses.html#denorm_reasoning',
174
+ 'fastllm/openai_responses.py'),
175
+ 'fastllm.openai_responses.denorm_system': ( 'oai_responses.html#denorm_system',
176
+ 'fastllm/openai_responses.py'),
177
+ 'fastllm.openai_responses.denorm_tool': ( 'oai_responses.html#denorm_tool',
178
+ 'fastllm/openai_responses.py'),
179
+ 'fastllm.openai_responses.denorm_tool_choice': ( 'oai_responses.html#denorm_tool_choice',
180
+ 'fastllm/openai_responses.py'),
181
+ 'fastllm.openai_responses.denorm_tool_result': ( 'oai_responses.html#denorm_tool_result',
182
+ 'fastllm/openai_responses.py'),
183
+ 'fastllm.openai_responses.denorm_tool_schs': ( 'oai_responses.html#denorm_tool_schs',
184
+ 'fastllm/openai_responses.py'),
185
+ 'fastllm.openai_responses.denorm_tool_use': ( 'oai_responses.html#denorm_tool_use',
186
+ 'fastllm/openai_responses.py'),
187
+ 'fastllm.openai_responses.denorm_user': ( 'oai_responses.html#denorm_user',
188
+ 'fastllm/openai_responses.py'),
189
+ 'fastllm.openai_responses.denorm_web_search': ( 'oai_responses.html#denorm_web_search',
190
+ 'fastllm/openai_responses.py'),
191
+ 'fastllm.openai_responses.get_hdrs': ( 'oai_responses.html#get_hdrs',
192
+ 'fastllm/openai_responses.py'),
193
+ 'fastllm.openai_responses.mk_payload': ( 'oai_responses.html#mk_payload',
194
+ 'fastllm/openai_responses.py'),
195
+ 'fastllm.openai_responses.norm_finish': ( 'oai_responses.html#norm_finish',
196
+ 'fastllm/openai_responses.py'),
197
+ 'fastllm.openai_responses.norm_parts': ( 'oai_responses.html#norm_parts',
198
+ 'fastllm/openai_responses.py'),
199
+ 'fastllm.openai_responses.norm_sse_event': ( 'oai_responses.html#norm_sse_event',
200
+ 'fastllm/openai_responses.py'),
201
+ 'fastllm.openai_responses.norm_tool_call': ( 'oai_responses.html#norm_tool_call',
202
+ 'fastllm/openai_responses.py'),
203
+ 'fastllm.openai_responses.norm_tool_calls': ( 'oai_responses.html#norm_tool_calls',
204
+ 'fastllm/openai_responses.py'),
205
+ 'fastllm.openai_responses.norm_usage': ( 'oai_responses.html#norm_usage',
206
+ 'fastllm/openai_responses.py')},
207
+ 'fastllm.streaming': { 'fastllm.streaming.Delta': ('streaming.html#delta', 'fastllm/streaming.py'),
208
+ 'fastllm.streaming.PartAccum': ('streaming.html#partaccum', 'fastllm/streaming.py'),
209
+ 'fastllm.streaming.PartAccum.append': ('streaming.html#partaccum.append', 'fastllm/streaming.py'),
210
+ 'fastllm.streaming.PartAccum.finalize': ('streaming.html#partaccum.finalize', 'fastllm/streaming.py'),
211
+ 'fastllm.streaming._trim_delta': ('streaming.html#_trim_delta', 'fastllm/streaming.py'),
212
+ 'fastllm.streaming.accum_completion': ('streaming.html#accum_completion', 'fastllm/streaming.py'),
213
+ 'fastllm.streaming.completion_text': ('streaming.html#completion_text', 'fastllm/streaming.py'),
214
+ 'fastllm.streaming.fake_stream': ('streaming.html#fake_stream', 'fastllm/streaming.py'),
215
+ 'fastllm.streaming.mk_acollect_stream': ('streaming.html#mk_acollect_stream', 'fastllm/streaming.py'),
216
+ 'fastllm.streaming.norm_and_yield': ('streaming.html#norm_and_yield', 'fastllm/streaming.py'),
217
+ 'fastllm.streaming.stop_sequences': ('streaming.html#stop_sequences', 'fastllm/streaming.py')},
218
+ 'fastllm.types': { 'fastllm.types.APIRegistry': ('types.html#apiregistry', 'fastllm/types.py'),
219
+ 'fastllm.types.APIRegistry.__init__': ('types.html#apiregistry.__init__', 'fastllm/types.py'),
220
+ 'fastllm.types.APIRegistry.register': ('types.html#apiregistry.register', 'fastllm/types.py'),
221
+ 'fastllm.types.Completion': ('types.html#completion', 'fastllm/types.py'),
222
+ 'fastllm.types.Completion._repr_markdown_': ('types.html#completion._repr_markdown_', 'fastllm/types.py'),
223
+ 'fastllm.types.Completion.cost': ('types.html#completion.cost', 'fastllm/types.py'),
224
+ 'fastllm.types.Msg': ('types.html#msg', 'fastllm/types.py'),
225
+ 'fastllm.types.Msg._repr_markdown_': ('types.html#msg._repr_markdown_', 'fastllm/types.py'),
226
+ 'fastllm.types.Part': ('types.html#part', 'fastllm/types.py'),
227
+ 'fastllm.types.Part._repr_markdown_': ('types.html#part._repr_markdown_', 'fastllm/types.py'),
228
+ 'fastllm.types.ToolCall': ('types.html#toolcall', 'fastllm/types.py'),
229
+ 'fastllm.types.ToolCall._repr_markdown_': ('types.html#toolcall._repr_markdown_', 'fastllm/types.py'),
230
+ 'fastllm.types.Usage': ('types.html#usage', 'fastllm/types.py'),
231
+ 'fastllm.types._trunc_strs': ('types.html#_trunc_strs', 'fastllm/types.py'),
232
+ 'fastllm.types.data_url': ('types.html#data_url', 'fastllm/types.py'),
233
+ 'fastllm.types.display_list': ('types.html#display_list', 'fastllm/types.py'),
234
+ 'fastllm.types.fn_schema': ('types.html#fn_schema', 'fastllm/types.py'),
235
+ 'fastllm.types.get_api_key': ('types.html#get_api_key', 'fastllm/types.py'),
236
+ 'fastllm.types.get_model_info': ('types.html#get_model_info', 'fastllm/types.py'),
237
+ 'fastllm.types.get_model_meta': ('types.html#get_model_meta', 'fastllm/types.py'),
238
+ 'fastllm.types.infer_api_name': ('types.html#infer_api_name', 'fastllm/types.py'),
239
+ 'fastllm.types.mk_completion': ('types.html#mk_completion', 'fastllm/types.py'),
240
+ 'fastllm.types.mk_tool_res_msg': ('types.html#mk_tool_res_msg', 'fastllm/types.py'),
241
+ 'fastllm.types.model_prices_meta': ('types.html#model_prices_meta', 'fastllm/types.py'),
242
+ 'fastllm.types.part_txt': ('types.html#part_txt', 'fastllm/types.py'),
243
+ 'fastllm.types.payload_kwargs': ('types.html#payload_kwargs', 'fastllm/types.py'),
244
+ 'fastllm.types.sys_text': ('types.html#sys_text', 'fastllm/types.py'),
245
+ 'fastllm.types.url_mime': ('types.html#url_mime', 'fastllm/types.py')}}}
fastllm/acomplete.py ADDED
@@ -0,0 +1,122 @@
1
+ """A high level unified function make api calls"""
2
+
3
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/06_acomplete.ipynb.
4
+
5
+ # %% auto #0
6
+ __all__ = ['specs_path', 'ant_spec', 'oai_spec', 'gem_spec', 'vendor_mapping', 'api2spec', 'mk_client',
7
+ 'ContextWindowExceededError', 'acomplete']
8
+
9
+ # %% ../nbs/06_acomplete.ipynb #f2f57253
10
+ import json
11
+ from importlib.resources import files
12
+ from fastcore.utils import *
13
+ from fastcore.meta import *
14
+ from fastspec.spec import *
15
+ from fastspec.oapi import *
16
+ from fastspec.errors import APIError
17
+
18
+ from .types import *
19
+ from .streaming import *
20
+ from .openai_responses import *
21
+ from .streaming import stop_sequences as _stop_sequences
22
+ from .openai_chat import *
23
+ from .anthropic import *
24
+ from .gemini import *
25
+
26
+ # %% ../nbs/06_acomplete.ipynb #6d11ac28
27
+ specs_path = files('fastllm') / 'specs'
28
+ ant_spec = SpecParser.from_openapi(dict2obj(json.loads((specs_path/'anthropic.json').read_text())))
29
+ oai_spec = SpecParser.from_openapi(dict2obj(json.loads((specs_path/'openai.with-code-samples.json').read_text())))
30
+ gem_spec = SpecParser.from_discovery(dict2obj(json.loads((specs_path/'gemini.json').read_text())))
31
+
32
+ # %% ../nbs/06_acomplete.ipynb #32ee2546
33
+ _codex_json = '~/.codex/auth.json', 'tokens','access_token'
34
+ vendor_mapping = {
35
+ "openai": ('openai', 'https://api.openai.com/v1', 'OPENAI_API_KEY'),
36
+ "anthropic": ('anthropic', 'https://api.anthropic.com', 'ANTHROPIC_API_KEY'),
37
+ "gemini": ('gemini', 'https://generativelanguage.googleapis.com/', 'GEMINI_API_KEY'),
38
+ "openai_chat": ('openai_chat', 'https://api.openai.com/v1', 'OPENAI_API_KEY'),
39
+ "codex": ('openai', 'https://chatgpt.com/backend-api/codex', 'CODEX_AUTH_TOKEN', _codex_json),
40
+ "moonshot": ('openai_chat', "https://api.moonshot.ai/v1", "MOONSHOT_API_KEY"),
41
+ "deepseek": ('openai_chat', "https://api.deepseek.com/v1", "DEEPSEEK_API_KEY"),
42
+ "openrouter": ('openai_chat', "https://openrouter.ai/api/v1", "OPENROUTER_API_KEY"),
43
+ "together": ('openai_chat', "https://api.together.xyz/v1", "TOGETHER_API_KEY"),
44
+ "fireworks_ai": ('openai_chat', "https://api.fireworks.ai/inference/v1", "FIREWORKS_API_KEY"),
45
+ "qwen": ('openai_chat', "https://dashscope.aliyuncs.com/compatible-mode/v1", "QWEN_API_KEY")
46
+ }
47
+
48
+ # %% ../nbs/06_acomplete.ipynb #77d27ea7
49
+ api2spec = {'openai':oai_spec, 'openai_chat':oai_spec, 'anthropic':ant_spec, 'gemini':gem_spec}
50
+
51
+ # %% ../nbs/06_acomplete.ipynb #79075d95
52
+ @flexicache()
53
+ def mk_client(model, vendor_name=None, api_name=None, api_key=None, base_url=None, xtra_hdrs=None):
54
+ err_msg = f"please pass a valid one vendor: {', '.join(list(vendor_mapping))} or pass `api_name`,`base_url` and `api_key`"
55
+ if vendor_name:
56
+ override_base_url = base_url
57
+ try:
58
+ api_name, base_url, env_api_nm, *auth_json = vendor_mapping[vendor_name]
59
+ base_url = override_base_url or base_url
60
+ if auth_json and not api_key and not os.getenv(env_api_nm):
61
+ fn,keys = auth_json[0] # pyright: ignore[reportAssignmentType]
62
+ auth_fn = Path(fn).expanduser()
63
+ if auth_fn.exists(): api_key = nested_idx(json.loads(auth_fn.read_text()), *keys)
64
+ api_key = get_api_key(api_key, env_api_nm)
65
+ except KeyError: raise ValueError(f"Unknown vendor '{vendor_name}', {err_msg}")
66
+ elif api_name and base_url and api_key: vendor_name = ifnone(vendor_name, 'custom')
67
+ elif (api_name:=infer_api_name(model)): base_url, vendor_name = None, api_name
68
+ else: raise ValueError(f"Model {model} can't be auto resolved, {err_msg}")
69
+ api = api_registry.apis[api_name]
70
+ spec, hdrs = api2spec[api_name], api.get_hdrs(api_key)
71
+ cli = OpenAPIClient(spec, headers=merge(hdrs, ifnone(xtra_hdrs, {})))
72
+ if base_url is not None:
73
+ for op in cli.ops: op.base_url = base_url # pyright: ignore[reportAttributeAccessIssue]
74
+ return cli, api_name, vendor_name
75
+
76
+ # %% ../nbs/06_acomplete.ipynb #df851a5c
77
+ class ContextWindowExceededError(APIError): pass
78
+
79
+ def _is_ctx_exceeded(code, msg):
80
+ m = (msg or "").lower()
81
+ if any(x in m for x in ("string_above_max_length", "invalid 'user'")): return False
82
+ if str(code or "").lower() == "context_length_exceeded": return True
83
+ return any(s in m for s in ("exceed context limit", "maximum context length", "maximum context limit",
84
+ "longer than the model's context length", "input tokens exceed the configured limit",
85
+ "exceeds the maximum number of tokens allowed", "prompt is too long"))
86
+
87
+ def _classify_error(exc):
88
+ "Upgrade generic `APIError` to a specific subclass if applicable."
89
+ if not isinstance(exc, APIError): return exc
90
+ if _is_ctx_exceeded(exc.code, exc.message):
91
+ return ContextWindowExceededError(exc.message, provider=exc.provider, model=exc.model,
92
+ endpoint=exc.endpoint, status_code=exc.status_code, error_type=exc.error_type,
93
+ code=exc.code, request_id=exc.request_id, retryable=exc.retryable, raw=exc.raw)
94
+ return exc
95
+
96
+ async def _classify_error_stream(gen):
97
+ "Wrap an async generator to upgrade `APIError`s as they're raised during iteration."
98
+ try:
99
+ async for x in gen: yield x
100
+ except APIError as e: raise _classify_error(e) from e
101
+
102
+ # %% ../nbs/06_acomplete.ipynb #2379ec94
103
+ @delegates(payload_kwargs)
104
+ async def acomplete(msgs, model, api_name=None, vendor_name=None, api_key=None, base_url=None, xtra_body=None, xtra_hdrs=None,
105
+ stream=False, stop_callables=None, stop_sequences=None, **kwargs):
106
+ "Unified completion across different APIs."
107
+ cli, api_name, vendor_name = mk_client(model, vendor_name, api_name, api_key, base_url, xtra_hdrs)
108
+ api = api_registry.apis[api_name]
109
+ if stop_sequences: stop_callables = L(stop_callables) + [_stop_sequences(stop_sequences)]
110
+ payload = api.mk_payload(msgs, model, stream=stream, stop_callables=stop_callables, **kwargs)
111
+ payload = merge(payload, ifnone(xtra_body, {}))
112
+ if vendor_name == 'codex':
113
+ for k in 'temperature max_tokens max_output_tokens max_completion_tokens metadata'.split(): payload.pop(k, None)
114
+ payload['store'] = False
115
+ if nested_idx(payload, 'messages', -1, 'role') == 'assistant':
116
+ if vendor_name == 'deepseek' and 'v4' in model: payload['messages'][-1]['prefix'] = True
117
+ if vendor_name == 'moonshot' and 'kimi' in model: payload['messages'][-1]['partial'] = True
118
+ func = attrgetter(api.op_path[stream])(cli)
119
+ try: resp = await func(**payload)
120
+ except APIError as e: raise _classify_error(e) from e
121
+ if stream: return _classify_error_stream(api.acollect_stream(resp, model=model, vendor_name=vendor_name, stop_callables=stop_callables))
122
+ return mk_completion(resp, model=model, api_name=api_name, vendor_name=vendor_name)