mirascope 1.25.7__py3-none-any.whl → 2.0.0__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.
Files changed (797) hide show
  1. mirascope/__init__.py +5 -52
  2. mirascope/_stubs.py +363 -0
  3. mirascope/api/__init__.py +14 -0
  4. mirascope/api/_generated/README.md +207 -0
  5. mirascope/api/_generated/__init__.py +440 -0
  6. mirascope/api/_generated/annotations/__init__.py +33 -0
  7. mirascope/api/_generated/annotations/client.py +506 -0
  8. mirascope/api/_generated/annotations/raw_client.py +1414 -0
  9. mirascope/api/_generated/annotations/types/__init__.py +31 -0
  10. mirascope/api/_generated/annotations/types/annotations_create_request_label.py +5 -0
  11. mirascope/api/_generated/annotations/types/annotations_create_response.py +48 -0
  12. mirascope/api/_generated/annotations/types/annotations_create_response_label.py +5 -0
  13. mirascope/api/_generated/annotations/types/annotations_get_response.py +48 -0
  14. mirascope/api/_generated/annotations/types/annotations_get_response_label.py +5 -0
  15. mirascope/api/_generated/annotations/types/annotations_list_request_label.py +5 -0
  16. mirascope/api/_generated/annotations/types/annotations_list_response.py +21 -0
  17. mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item.py +50 -0
  18. mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item_label.py +5 -0
  19. mirascope/api/_generated/annotations/types/annotations_update_request_label.py +5 -0
  20. mirascope/api/_generated/annotations/types/annotations_update_response.py +48 -0
  21. mirascope/api/_generated/annotations/types/annotations_update_response_label.py +5 -0
  22. mirascope/api/_generated/api_keys/__init__.py +17 -0
  23. mirascope/api/_generated/api_keys/client.py +530 -0
  24. mirascope/api/_generated/api_keys/raw_client.py +1236 -0
  25. mirascope/api/_generated/api_keys/types/__init__.py +15 -0
  26. mirascope/api/_generated/api_keys/types/api_keys_create_response.py +28 -0
  27. mirascope/api/_generated/api_keys/types/api_keys_get_response.py +27 -0
  28. mirascope/api/_generated/api_keys/types/api_keys_list_all_for_org_response_item.py +40 -0
  29. mirascope/api/_generated/api_keys/types/api_keys_list_response_item.py +27 -0
  30. mirascope/api/_generated/client.py +211 -0
  31. mirascope/api/_generated/core/__init__.py +52 -0
  32. mirascope/api/_generated/core/api_error.py +23 -0
  33. mirascope/api/_generated/core/client_wrapper.py +46 -0
  34. mirascope/api/_generated/core/datetime_utils.py +28 -0
  35. mirascope/api/_generated/core/file.py +67 -0
  36. mirascope/api/_generated/core/force_multipart.py +16 -0
  37. mirascope/api/_generated/core/http_client.py +543 -0
  38. mirascope/api/_generated/core/http_response.py +55 -0
  39. mirascope/api/_generated/core/jsonable_encoder.py +100 -0
  40. mirascope/api/_generated/core/pydantic_utilities.py +255 -0
  41. mirascope/api/_generated/core/query_encoder.py +58 -0
  42. mirascope/api/_generated/core/remove_none_from_dict.py +11 -0
  43. mirascope/api/_generated/core/request_options.py +35 -0
  44. mirascope/api/_generated/core/serialization.py +276 -0
  45. mirascope/api/_generated/docs/__init__.py +4 -0
  46. mirascope/api/_generated/docs/client.py +91 -0
  47. mirascope/api/_generated/docs/raw_client.py +178 -0
  48. mirascope/api/_generated/environment.py +9 -0
  49. mirascope/api/_generated/environments/__init__.py +23 -0
  50. mirascope/api/_generated/environments/client.py +649 -0
  51. mirascope/api/_generated/environments/raw_client.py +1567 -0
  52. mirascope/api/_generated/environments/types/__init__.py +25 -0
  53. mirascope/api/_generated/environments/types/environments_create_response.py +24 -0
  54. mirascope/api/_generated/environments/types/environments_get_analytics_response.py +60 -0
  55. mirascope/api/_generated/environments/types/environments_get_analytics_response_top_functions_item.py +24 -0
  56. mirascope/api/_generated/environments/types/environments_get_analytics_response_top_models_item.py +22 -0
  57. mirascope/api/_generated/environments/types/environments_get_response.py +24 -0
  58. mirascope/api/_generated/environments/types/environments_list_response_item.py +24 -0
  59. mirascope/api/_generated/environments/types/environments_update_response.py +24 -0
  60. mirascope/api/_generated/errors/__init__.py +25 -0
  61. mirascope/api/_generated/errors/bad_request_error.py +14 -0
  62. mirascope/api/_generated/errors/conflict_error.py +14 -0
  63. mirascope/api/_generated/errors/forbidden_error.py +11 -0
  64. mirascope/api/_generated/errors/internal_server_error.py +10 -0
  65. mirascope/api/_generated/errors/not_found_error.py +11 -0
  66. mirascope/api/_generated/errors/payment_required_error.py +15 -0
  67. mirascope/api/_generated/errors/service_unavailable_error.py +14 -0
  68. mirascope/api/_generated/errors/too_many_requests_error.py +15 -0
  69. mirascope/api/_generated/errors/unauthorized_error.py +11 -0
  70. mirascope/api/_generated/functions/__init__.py +39 -0
  71. mirascope/api/_generated/functions/client.py +647 -0
  72. mirascope/api/_generated/functions/raw_client.py +1890 -0
  73. mirascope/api/_generated/functions/types/__init__.py +53 -0
  74. mirascope/api/_generated/functions/types/functions_create_request_dependencies_value.py +20 -0
  75. mirascope/api/_generated/functions/types/functions_create_response.py +37 -0
  76. mirascope/api/_generated/functions/types/functions_create_response_dependencies_value.py +20 -0
  77. mirascope/api/_generated/functions/types/functions_find_by_hash_response.py +39 -0
  78. mirascope/api/_generated/functions/types/functions_find_by_hash_response_dependencies_value.py +20 -0
  79. mirascope/api/_generated/functions/types/functions_get_by_env_response.py +53 -0
  80. mirascope/api/_generated/functions/types/functions_get_by_env_response_dependencies_value.py +22 -0
  81. mirascope/api/_generated/functions/types/functions_get_response.py +37 -0
  82. mirascope/api/_generated/functions/types/functions_get_response_dependencies_value.py +20 -0
  83. mirascope/api/_generated/functions/types/functions_list_by_env_response.py +25 -0
  84. mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item.py +56 -0
  85. mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item_dependencies_value.py +22 -0
  86. mirascope/api/_generated/functions/types/functions_list_response.py +21 -0
  87. mirascope/api/_generated/functions/types/functions_list_response_functions_item.py +41 -0
  88. mirascope/api/_generated/functions/types/functions_list_response_functions_item_dependencies_value.py +20 -0
  89. mirascope/api/_generated/health/__init__.py +7 -0
  90. mirascope/api/_generated/health/client.py +92 -0
  91. mirascope/api/_generated/health/raw_client.py +175 -0
  92. mirascope/api/_generated/health/types/__init__.py +8 -0
  93. mirascope/api/_generated/health/types/health_check_response.py +22 -0
  94. mirascope/api/_generated/health/types/health_check_response_status.py +5 -0
  95. mirascope/api/_generated/organization_invitations/__init__.py +33 -0
  96. mirascope/api/_generated/organization_invitations/client.py +546 -0
  97. mirascope/api/_generated/organization_invitations/raw_client.py +1519 -0
  98. mirascope/api/_generated/organization_invitations/types/__init__.py +53 -0
  99. mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response.py +34 -0
  100. mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response_role.py +7 -0
  101. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_request_role.py +7 -0
  102. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response.py +48 -0
  103. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_role.py +7 -0
  104. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_status.py +7 -0
  105. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response.py +48 -0
  106. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_role.py +7 -0
  107. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_status.py +7 -0
  108. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item.py +48 -0
  109. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_role.py +7 -0
  110. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_status.py +7 -0
  111. mirascope/api/_generated/organization_memberships/__init__.py +19 -0
  112. mirascope/api/_generated/organization_memberships/client.py +302 -0
  113. mirascope/api/_generated/organization_memberships/raw_client.py +736 -0
  114. mirascope/api/_generated/organization_memberships/types/__init__.py +27 -0
  115. mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item.py +33 -0
  116. mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item_role.py +7 -0
  117. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_request_role.py +7 -0
  118. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response.py +31 -0
  119. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response_role.py +7 -0
  120. mirascope/api/_generated/organizations/__init__.py +51 -0
  121. mirascope/api/_generated/organizations/client.py +869 -0
  122. mirascope/api/_generated/organizations/raw_client.py +2593 -0
  123. mirascope/api/_generated/organizations/types/__init__.py +71 -0
  124. mirascope/api/_generated/organizations/types/organizations_create_payment_intent_response.py +24 -0
  125. mirascope/api/_generated/organizations/types/organizations_create_response.py +26 -0
  126. mirascope/api/_generated/organizations/types/organizations_create_response_role.py +5 -0
  127. mirascope/api/_generated/organizations/types/organizations_get_response.py +26 -0
  128. mirascope/api/_generated/organizations/types/organizations_get_response_role.py +5 -0
  129. mirascope/api/_generated/organizations/types/organizations_list_response_item.py +26 -0
  130. mirascope/api/_generated/organizations/types/organizations_list_response_item_role.py +5 -0
  131. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_request_target_plan.py +7 -0
  132. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response.py +47 -0
  133. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item.py +33 -0
  134. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item_resource.py +7 -0
  135. mirascope/api/_generated/organizations/types/organizations_router_balance_response.py +24 -0
  136. mirascope/api/_generated/organizations/types/organizations_subscription_response.py +53 -0
  137. mirascope/api/_generated/organizations/types/organizations_subscription_response_current_plan.py +7 -0
  138. mirascope/api/_generated/organizations/types/organizations_subscription_response_payment_method.py +26 -0
  139. mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change.py +34 -0
  140. mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change_target_plan.py +7 -0
  141. mirascope/api/_generated/organizations/types/organizations_update_response.py +26 -0
  142. mirascope/api/_generated/organizations/types/organizations_update_response_role.py +5 -0
  143. mirascope/api/_generated/organizations/types/organizations_update_subscription_request_target_plan.py +7 -0
  144. mirascope/api/_generated/organizations/types/organizations_update_subscription_response.py +35 -0
  145. mirascope/api/_generated/project_memberships/__init__.py +25 -0
  146. mirascope/api/_generated/project_memberships/client.py +437 -0
  147. mirascope/api/_generated/project_memberships/raw_client.py +1039 -0
  148. mirascope/api/_generated/project_memberships/types/__init__.py +29 -0
  149. mirascope/api/_generated/project_memberships/types/project_memberships_create_request_role.py +7 -0
  150. mirascope/api/_generated/project_memberships/types/project_memberships_create_response.py +35 -0
  151. mirascope/api/_generated/project_memberships/types/project_memberships_create_response_role.py +7 -0
  152. mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item.py +33 -0
  153. mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item_role.py +7 -0
  154. mirascope/api/_generated/project_memberships/types/project_memberships_update_request_role.py +7 -0
  155. mirascope/api/_generated/project_memberships/types/project_memberships_update_response.py +35 -0
  156. mirascope/api/_generated/project_memberships/types/project_memberships_update_response_role.py +7 -0
  157. mirascope/api/_generated/projects/__init__.py +7 -0
  158. mirascope/api/_generated/projects/client.py +428 -0
  159. mirascope/api/_generated/projects/raw_client.py +1302 -0
  160. mirascope/api/_generated/projects/types/__init__.py +10 -0
  161. mirascope/api/_generated/projects/types/projects_create_response.py +25 -0
  162. mirascope/api/_generated/projects/types/projects_get_response.py +25 -0
  163. mirascope/api/_generated/projects/types/projects_list_response_item.py +25 -0
  164. mirascope/api/_generated/projects/types/projects_update_response.py +25 -0
  165. mirascope/api/_generated/reference.md +4915 -0
  166. mirascope/api/_generated/tags/__init__.py +19 -0
  167. mirascope/api/_generated/tags/client.py +504 -0
  168. mirascope/api/_generated/tags/raw_client.py +1288 -0
  169. mirascope/api/_generated/tags/types/__init__.py +17 -0
  170. mirascope/api/_generated/tags/types/tags_create_response.py +41 -0
  171. mirascope/api/_generated/tags/types/tags_get_response.py +41 -0
  172. mirascope/api/_generated/tags/types/tags_list_response.py +23 -0
  173. mirascope/api/_generated/tags/types/tags_list_response_tags_item.py +41 -0
  174. mirascope/api/_generated/tags/types/tags_update_response.py +41 -0
  175. mirascope/api/_generated/token_cost/__init__.py +7 -0
  176. mirascope/api/_generated/token_cost/client.py +160 -0
  177. mirascope/api/_generated/token_cost/raw_client.py +264 -0
  178. mirascope/api/_generated/token_cost/types/__init__.py +8 -0
  179. mirascope/api/_generated/token_cost/types/token_cost_calculate_request_usage.py +54 -0
  180. mirascope/api/_generated/token_cost/types/token_cost_calculate_response.py +52 -0
  181. mirascope/api/_generated/traces/__init__.py +97 -0
  182. mirascope/api/_generated/traces/client.py +1103 -0
  183. mirascope/api/_generated/traces/raw_client.py +2322 -0
  184. mirascope/api/_generated/traces/types/__init__.py +155 -0
  185. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +29 -0
  186. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +27 -0
  187. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +23 -0
  188. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +38 -0
  189. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +19 -0
  190. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +22 -0
  191. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +20 -0
  192. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +29 -0
  193. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +31 -0
  194. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +23 -0
  195. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +38 -0
  196. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +19 -0
  197. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +22 -0
  198. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value_values_item.py +22 -0
  199. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +48 -0
  200. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +23 -0
  201. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +38 -0
  202. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +19 -0
  203. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +24 -0
  204. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value_values_item.py +22 -0
  205. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +20 -0
  206. mirascope/api/_generated/traces/types/traces_create_response.py +24 -0
  207. mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +22 -0
  208. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response.py +60 -0
  209. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_functions_item.py +24 -0
  210. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_models_item.py +22 -0
  211. mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response.py +33 -0
  212. mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response_spans_item.py +88 -0
  213. mirascope/api/_generated/traces/types/traces_get_trace_detail_response.py +33 -0
  214. mirascope/api/_generated/traces/types/traces_get_trace_detail_response_spans_item.py +88 -0
  215. mirascope/api/_generated/traces/types/traces_list_by_function_hash_response.py +25 -0
  216. mirascope/api/_generated/traces/types/traces_list_by_function_hash_response_traces_item.py +44 -0
  217. mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item.py +26 -0
  218. mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item_operator.py +7 -0
  219. mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_by.py +7 -0
  220. mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_order.py +7 -0
  221. mirascope/api/_generated/traces/types/traces_search_by_env_response.py +26 -0
  222. mirascope/api/_generated/traces/types/traces_search_by_env_response_spans_item.py +50 -0
  223. mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item.py +26 -0
  224. mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item_operator.py +7 -0
  225. mirascope/api/_generated/traces/types/traces_search_request_sort_by.py +7 -0
  226. mirascope/api/_generated/traces/types/traces_search_request_sort_order.py +5 -0
  227. mirascope/api/_generated/traces/types/traces_search_response.py +26 -0
  228. mirascope/api/_generated/traces/types/traces_search_response_spans_item.py +50 -0
  229. mirascope/api/_generated/types/__init__.py +85 -0
  230. mirascope/api/_generated/types/already_exists_error.py +22 -0
  231. mirascope/api/_generated/types/already_exists_error_tag.py +5 -0
  232. mirascope/api/_generated/types/bad_request_error_body.py +50 -0
  233. mirascope/api/_generated/types/click_house_error.py +22 -0
  234. mirascope/api/_generated/types/database_error.py +22 -0
  235. mirascope/api/_generated/types/database_error_tag.py +5 -0
  236. mirascope/api/_generated/types/date.py +3 -0
  237. mirascope/api/_generated/types/http_api_decode_error.py +27 -0
  238. mirascope/api/_generated/types/http_api_decode_error_tag.py +5 -0
  239. mirascope/api/_generated/types/immutable_resource_error.py +22 -0
  240. mirascope/api/_generated/types/internal_server_error_body.py +49 -0
  241. mirascope/api/_generated/types/issue.py +38 -0
  242. mirascope/api/_generated/types/issue_tag.py +10 -0
  243. mirascope/api/_generated/types/not_found_error_body.py +22 -0
  244. mirascope/api/_generated/types/not_found_error_tag.py +5 -0
  245. mirascope/api/_generated/types/number_from_string.py +3 -0
  246. mirascope/api/_generated/types/permission_denied_error.py +22 -0
  247. mirascope/api/_generated/types/permission_denied_error_tag.py +5 -0
  248. mirascope/api/_generated/types/plan_limit_exceeded_error.py +32 -0
  249. mirascope/api/_generated/types/plan_limit_exceeded_error_tag.py +7 -0
  250. mirascope/api/_generated/types/pricing_unavailable_error.py +23 -0
  251. mirascope/api/_generated/types/property_key.py +7 -0
  252. mirascope/api/_generated/types/property_key_key.py +25 -0
  253. mirascope/api/_generated/types/property_key_key_tag.py +5 -0
  254. mirascope/api/_generated/types/rate_limit_error.py +31 -0
  255. mirascope/api/_generated/types/rate_limit_error_tag.py +5 -0
  256. mirascope/api/_generated/types/service_unavailable_error_body.py +24 -0
  257. mirascope/api/_generated/types/service_unavailable_error_tag.py +7 -0
  258. mirascope/api/_generated/types/stripe_error.py +20 -0
  259. mirascope/api/_generated/types/subscription_past_due_error.py +31 -0
  260. mirascope/api/_generated/types/subscription_past_due_error_tag.py +7 -0
  261. mirascope/api/_generated/types/unauthorized_error_body.py +21 -0
  262. mirascope/api/_generated/types/unauthorized_error_tag.py +5 -0
  263. mirascope/api/client.py +255 -0
  264. mirascope/api/settings.py +99 -0
  265. mirascope/llm/__init__.py +290 -15
  266. mirascope/llm/calls/__init__.py +17 -0
  267. mirascope/llm/calls/calls.py +341 -0
  268. mirascope/llm/calls/decorator.py +275 -0
  269. mirascope/llm/content/__init__.py +71 -0
  270. mirascope/llm/content/audio.py +173 -0
  271. mirascope/llm/content/document.py +94 -0
  272. mirascope/llm/content/image.py +206 -0
  273. mirascope/llm/content/text.py +47 -0
  274. mirascope/llm/content/thought.py +58 -0
  275. mirascope/llm/content/tool_call.py +69 -0
  276. mirascope/llm/content/tool_output.py +43 -0
  277. mirascope/llm/context/__init__.py +6 -0
  278. mirascope/llm/context/_utils.py +41 -0
  279. mirascope/llm/context/context.py +24 -0
  280. mirascope/llm/exceptions.py +360 -0
  281. mirascope/llm/formatting/__init__.py +39 -0
  282. mirascope/llm/formatting/format.py +293 -0
  283. mirascope/llm/formatting/from_call_args.py +30 -0
  284. mirascope/llm/formatting/output_parser.py +178 -0
  285. mirascope/llm/formatting/partial.py +131 -0
  286. mirascope/llm/formatting/primitives.py +192 -0
  287. mirascope/llm/formatting/types.py +66 -0
  288. mirascope/llm/mcp/__init__.py +5 -0
  289. mirascope/llm/mcp/mcp_client.py +130 -0
  290. mirascope/llm/messages/__init__.py +35 -0
  291. mirascope/llm/messages/_utils.py +34 -0
  292. mirascope/llm/messages/message.py +190 -0
  293. mirascope/llm/models/__init__.py +21 -0
  294. mirascope/llm/models/models.py +1419 -0
  295. mirascope/llm/models/params.py +72 -0
  296. mirascope/llm/models/thinking_config.py +61 -0
  297. mirascope/llm/prompts/__init__.py +34 -0
  298. mirascope/llm/prompts/_utils.py +31 -0
  299. mirascope/llm/prompts/decorator.py +226 -0
  300. mirascope/llm/prompts/prompts.py +487 -0
  301. mirascope/llm/prompts/protocols.py +65 -0
  302. mirascope/llm/providers/__init__.py +62 -0
  303. mirascope/llm/providers/anthropic/__init__.py +11 -0
  304. mirascope/llm/providers/anthropic/_utils/__init__.py +27 -0
  305. mirascope/llm/providers/anthropic/_utils/beta_decode.py +282 -0
  306. mirascope/llm/providers/anthropic/_utils/beta_encode.py +266 -0
  307. mirascope/llm/providers/anthropic/_utils/decode.py +288 -0
  308. mirascope/llm/providers/anthropic/_utils/encode.py +418 -0
  309. mirascope/llm/providers/anthropic/_utils/errors.py +46 -0
  310. mirascope/llm/providers/anthropic/beta_provider.py +374 -0
  311. mirascope/llm/providers/anthropic/model_id.py +23 -0
  312. mirascope/llm/providers/anthropic/model_info.py +87 -0
  313. mirascope/llm/providers/anthropic/provider.py +479 -0
  314. mirascope/llm/providers/base/__init__.py +14 -0
  315. mirascope/llm/providers/base/_utils.py +253 -0
  316. mirascope/llm/providers/base/base_provider.py +1579 -0
  317. mirascope/llm/providers/base/kwargs.py +12 -0
  318. mirascope/llm/providers/google/__init__.py +6 -0
  319. mirascope/llm/providers/google/_utils/__init__.py +17 -0
  320. mirascope/llm/providers/google/_utils/decode.py +307 -0
  321. mirascope/llm/providers/google/_utils/encode.py +401 -0
  322. mirascope/llm/providers/google/_utils/errors.py +50 -0
  323. mirascope/llm/providers/google/message.py +7 -0
  324. mirascope/llm/providers/google/model_id.py +22 -0
  325. mirascope/llm/providers/google/model_info.py +63 -0
  326. mirascope/llm/providers/google/provider.py +492 -0
  327. mirascope/llm/providers/mirascope/__init__.py +5 -0
  328. mirascope/llm/providers/mirascope/_utils.py +73 -0
  329. mirascope/llm/providers/mirascope/provider.py +349 -0
  330. mirascope/llm/providers/mlx/__init__.py +9 -0
  331. mirascope/llm/providers/mlx/_utils.py +141 -0
  332. mirascope/llm/providers/mlx/encoding/__init__.py +8 -0
  333. mirascope/llm/providers/mlx/encoding/base.py +72 -0
  334. mirascope/llm/providers/mlx/encoding/transformers.py +150 -0
  335. mirascope/llm/providers/mlx/mlx.py +254 -0
  336. mirascope/llm/providers/mlx/model_id.py +17 -0
  337. mirascope/llm/providers/mlx/provider.py +452 -0
  338. mirascope/llm/providers/model_id.py +16 -0
  339. mirascope/llm/providers/ollama/__init__.py +7 -0
  340. mirascope/llm/providers/ollama/provider.py +71 -0
  341. mirascope/llm/providers/openai/__init__.py +15 -0
  342. mirascope/llm/providers/openai/_utils/__init__.py +5 -0
  343. mirascope/llm/providers/openai/_utils/errors.py +46 -0
  344. mirascope/llm/providers/openai/completions/__init__.py +7 -0
  345. mirascope/llm/providers/openai/completions/_utils/__init__.py +15 -0
  346. mirascope/llm/providers/openai/completions/_utils/decode.py +252 -0
  347. mirascope/llm/providers/openai/completions/_utils/encode.py +376 -0
  348. mirascope/llm/providers/openai/completions/base_provider.py +542 -0
  349. mirascope/llm/providers/openai/completions/provider.py +22 -0
  350. mirascope/llm/providers/openai/model_id.py +31 -0
  351. mirascope/llm/providers/openai/model_info.py +303 -0
  352. mirascope/llm/providers/openai/provider.py +441 -0
  353. mirascope/llm/providers/openai/responses/__init__.py +5 -0
  354. mirascope/llm/providers/openai/responses/_utils/__init__.py +15 -0
  355. mirascope/llm/providers/openai/responses/_utils/decode.py +260 -0
  356. mirascope/llm/providers/openai/responses/_utils/encode.py +384 -0
  357. mirascope/llm/providers/openai/responses/provider.py +513 -0
  358. mirascope/llm/providers/provider_id.py +24 -0
  359. mirascope/llm/providers/provider_registry.py +299 -0
  360. mirascope/llm/providers/together/__init__.py +7 -0
  361. mirascope/llm/providers/together/provider.py +40 -0
  362. mirascope/llm/responses/__init__.py +65 -0
  363. mirascope/llm/responses/_utils.py +146 -0
  364. mirascope/llm/responses/base_response.py +103 -0
  365. mirascope/llm/responses/base_stream_response.py +820 -0
  366. mirascope/llm/responses/finish_reason.py +28 -0
  367. mirascope/llm/responses/response.py +366 -0
  368. mirascope/llm/responses/root_response.py +248 -0
  369. mirascope/llm/responses/stream_response.py +581 -0
  370. mirascope/llm/responses/streams.py +363 -0
  371. mirascope/llm/responses/usage.py +95 -0
  372. mirascope/llm/tools/__init__.py +47 -0
  373. mirascope/llm/tools/_utils.py +34 -0
  374. mirascope/llm/tools/decorator.py +184 -0
  375. mirascope/llm/tools/protocols.py +96 -0
  376. mirascope/llm/tools/tool_schema.py +314 -0
  377. mirascope/llm/tools/toolkit.py +160 -0
  378. mirascope/llm/tools/tools.py +263 -0
  379. mirascope/llm/types/__init__.py +22 -0
  380. mirascope/llm/types/dataclass.py +9 -0
  381. mirascope/llm/types/jsonable.py +44 -0
  382. mirascope/llm/types/type_vars.py +19 -0
  383. mirascope/ops/__init__.py +111 -0
  384. mirascope/ops/_internal/__init__.py +5 -0
  385. mirascope/ops/_internal/closure.py +1169 -0
  386. mirascope/ops/_internal/configuration.py +177 -0
  387. mirascope/ops/_internal/context.py +76 -0
  388. mirascope/ops/_internal/exporters/__init__.py +26 -0
  389. mirascope/ops/_internal/exporters/exporters.py +395 -0
  390. mirascope/ops/_internal/exporters/processors.py +104 -0
  391. mirascope/ops/_internal/exporters/types.py +165 -0
  392. mirascope/ops/_internal/exporters/utils.py +29 -0
  393. mirascope/ops/_internal/instrumentation/__init__.py +8 -0
  394. mirascope/ops/_internal/instrumentation/llm/__init__.py +8 -0
  395. mirascope/ops/_internal/instrumentation/llm/common.py +530 -0
  396. mirascope/ops/_internal/instrumentation/llm/cost.py +190 -0
  397. mirascope/ops/_internal/instrumentation/llm/encode.py +238 -0
  398. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/__init__.py +38 -0
  399. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_input_messages.py +31 -0
  400. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_output_messages.py +38 -0
  401. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_system_instructions.py +18 -0
  402. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/shared.py +100 -0
  403. mirascope/ops/_internal/instrumentation/llm/llm.py +161 -0
  404. mirascope/ops/_internal/instrumentation/llm/model.py +1798 -0
  405. mirascope/ops/_internal/instrumentation/llm/response.py +521 -0
  406. mirascope/ops/_internal/instrumentation/llm/serialize.py +300 -0
  407. mirascope/ops/_internal/propagation.py +198 -0
  408. mirascope/ops/_internal/protocols.py +133 -0
  409. mirascope/ops/_internal/session.py +139 -0
  410. mirascope/ops/_internal/spans.py +232 -0
  411. mirascope/ops/_internal/traced_calls.py +375 -0
  412. mirascope/ops/_internal/traced_functions.py +523 -0
  413. mirascope/ops/_internal/tracing.py +353 -0
  414. mirascope/ops/_internal/types.py +13 -0
  415. mirascope/ops/_internal/utils.py +123 -0
  416. mirascope/ops/_internal/versioned_calls.py +512 -0
  417. mirascope/ops/_internal/versioned_functions.py +357 -0
  418. mirascope/ops/_internal/versioning.py +303 -0
  419. mirascope/ops/exceptions.py +21 -0
  420. mirascope-2.0.0.dist-info/METADATA +203 -0
  421. mirascope-2.0.0.dist-info/RECORD +423 -0
  422. {mirascope-1.25.7.dist-info → mirascope-2.0.0.dist-info}/WHEEL +1 -1
  423. {mirascope-1.25.7.dist-info → mirascope-2.0.0.dist-info}/licenses/LICENSE +1 -1
  424. mirascope/beta/__init__.py +0 -3
  425. mirascope/beta/openai/__init__.py +0 -17
  426. mirascope/beta/openai/realtime/__init__.py +0 -13
  427. mirascope/beta/openai/realtime/_utils/__init__.py +0 -3
  428. mirascope/beta/openai/realtime/_utils/_audio.py +0 -74
  429. mirascope/beta/openai/realtime/_utils/_protocols.py +0 -50
  430. mirascope/beta/openai/realtime/realtime.py +0 -500
  431. mirascope/beta/openai/realtime/recording.py +0 -98
  432. mirascope/beta/openai/realtime/tool.py +0 -113
  433. mirascope/beta/rag/__init__.py +0 -24
  434. mirascope/beta/rag/base/__init__.py +0 -22
  435. mirascope/beta/rag/base/chunkers/__init__.py +0 -2
  436. mirascope/beta/rag/base/chunkers/base_chunker.py +0 -37
  437. mirascope/beta/rag/base/chunkers/text_chunker.py +0 -33
  438. mirascope/beta/rag/base/config.py +0 -8
  439. mirascope/beta/rag/base/document.py +0 -11
  440. mirascope/beta/rag/base/embedders.py +0 -35
  441. mirascope/beta/rag/base/embedding_params.py +0 -18
  442. mirascope/beta/rag/base/embedding_response.py +0 -30
  443. mirascope/beta/rag/base/query_results.py +0 -7
  444. mirascope/beta/rag/base/vectorstore_params.py +0 -18
  445. mirascope/beta/rag/base/vectorstores.py +0 -37
  446. mirascope/beta/rag/chroma/__init__.py +0 -11
  447. mirascope/beta/rag/chroma/types.py +0 -62
  448. mirascope/beta/rag/chroma/vectorstores.py +0 -121
  449. mirascope/beta/rag/cohere/__init__.py +0 -11
  450. mirascope/beta/rag/cohere/embedders.py +0 -87
  451. mirascope/beta/rag/cohere/embedding_params.py +0 -29
  452. mirascope/beta/rag/cohere/embedding_response.py +0 -29
  453. mirascope/beta/rag/cohere/py.typed +0 -0
  454. mirascope/beta/rag/openai/__init__.py +0 -11
  455. mirascope/beta/rag/openai/embedders.py +0 -144
  456. mirascope/beta/rag/openai/embedding_params.py +0 -18
  457. mirascope/beta/rag/openai/embedding_response.py +0 -14
  458. mirascope/beta/rag/openai/py.typed +0 -0
  459. mirascope/beta/rag/pinecone/__init__.py +0 -19
  460. mirascope/beta/rag/pinecone/types.py +0 -143
  461. mirascope/beta/rag/pinecone/vectorstores.py +0 -148
  462. mirascope/beta/rag/weaviate/__init__.py +0 -6
  463. mirascope/beta/rag/weaviate/types.py +0 -92
  464. mirascope/beta/rag/weaviate/vectorstores.py +0 -103
  465. mirascope/core/__init__.py +0 -109
  466. mirascope/core/anthropic/__init__.py +0 -31
  467. mirascope/core/anthropic/_call.py +0 -67
  468. mirascope/core/anthropic/_call_kwargs.py +0 -13
  469. mirascope/core/anthropic/_thinking.py +0 -70
  470. mirascope/core/anthropic/_utils/__init__.py +0 -16
  471. mirascope/core/anthropic/_utils/_convert_common_call_params.py +0 -25
  472. mirascope/core/anthropic/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -21
  473. mirascope/core/anthropic/_utils/_convert_message_params.py +0 -102
  474. mirascope/core/anthropic/_utils/_get_json_output.py +0 -31
  475. mirascope/core/anthropic/_utils/_handle_stream.py +0 -113
  476. mirascope/core/anthropic/_utils/_message_param_converter.py +0 -154
  477. mirascope/core/anthropic/_utils/_setup_call.py +0 -146
  478. mirascope/core/anthropic/call_params.py +0 -44
  479. mirascope/core/anthropic/call_response.py +0 -226
  480. mirascope/core/anthropic/call_response_chunk.py +0 -152
  481. mirascope/core/anthropic/dynamic_config.py +0 -40
  482. mirascope/core/anthropic/py.typed +0 -0
  483. mirascope/core/anthropic/stream.py +0 -204
  484. mirascope/core/anthropic/tool.py +0 -101
  485. mirascope/core/azure/__init__.py +0 -31
  486. mirascope/core/azure/_call.py +0 -67
  487. mirascope/core/azure/_call_kwargs.py +0 -13
  488. mirascope/core/azure/_utils/__init__.py +0 -14
  489. mirascope/core/azure/_utils/_convert_common_call_params.py +0 -26
  490. mirascope/core/azure/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -21
  491. mirascope/core/azure/_utils/_convert_message_params.py +0 -121
  492. mirascope/core/azure/_utils/_get_credential.py +0 -33
  493. mirascope/core/azure/_utils/_get_json_output.py +0 -27
  494. mirascope/core/azure/_utils/_handle_stream.py +0 -130
  495. mirascope/core/azure/_utils/_message_param_converter.py +0 -117
  496. mirascope/core/azure/_utils/_setup_call.py +0 -183
  497. mirascope/core/azure/call_params.py +0 -59
  498. mirascope/core/azure/call_response.py +0 -215
  499. mirascope/core/azure/call_response_chunk.py +0 -105
  500. mirascope/core/azure/dynamic_config.py +0 -30
  501. mirascope/core/azure/py.typed +0 -0
  502. mirascope/core/azure/stream.py +0 -147
  503. mirascope/core/azure/tool.py +0 -93
  504. mirascope/core/base/__init__.py +0 -86
  505. mirascope/core/base/_call_factory.py +0 -256
  506. mirascope/core/base/_create.py +0 -253
  507. mirascope/core/base/_extract.py +0 -175
  508. mirascope/core/base/_extract_with_tools.py +0 -189
  509. mirascope/core/base/_partial.py +0 -95
  510. mirascope/core/base/_utils/__init__.py +0 -92
  511. mirascope/core/base/_utils/_base_message_param_converter.py +0 -22
  512. mirascope/core/base/_utils/_base_type.py +0 -26
  513. mirascope/core/base/_utils/_convert_base_model_to_base_tool.py +0 -48
  514. mirascope/core/base/_utils/_convert_base_type_to_base_tool.py +0 -24
  515. mirascope/core/base/_utils/_convert_function_to_base_tool.py +0 -139
  516. mirascope/core/base/_utils/_convert_messages_to_message_params.py +0 -178
  517. mirascope/core/base/_utils/_convert_provider_finish_reason_to_finish_reason.py +0 -20
  518. mirascope/core/base/_utils/_default_tool_docstring.py +0 -6
  519. mirascope/core/base/_utils/_extract_tool_return.py +0 -42
  520. mirascope/core/base/_utils/_fn_is_async.py +0 -24
  521. mirascope/core/base/_utils/_format_template.py +0 -32
  522. mirascope/core/base/_utils/_get_audio_type.py +0 -18
  523. mirascope/core/base/_utils/_get_common_usage.py +0 -20
  524. mirascope/core/base/_utils/_get_create_fn_or_async_create_fn.py +0 -137
  525. mirascope/core/base/_utils/_get_document_type.py +0 -7
  526. mirascope/core/base/_utils/_get_dynamic_configuration.py +0 -69
  527. mirascope/core/base/_utils/_get_fields_from_call_args.py +0 -34
  528. mirascope/core/base/_utils/_get_fn_args.py +0 -23
  529. mirascope/core/base/_utils/_get_image_dimensions.py +0 -39
  530. mirascope/core/base/_utils/_get_image_type.py +0 -26
  531. mirascope/core/base/_utils/_get_metadata.py +0 -17
  532. mirascope/core/base/_utils/_get_possible_user_message_param.py +0 -21
  533. mirascope/core/base/_utils/_get_prompt_template.py +0 -28
  534. mirascope/core/base/_utils/_get_template_values.py +0 -51
  535. mirascope/core/base/_utils/_get_template_variables.py +0 -38
  536. mirascope/core/base/_utils/_get_unsupported_tool_config_keys.py +0 -10
  537. mirascope/core/base/_utils/_is_prompt_template.py +0 -24
  538. mirascope/core/base/_utils/_json_mode_content.py +0 -17
  539. mirascope/core/base/_utils/_messages_decorator.py +0 -121
  540. mirascope/core/base/_utils/_parse_content_template.py +0 -323
  541. mirascope/core/base/_utils/_parse_prompt_messages.py +0 -63
  542. mirascope/core/base/_utils/_pil_image_to_bytes.py +0 -13
  543. mirascope/core/base/_utils/_protocols.py +0 -901
  544. mirascope/core/base/_utils/_setup_call.py +0 -79
  545. mirascope/core/base/_utils/_setup_extract_tool.py +0 -30
  546. mirascope/core/base/call_kwargs.py +0 -13
  547. mirascope/core/base/call_params.py +0 -36
  548. mirascope/core/base/call_response.py +0 -338
  549. mirascope/core/base/call_response_chunk.py +0 -130
  550. mirascope/core/base/dynamic_config.py +0 -82
  551. mirascope/core/base/from_call_args.py +0 -30
  552. mirascope/core/base/merge_decorators.py +0 -59
  553. mirascope/core/base/message_param.py +0 -175
  554. mirascope/core/base/messages.py +0 -116
  555. mirascope/core/base/metadata.py +0 -13
  556. mirascope/core/base/prompt.py +0 -497
  557. mirascope/core/base/response_model_config_dict.py +0 -9
  558. mirascope/core/base/stream.py +0 -479
  559. mirascope/core/base/stream_config.py +0 -11
  560. mirascope/core/base/structured_stream.py +0 -296
  561. mirascope/core/base/tool.py +0 -214
  562. mirascope/core/base/toolkit.py +0 -176
  563. mirascope/core/base/types.py +0 -344
  564. mirascope/core/bedrock/__init__.py +0 -34
  565. mirascope/core/bedrock/_call.py +0 -68
  566. mirascope/core/bedrock/_call_kwargs.py +0 -12
  567. mirascope/core/bedrock/_types.py +0 -104
  568. mirascope/core/bedrock/_utils/__init__.py +0 -14
  569. mirascope/core/bedrock/_utils/_convert_common_call_params.py +0 -39
  570. mirascope/core/bedrock/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -23
  571. mirascope/core/bedrock/_utils/_convert_message_params.py +0 -111
  572. mirascope/core/bedrock/_utils/_get_json_output.py +0 -30
  573. mirascope/core/bedrock/_utils/_handle_stream.py +0 -104
  574. mirascope/core/bedrock/_utils/_message_param_converter.py +0 -172
  575. mirascope/core/bedrock/_utils/_setup_call.py +0 -258
  576. mirascope/core/bedrock/call_params.py +0 -38
  577. mirascope/core/bedrock/call_response.py +0 -248
  578. mirascope/core/bedrock/call_response_chunk.py +0 -111
  579. mirascope/core/bedrock/dynamic_config.py +0 -37
  580. mirascope/core/bedrock/py.typed +0 -0
  581. mirascope/core/bedrock/stream.py +0 -154
  582. mirascope/core/bedrock/tool.py +0 -100
  583. mirascope/core/cohere/__init__.py +0 -30
  584. mirascope/core/cohere/_call.py +0 -67
  585. mirascope/core/cohere/_call_kwargs.py +0 -11
  586. mirascope/core/cohere/_types.py +0 -20
  587. mirascope/core/cohere/_utils/__init__.py +0 -14
  588. mirascope/core/cohere/_utils/_convert_common_call_params.py +0 -26
  589. mirascope/core/cohere/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -24
  590. mirascope/core/cohere/_utils/_convert_message_params.py +0 -32
  591. mirascope/core/cohere/_utils/_get_json_output.py +0 -30
  592. mirascope/core/cohere/_utils/_handle_stream.py +0 -35
  593. mirascope/core/cohere/_utils/_message_param_converter.py +0 -54
  594. mirascope/core/cohere/_utils/_setup_call.py +0 -150
  595. mirascope/core/cohere/call_params.py +0 -62
  596. mirascope/core/cohere/call_response.py +0 -205
  597. mirascope/core/cohere/call_response_chunk.py +0 -125
  598. mirascope/core/cohere/dynamic_config.py +0 -32
  599. mirascope/core/cohere/py.typed +0 -0
  600. mirascope/core/cohere/stream.py +0 -113
  601. mirascope/core/cohere/tool.py +0 -93
  602. mirascope/core/costs/__init__.py +0 -5
  603. mirascope/core/costs/_anthropic_calculate_cost.py +0 -219
  604. mirascope/core/costs/_azure_calculate_cost.py +0 -11
  605. mirascope/core/costs/_bedrock_calculate_cost.py +0 -15
  606. mirascope/core/costs/_cohere_calculate_cost.py +0 -44
  607. mirascope/core/costs/_gemini_calculate_cost.py +0 -67
  608. mirascope/core/costs/_google_calculate_cost.py +0 -427
  609. mirascope/core/costs/_groq_calculate_cost.py +0 -156
  610. mirascope/core/costs/_litellm_calculate_cost.py +0 -11
  611. mirascope/core/costs/_mistral_calculate_cost.py +0 -64
  612. mirascope/core/costs/_openai_calculate_cost.py +0 -416
  613. mirascope/core/costs/_vertex_calculate_cost.py +0 -67
  614. mirascope/core/costs/_xai_calculate_cost.py +0 -104
  615. mirascope/core/costs/calculate_cost.py +0 -86
  616. mirascope/core/gemini/__init__.py +0 -40
  617. mirascope/core/gemini/_call.py +0 -67
  618. mirascope/core/gemini/_call_kwargs.py +0 -12
  619. mirascope/core/gemini/_utils/__init__.py +0 -14
  620. mirascope/core/gemini/_utils/_convert_common_call_params.py +0 -39
  621. mirascope/core/gemini/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -23
  622. mirascope/core/gemini/_utils/_convert_message_params.py +0 -156
  623. mirascope/core/gemini/_utils/_get_json_output.py +0 -35
  624. mirascope/core/gemini/_utils/_handle_stream.py +0 -33
  625. mirascope/core/gemini/_utils/_message_param_converter.py +0 -209
  626. mirascope/core/gemini/_utils/_setup_call.py +0 -149
  627. mirascope/core/gemini/call_params.py +0 -52
  628. mirascope/core/gemini/call_response.py +0 -216
  629. mirascope/core/gemini/call_response_chunk.py +0 -100
  630. mirascope/core/gemini/dynamic_config.py +0 -26
  631. mirascope/core/gemini/stream.py +0 -120
  632. mirascope/core/gemini/tool.py +0 -104
  633. mirascope/core/google/__init__.py +0 -29
  634. mirascope/core/google/_call.py +0 -67
  635. mirascope/core/google/_call_kwargs.py +0 -13
  636. mirascope/core/google/_utils/__init__.py +0 -14
  637. mirascope/core/google/_utils/_convert_common_call_params.py +0 -38
  638. mirascope/core/google/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -27
  639. mirascope/core/google/_utils/_convert_message_params.py +0 -297
  640. mirascope/core/google/_utils/_get_json_output.py +0 -37
  641. mirascope/core/google/_utils/_handle_stream.py +0 -58
  642. mirascope/core/google/_utils/_message_param_converter.py +0 -200
  643. mirascope/core/google/_utils/_setup_call.py +0 -201
  644. mirascope/core/google/_utils/_validate_media_type.py +0 -58
  645. mirascope/core/google/call_params.py +0 -22
  646. mirascope/core/google/call_response.py +0 -255
  647. mirascope/core/google/call_response_chunk.py +0 -135
  648. mirascope/core/google/dynamic_config.py +0 -26
  649. mirascope/core/google/stream.py +0 -199
  650. mirascope/core/google/tool.py +0 -146
  651. mirascope/core/groq/__init__.py +0 -30
  652. mirascope/core/groq/_call.py +0 -67
  653. mirascope/core/groq/_call_kwargs.py +0 -13
  654. mirascope/core/groq/_utils/__init__.py +0 -14
  655. mirascope/core/groq/_utils/_convert_common_call_params.py +0 -26
  656. mirascope/core/groq/_utils/_convert_message_params.py +0 -112
  657. mirascope/core/groq/_utils/_get_json_output.py +0 -27
  658. mirascope/core/groq/_utils/_handle_stream.py +0 -123
  659. mirascope/core/groq/_utils/_message_param_converter.py +0 -89
  660. mirascope/core/groq/_utils/_setup_call.py +0 -132
  661. mirascope/core/groq/call_params.py +0 -52
  662. mirascope/core/groq/call_response.py +0 -213
  663. mirascope/core/groq/call_response_chunk.py +0 -104
  664. mirascope/core/groq/dynamic_config.py +0 -29
  665. mirascope/core/groq/py.typed +0 -0
  666. mirascope/core/groq/stream.py +0 -135
  667. mirascope/core/groq/tool.py +0 -80
  668. mirascope/core/litellm/__init__.py +0 -28
  669. mirascope/core/litellm/_call.py +0 -67
  670. mirascope/core/litellm/_utils/__init__.py +0 -5
  671. mirascope/core/litellm/_utils/_setup_call.py +0 -109
  672. mirascope/core/litellm/call_params.py +0 -10
  673. mirascope/core/litellm/call_response.py +0 -24
  674. mirascope/core/litellm/call_response_chunk.py +0 -14
  675. mirascope/core/litellm/dynamic_config.py +0 -8
  676. mirascope/core/litellm/py.typed +0 -0
  677. mirascope/core/litellm/stream.py +0 -86
  678. mirascope/core/litellm/tool.py +0 -13
  679. mirascope/core/mistral/__init__.py +0 -36
  680. mirascope/core/mistral/_call.py +0 -65
  681. mirascope/core/mistral/_call_kwargs.py +0 -19
  682. mirascope/core/mistral/_utils/__init__.py +0 -14
  683. mirascope/core/mistral/_utils/_convert_common_call_params.py +0 -24
  684. mirascope/core/mistral/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -22
  685. mirascope/core/mistral/_utils/_convert_message_params.py +0 -122
  686. mirascope/core/mistral/_utils/_get_json_output.py +0 -34
  687. mirascope/core/mistral/_utils/_handle_stream.py +0 -139
  688. mirascope/core/mistral/_utils/_message_param_converter.py +0 -176
  689. mirascope/core/mistral/_utils/_setup_call.py +0 -164
  690. mirascope/core/mistral/call_params.py +0 -36
  691. mirascope/core/mistral/call_response.py +0 -205
  692. mirascope/core/mistral/call_response_chunk.py +0 -105
  693. mirascope/core/mistral/dynamic_config.py +0 -33
  694. mirascope/core/mistral/py.typed +0 -0
  695. mirascope/core/mistral/stream.py +0 -120
  696. mirascope/core/mistral/tool.py +0 -81
  697. mirascope/core/openai/__init__.py +0 -31
  698. mirascope/core/openai/_call.py +0 -67
  699. mirascope/core/openai/_call_kwargs.py +0 -13
  700. mirascope/core/openai/_utils/__init__.py +0 -14
  701. mirascope/core/openai/_utils/_convert_common_call_params.py +0 -26
  702. mirascope/core/openai/_utils/_convert_message_params.py +0 -148
  703. mirascope/core/openai/_utils/_get_json_output.py +0 -31
  704. mirascope/core/openai/_utils/_handle_stream.py +0 -138
  705. mirascope/core/openai/_utils/_message_param_converter.py +0 -105
  706. mirascope/core/openai/_utils/_setup_call.py +0 -155
  707. mirascope/core/openai/call_params.py +0 -92
  708. mirascope/core/openai/call_response.py +0 -273
  709. mirascope/core/openai/call_response_chunk.py +0 -139
  710. mirascope/core/openai/dynamic_config.py +0 -34
  711. mirascope/core/openai/py.typed +0 -0
  712. mirascope/core/openai/stream.py +0 -185
  713. mirascope/core/openai/tool.py +0 -101
  714. mirascope/core/py.typed +0 -0
  715. mirascope/core/vertex/__init__.py +0 -45
  716. mirascope/core/vertex/_call.py +0 -62
  717. mirascope/core/vertex/_call_kwargs.py +0 -12
  718. mirascope/core/vertex/_utils/__init__.py +0 -14
  719. mirascope/core/vertex/_utils/_convert_common_call_params.py +0 -37
  720. mirascope/core/vertex/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -23
  721. mirascope/core/vertex/_utils/_convert_message_params.py +0 -171
  722. mirascope/core/vertex/_utils/_get_json_output.py +0 -36
  723. mirascope/core/vertex/_utils/_handle_stream.py +0 -33
  724. mirascope/core/vertex/_utils/_message_param_converter.py +0 -133
  725. mirascope/core/vertex/_utils/_setup_call.py +0 -160
  726. mirascope/core/vertex/call_params.py +0 -24
  727. mirascope/core/vertex/call_response.py +0 -206
  728. mirascope/core/vertex/call_response_chunk.py +0 -99
  729. mirascope/core/vertex/dynamic_config.py +0 -28
  730. mirascope/core/vertex/stream.py +0 -119
  731. mirascope/core/vertex/tool.py +0 -101
  732. mirascope/core/xai/__init__.py +0 -28
  733. mirascope/core/xai/_call.py +0 -67
  734. mirascope/core/xai/_utils/__init__.py +0 -5
  735. mirascope/core/xai/_utils/_setup_call.py +0 -113
  736. mirascope/core/xai/call_params.py +0 -10
  737. mirascope/core/xai/call_response.py +0 -16
  738. mirascope/core/xai/call_response_chunk.py +0 -14
  739. mirascope/core/xai/dynamic_config.py +0 -8
  740. mirascope/core/xai/py.typed +0 -0
  741. mirascope/core/xai/stream.py +0 -57
  742. mirascope/core/xai/tool.py +0 -13
  743. mirascope/experimental/graphs/__init__.py +0 -5
  744. mirascope/experimental/graphs/finite_state_machine.py +0 -714
  745. mirascope/integrations/__init__.py +0 -16
  746. mirascope/integrations/_middleware_factory.py +0 -403
  747. mirascope/integrations/langfuse/__init__.py +0 -3
  748. mirascope/integrations/langfuse/_utils.py +0 -114
  749. mirascope/integrations/langfuse/_with_langfuse.py +0 -70
  750. mirascope/integrations/logfire/__init__.py +0 -3
  751. mirascope/integrations/logfire/_utils.py +0 -225
  752. mirascope/integrations/logfire/_with_logfire.py +0 -63
  753. mirascope/integrations/otel/__init__.py +0 -10
  754. mirascope/integrations/otel/_utils.py +0 -270
  755. mirascope/integrations/otel/_with_hyperdx.py +0 -60
  756. mirascope/integrations/otel/_with_otel.py +0 -59
  757. mirascope/integrations/tenacity.py +0 -14
  758. mirascope/llm/_call.py +0 -401
  759. mirascope/llm/_context.py +0 -384
  760. mirascope/llm/_override.py +0 -3639
  761. mirascope/llm/_protocols.py +0 -500
  762. mirascope/llm/_response_metaclass.py +0 -31
  763. mirascope/llm/call_response.py +0 -158
  764. mirascope/llm/call_response_chunk.py +0 -66
  765. mirascope/llm/stream.py +0 -162
  766. mirascope/llm/tool.py +0 -64
  767. mirascope/mcp/__init__.py +0 -7
  768. mirascope/mcp/_utils.py +0 -288
  769. mirascope/mcp/client.py +0 -167
  770. mirascope/mcp/server.py +0 -356
  771. mirascope/mcp/tools.py +0 -110
  772. mirascope/py.typed +0 -0
  773. mirascope/retries/__init__.py +0 -11
  774. mirascope/retries/fallback.py +0 -131
  775. mirascope/retries/tenacity.py +0 -50
  776. mirascope/tools/__init__.py +0 -37
  777. mirascope/tools/base.py +0 -98
  778. mirascope/tools/system/__init__.py +0 -0
  779. mirascope/tools/system/_docker_operation.py +0 -166
  780. mirascope/tools/system/_file_system.py +0 -267
  781. mirascope/tools/web/__init__.py +0 -0
  782. mirascope/tools/web/_duckduckgo.py +0 -111
  783. mirascope/tools/web/_httpx.py +0 -125
  784. mirascope/tools/web/_parse_url_content.py +0 -94
  785. mirascope/tools/web/_requests.py +0 -54
  786. mirascope/v0/__init__.py +0 -43
  787. mirascope/v0/anthropic.py +0 -54
  788. mirascope/v0/base/__init__.py +0 -12
  789. mirascope/v0/base/calls.py +0 -118
  790. mirascope/v0/base/extractors.py +0 -122
  791. mirascope/v0/base/ops_utils.py +0 -207
  792. mirascope/v0/base/prompts.py +0 -48
  793. mirascope/v0/base/types.py +0 -14
  794. mirascope/v0/base/utils.py +0 -21
  795. mirascope/v0/openai.py +0 -54
  796. mirascope-1.25.7.dist-info/METADATA +0 -169
  797. mirascope-1.25.7.dist-info/RECORD +0 -378
@@ -0,0 +1,1579 @@
1
+ """Base abstract interface for provider clients."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from abc import ABC, abstractmethod
6
+ from collections.abc import Callable, Generator, Mapping, Sequence
7
+ from contextlib import contextmanager
8
+ from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypeAlias, cast, overload
9
+ from typing_extensions import TypeVar, Unpack
10
+
11
+ from ...context import Context, DepsT
12
+ from ...exceptions import APIError, ProviderError
13
+ from ...formatting import Format, FormattableT, OutputParser
14
+ from ...messages import Message, UserContent, user
15
+ from ...responses import (
16
+ AsyncChunkIterator,
17
+ AsyncContextResponse,
18
+ AsyncContextStreamResponse,
19
+ AsyncResponse,
20
+ AsyncStreamResponse,
21
+ ChunkIterator,
22
+ ContextResponse,
23
+ ContextStreamResponse,
24
+ Response,
25
+ StreamResponse,
26
+ )
27
+ from ...tools import (
28
+ AsyncContextTool,
29
+ AsyncContextToolkit,
30
+ AsyncTool,
31
+ AsyncToolkit,
32
+ ContextTool,
33
+ ContextToolkit,
34
+ Tool,
35
+ Toolkit,
36
+ )
37
+
38
+ if TYPE_CHECKING:
39
+ from ...models import Params
40
+ from ..provider_id import ProviderId
41
+
42
+ ProviderClientT = TypeVar("ProviderClientT")
43
+
44
+ Provider: TypeAlias = "BaseProvider[Any]"
45
+ """Type alias for `BaseProvider` with any client type."""
46
+
47
+ ProviderErrorMap: TypeAlias = Mapping[
48
+ type[Exception],
49
+ "type[ProviderError] | Callable[[Exception], type[ProviderError]]",
50
+ ]
51
+ """Mapping from provider SDK exceptions to Mirascope error types.
52
+
53
+ Keys are provider SDK exception types (e.g., OpenAIError, AnthropicError).
54
+ Values can be:
55
+ - Error type: Simple 1:1 mapping (e.g., RateLimitError)
56
+ - Callable: Transform function returning error type based on exception details
57
+ """
58
+
59
+
60
+ class BaseProvider(Generic[ProviderClientT], ABC):
61
+ """Base abstract provider for LLM interactions.
62
+
63
+ This class defines explicit methods for each type of call, eliminating
64
+ the need for complex overloads in provider implementations.
65
+ """
66
+
67
+ id: ClassVar[ProviderId]
68
+ """Provider identifier (e.g., "anthropic", "openai")."""
69
+
70
+ default_scope: ClassVar[str | list[str]]
71
+ """Default scope(s) for this provider when explicitly registered.
72
+
73
+ Can be a single scope string or a list of scopes. For example:
74
+ - "anthropic/" - Single scope
75
+ - ["anthropic/", "openai/"] - Multiple scopes (e.g., for AWS Bedrock)
76
+ """
77
+
78
+ error_map: ClassVar[ProviderErrorMap]
79
+ """Mapping from provider SDK exceptions to Mirascope error types.
80
+
81
+ Values can be:
82
+ - Error type: Simple 1:1 mapping (e.g., AnthropicRateLimitError -> RateLimitError)
83
+ - Callable: Transform function returning error type based on exception details
84
+ (e.g., lambda e: NotFoundError if e.code == "model_not_found" else BadRequestError)
85
+
86
+ The mapping is walked via the exception's MRO, allowing both specific error handling
87
+ and fallback to base SDK error types (e.g., AnthropicError -> ProviderError).
88
+ """
89
+
90
+ client: ProviderClientT
91
+
92
+ @contextmanager
93
+ def _wrap_errors(self) -> Generator[None, None, None]:
94
+ """Wrap provider API calls and convert errors to Mirascope exceptions.
95
+
96
+ Walks the exception's MRO to find the first matching error type in the
97
+ provider's error_map, allowing both specific error handling and fallback
98
+ to base SDK error types (e.g., AnthropicError -> ProviderError).
99
+ """
100
+ try:
101
+ yield
102
+ except Exception as e:
103
+ # Walk MRO to find first matching error type in provider's error_map
104
+ for error_class in type(e).__mro__:
105
+ if error_class in self.error_map:
106
+ error_type_or_fn = self.error_map[error_class]
107
+
108
+ if isinstance(error_type_or_fn, type):
109
+ error_type = cast(type[ProviderError], error_type_or_fn)
110
+ else:
111
+ error_type = error_type_or_fn(e)
112
+
113
+ # Construct Mirascope error with metadata
114
+ if issubclass(error_type, APIError):
115
+ error: ProviderError = error_type(
116
+ str(e),
117
+ provider=self.id,
118
+ status_code=self.get_error_status(e),
119
+ original_exception=e,
120
+ )
121
+ else:
122
+ error = error_type(
123
+ str(e),
124
+ provider=self.id,
125
+ original_exception=e,
126
+ )
127
+ raise error from e
128
+
129
+ # Not in error_map - not a provider error, re-raise as-is
130
+ raise
131
+
132
+ def _wrap_iterator_errors(self, iterator: ChunkIterator) -> ChunkIterator:
133
+ """Wrap sync chunk iterator to handle errors during iteration."""
134
+ # TODO: Consider moving this logic into BaseSyncStreamResponse if appropriate.
135
+ with self._wrap_errors():
136
+ yield from iterator
137
+
138
+ async def _wrap_async_iterator_errors(
139
+ self, iterator: AsyncChunkIterator
140
+ ) -> AsyncChunkIterator:
141
+ """Wrap async chunk iterator to handle errors during iteration."""
142
+ # TODO: Consider moving this logic into BaseAsyncStreamResponse if appropriate.
143
+ with self._wrap_errors():
144
+ async for chunk in iterator:
145
+ yield chunk
146
+
147
+ @overload
148
+ def call(
149
+ self,
150
+ *,
151
+ model_id: str,
152
+ messages: Sequence[Message],
153
+ tools: Sequence[Tool] | Toolkit | None = None,
154
+ format: None = None,
155
+ **params: Unpack[Params],
156
+ ) -> Response:
157
+ """Generate an `llm.Response` without a response format."""
158
+ ...
159
+
160
+ @overload
161
+ def call(
162
+ self,
163
+ *,
164
+ model_id: str,
165
+ messages: Sequence[Message],
166
+ tools: Sequence[Tool] | Toolkit | None = None,
167
+ format: type[FormattableT] | Format[FormattableT],
168
+ **params: Unpack[Params],
169
+ ) -> Response[FormattableT]:
170
+ """Generate an `llm.Response` with a response format."""
171
+ ...
172
+
173
+ @overload
174
+ def call(
175
+ self,
176
+ *,
177
+ model_id: str,
178
+ messages: Sequence[Message],
179
+ tools: Sequence[Tool] | Toolkit | None = None,
180
+ format: type[FormattableT]
181
+ | Format[FormattableT]
182
+ | OutputParser[FormattableT]
183
+ | None,
184
+ **params: Unpack[Params],
185
+ ) -> Response | Response[FormattableT]:
186
+ """Generate an `llm.Response` with an optional response format."""
187
+ ...
188
+
189
+ def call(
190
+ self,
191
+ *,
192
+ model_id: str,
193
+ messages: Sequence[Message],
194
+ tools: Sequence[Tool] | Toolkit | None = None,
195
+ format: type[FormattableT]
196
+ | Format[FormattableT]
197
+ | OutputParser[FormattableT]
198
+ | None = None,
199
+ **params: Unpack[Params],
200
+ ) -> Response | Response[FormattableT]:
201
+ """Generate an `llm.Response` by synchronously calling this client's LLM provider.
202
+
203
+ Args:
204
+ model_id: Model identifier to use.
205
+ messages: Messages to send to the LLM.
206
+ tools: Optional tools that the model may invoke.
207
+ format: Optional response format specifier.
208
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
209
+
210
+ Returns:
211
+ An `llm.Response` object containing the LLM-generated content.
212
+ """
213
+ with self._wrap_errors():
214
+ return self._call(
215
+ model_id=model_id,
216
+ messages=messages,
217
+ tools=tools,
218
+ format=format,
219
+ **params,
220
+ )
221
+
222
+ @abstractmethod
223
+ def _call(
224
+ self,
225
+ *,
226
+ model_id: str,
227
+ messages: Sequence[Message],
228
+ tools: Sequence[Tool] | Toolkit | None = None,
229
+ format: type[FormattableT]
230
+ | Format[FormattableT]
231
+ | OutputParser[FormattableT]
232
+ | None = None,
233
+ **params: Unpack[Params],
234
+ ) -> Response | Response[FormattableT]:
235
+ """Implementation for call(). Subclasses override this method."""
236
+ ...
237
+
238
+ @overload
239
+ def context_call(
240
+ self,
241
+ *,
242
+ ctx: Context[DepsT],
243
+ model_id: str,
244
+ messages: Sequence[Message],
245
+ tools: Sequence[Tool | ContextTool[DepsT]]
246
+ | ContextToolkit[DepsT]
247
+ | None = None,
248
+ format: None = None,
249
+ **params: Unpack[Params],
250
+ ) -> ContextResponse[DepsT, None]:
251
+ """Generate an `llm.ContextResponse` without a response format."""
252
+ ...
253
+
254
+ @overload
255
+ def context_call(
256
+ self,
257
+ *,
258
+ ctx: Context[DepsT],
259
+ model_id: str,
260
+ messages: Sequence[Message],
261
+ tools: Sequence[Tool | ContextTool[DepsT]]
262
+ | ContextToolkit[DepsT]
263
+ | None = None,
264
+ format: type[FormattableT] | Format[FormattableT],
265
+ **params: Unpack[Params],
266
+ ) -> ContextResponse[DepsT, FormattableT]:
267
+ """Generate an `llm.ContextResponse` with a response format."""
268
+ ...
269
+
270
+ @overload
271
+ def context_call(
272
+ self,
273
+ *,
274
+ ctx: Context[DepsT],
275
+ model_id: str,
276
+ messages: Sequence[Message],
277
+ tools: Sequence[Tool | ContextTool[DepsT]]
278
+ | ContextToolkit[DepsT]
279
+ | None = None,
280
+ format: type[FormattableT]
281
+ | Format[FormattableT]
282
+ | OutputParser[FormattableT]
283
+ | None,
284
+ **params: Unpack[Params],
285
+ ) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
286
+ """Generate an `llm.ContextResponse` with an optional response format."""
287
+ ...
288
+
289
+ def context_call(
290
+ self,
291
+ *,
292
+ ctx: Context[DepsT],
293
+ model_id: str,
294
+ messages: Sequence[Message],
295
+ tools: Sequence[Tool | ContextTool[DepsT]]
296
+ | ContextToolkit[DepsT]
297
+ | None = None,
298
+ format: type[FormattableT]
299
+ | Format[FormattableT]
300
+ | OutputParser[FormattableT]
301
+ | None = None,
302
+ **params: Unpack[Params],
303
+ ) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
304
+ """Generate an `llm.ContextResponse` by synchronously calling this client's LLM provider.
305
+
306
+ Args:
307
+ ctx: Context object with dependencies for tools.
308
+ model_id: Model identifier to use.
309
+ messages: Messages to send to the LLM.
310
+ tools: Optional tools that the model may invoke.
311
+ format: Optional response format specifier.
312
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
313
+
314
+ Returns:
315
+ An `llm.ContextResponse` object containing the LLM-generated content.
316
+ """
317
+ with self._wrap_errors():
318
+ return self._context_call(
319
+ ctx=ctx,
320
+ model_id=model_id,
321
+ messages=messages,
322
+ tools=tools,
323
+ format=format,
324
+ **params,
325
+ )
326
+
327
+ @abstractmethod
328
+ def _context_call(
329
+ self,
330
+ *,
331
+ ctx: Context[DepsT],
332
+ model_id: str,
333
+ messages: Sequence[Message],
334
+ tools: Sequence[Tool | ContextTool[DepsT]]
335
+ | ContextToolkit[DepsT]
336
+ | None = None,
337
+ format: type[FormattableT]
338
+ | Format[FormattableT]
339
+ | OutputParser[FormattableT]
340
+ | None = None,
341
+ **params: Unpack[Params],
342
+ ) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
343
+ """Implementation for context_call(). Subclasses override this method."""
344
+ ...
345
+
346
+ @overload
347
+ async def call_async(
348
+ self,
349
+ *,
350
+ model_id: str,
351
+ messages: Sequence[Message],
352
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
353
+ format: None = None,
354
+ **params: Unpack[Params],
355
+ ) -> AsyncResponse:
356
+ """Generate an `llm.AsyncResponse` without a response format."""
357
+ ...
358
+
359
+ @overload
360
+ async def call_async(
361
+ self,
362
+ *,
363
+ model_id: str,
364
+ messages: Sequence[Message],
365
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
366
+ format: type[FormattableT] | Format[FormattableT],
367
+ **params: Unpack[Params],
368
+ ) -> AsyncResponse[FormattableT]:
369
+ """Generate an `llm.AsyncResponse` with a response format."""
370
+ ...
371
+
372
+ @overload
373
+ async def call_async(
374
+ self,
375
+ *,
376
+ model_id: str,
377
+ messages: Sequence[Message],
378
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
379
+ format: type[FormattableT]
380
+ | Format[FormattableT]
381
+ | OutputParser[FormattableT]
382
+ | None,
383
+ **params: Unpack[Params],
384
+ ) -> AsyncResponse | AsyncResponse[FormattableT]:
385
+ """Generate an `llm.AsyncResponse` with an optional response format."""
386
+ ...
387
+
388
+ async def call_async(
389
+ self,
390
+ *,
391
+ model_id: str,
392
+ messages: Sequence[Message],
393
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
394
+ format: type[FormattableT]
395
+ | Format[FormattableT]
396
+ | OutputParser[FormattableT]
397
+ | None = None,
398
+ **params: Unpack[Params],
399
+ ) -> AsyncResponse | AsyncResponse[FormattableT]:
400
+ """Generate an `llm.AsyncResponse` by asynchronously calling this client's LLM provider.
401
+
402
+ Args:
403
+ model_id: Model identifier to use.
404
+ messages: Messages to send to the LLM.
405
+ tools: Optional tools that the model may invoke.
406
+ format: Optional response format specifier.
407
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
408
+
409
+ Returns:
410
+ An `llm.AsyncResponse` object containing the LLM-generated content.
411
+ """
412
+ with self._wrap_errors():
413
+ return await self._call_async(
414
+ model_id=model_id,
415
+ messages=messages,
416
+ tools=tools,
417
+ format=format,
418
+ **params,
419
+ )
420
+
421
+ @abstractmethod
422
+ async def _call_async(
423
+ self,
424
+ *,
425
+ model_id: str,
426
+ messages: Sequence[Message],
427
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
428
+ format: type[FormattableT]
429
+ | Format[FormattableT]
430
+ | OutputParser[FormattableT]
431
+ | None = None,
432
+ **params: Unpack[Params],
433
+ ) -> AsyncResponse | AsyncResponse[FormattableT]:
434
+ """Implementation for call_async(). Subclasses override this method."""
435
+ ...
436
+
437
+ @overload
438
+ async def context_call_async(
439
+ self,
440
+ *,
441
+ ctx: Context[DepsT],
442
+ model_id: str,
443
+ messages: Sequence[Message],
444
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
445
+ | AsyncContextToolkit[DepsT]
446
+ | None = None,
447
+ format: None = None,
448
+ **params: Unpack[Params],
449
+ ) -> AsyncContextResponse[DepsT, None]:
450
+ """Generate an `llm.AsyncContextResponse` without a response format."""
451
+ ...
452
+
453
+ @overload
454
+ async def context_call_async(
455
+ self,
456
+ *,
457
+ ctx: Context[DepsT],
458
+ model_id: str,
459
+ messages: Sequence[Message],
460
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
461
+ | AsyncContextToolkit[DepsT]
462
+ | None = None,
463
+ format: type[FormattableT] | Format[FormattableT],
464
+ **params: Unpack[Params],
465
+ ) -> AsyncContextResponse[DepsT, FormattableT]:
466
+ """Generate an `llm.AsyncContextResponse` with a response format."""
467
+ ...
468
+
469
+ @overload
470
+ async def context_call_async(
471
+ self,
472
+ *,
473
+ ctx: Context[DepsT],
474
+ model_id: str,
475
+ messages: Sequence[Message],
476
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
477
+ | AsyncContextToolkit[DepsT]
478
+ | None = None,
479
+ format: type[FormattableT]
480
+ | Format[FormattableT]
481
+ | OutputParser[FormattableT]
482
+ | None,
483
+ **params: Unpack[Params],
484
+ ) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
485
+ """Generate an `llm.AsyncContextResponse` with an optional response format."""
486
+ ...
487
+
488
+ async def context_call_async(
489
+ self,
490
+ *,
491
+ ctx: Context[DepsT],
492
+ model_id: str,
493
+ messages: Sequence[Message],
494
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
495
+ | AsyncContextToolkit[DepsT]
496
+ | None = None,
497
+ format: type[FormattableT]
498
+ | Format[FormattableT]
499
+ | OutputParser[FormattableT]
500
+ | None = None,
501
+ **params: Unpack[Params],
502
+ ) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
503
+ """Generate an `llm.AsyncContextResponse` by asynchronously calling this client's LLM provider.
504
+
505
+ Args:
506
+ ctx: Context object with dependencies for tools.
507
+ model_id: Model identifier to use.
508
+ messages: Messages to send to the LLM.
509
+ tools: Optional tools that the model may invoke.
510
+ format: Optional response format specifier.
511
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
512
+
513
+ Returns:
514
+ An `llm.AsyncContextResponse` object containing the LLM-generated content.
515
+ """
516
+ with self._wrap_errors():
517
+ return await self._context_call_async(
518
+ ctx=ctx,
519
+ model_id=model_id,
520
+ messages=messages,
521
+ tools=tools,
522
+ format=format,
523
+ **params,
524
+ )
525
+
526
+ @abstractmethod
527
+ async def _context_call_async(
528
+ self,
529
+ *,
530
+ ctx: Context[DepsT],
531
+ model_id: str,
532
+ messages: Sequence[Message],
533
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
534
+ | AsyncContextToolkit[DepsT]
535
+ | None = None,
536
+ format: type[FormattableT]
537
+ | Format[FormattableT]
538
+ | OutputParser[FormattableT]
539
+ | None = None,
540
+ **params: Unpack[Params],
541
+ ) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
542
+ """Implementation for context_call_async(). Subclasses override this method."""
543
+ ...
544
+
545
+ @overload
546
+ def stream(
547
+ self,
548
+ *,
549
+ model_id: str,
550
+ messages: Sequence[Message],
551
+ tools: Sequence[Tool] | Toolkit | None = None,
552
+ format: None = None,
553
+ **params: Unpack[Params],
554
+ ) -> StreamResponse:
555
+ """Stream an `llm.StreamResponse` without a response format."""
556
+ ...
557
+
558
+ @overload
559
+ def stream(
560
+ self,
561
+ *,
562
+ model_id: str,
563
+ messages: Sequence[Message],
564
+ tools: Sequence[Tool] | Toolkit | None = None,
565
+ format: type[FormattableT] | Format[FormattableT],
566
+ **params: Unpack[Params],
567
+ ) -> StreamResponse[FormattableT]:
568
+ """Stream an `llm.StreamResponse` with a response format."""
569
+ ...
570
+
571
+ @overload
572
+ def stream(
573
+ self,
574
+ *,
575
+ model_id: str,
576
+ messages: Sequence[Message],
577
+ tools: Sequence[Tool] | Toolkit | None = None,
578
+ format: type[FormattableT]
579
+ | Format[FormattableT]
580
+ | OutputParser[FormattableT]
581
+ | None,
582
+ **params: Unpack[Params],
583
+ ) -> StreamResponse | StreamResponse[FormattableT]:
584
+ """Stream an `llm.StreamResponse` with an optional response format."""
585
+ ...
586
+
587
+ def stream(
588
+ self,
589
+ *,
590
+ model_id: str,
591
+ messages: Sequence[Message],
592
+ tools: Sequence[Tool] | Toolkit | None = None,
593
+ format: type[FormattableT]
594
+ | Format[FormattableT]
595
+ | OutputParser[FormattableT]
596
+ | None = None,
597
+ **params: Unpack[Params],
598
+ ) -> StreamResponse | StreamResponse[FormattableT]:
599
+ """Generate an `llm.StreamResponse` by synchronously streaming from this client's LLM provider.
600
+
601
+ Args:
602
+ model_id: Model identifier to use.
603
+ messages: Messages to send to the LLM.
604
+ tools: Optional tools that the model may invoke.
605
+ format: Optional response format specifier.
606
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
607
+
608
+ Returns:
609
+ An `llm.StreamResponse` object for iterating over the LLM-generated content.
610
+ """
611
+ with self._wrap_errors():
612
+ stream_response = self._stream(
613
+ model_id=model_id,
614
+ messages=messages,
615
+ tools=tools,
616
+ format=format,
617
+ **params,
618
+ )
619
+ stream_response._chunk_iterator = self._wrap_iterator_errors( # pyright: ignore[reportPrivateUsage]
620
+ stream_response._chunk_iterator # pyright: ignore[reportPrivateUsage]
621
+ )
622
+ return stream_response
623
+
624
+ @abstractmethod
625
+ def _stream(
626
+ self,
627
+ *,
628
+ model_id: str,
629
+ messages: Sequence[Message],
630
+ tools: Sequence[Tool] | Toolkit | None = None,
631
+ format: type[FormattableT]
632
+ | Format[FormattableT]
633
+ | OutputParser[FormattableT]
634
+ | None = None,
635
+ **params: Unpack[Params],
636
+ ) -> StreamResponse | StreamResponse[FormattableT]:
637
+ """Implementation for stream(). Subclasses override this method."""
638
+ ...
639
+
640
+ @overload
641
+ def context_stream(
642
+ self,
643
+ *,
644
+ ctx: Context[DepsT],
645
+ model_id: str,
646
+ messages: Sequence[Message],
647
+ tools: Sequence[Tool | ContextTool[DepsT]]
648
+ | ContextToolkit[DepsT]
649
+ | None = None,
650
+ format: None = None,
651
+ **params: Unpack[Params],
652
+ ) -> ContextStreamResponse[DepsT, None]:
653
+ """Stream an `llm.ContextStreamResponse` without a response format."""
654
+ ...
655
+
656
+ @overload
657
+ def context_stream(
658
+ self,
659
+ *,
660
+ ctx: Context[DepsT],
661
+ model_id: str,
662
+ messages: Sequence[Message],
663
+ tools: Sequence[Tool | ContextTool[DepsT]]
664
+ | ContextToolkit[DepsT]
665
+ | None = None,
666
+ format: type[FormattableT] | Format[FormattableT],
667
+ **params: Unpack[Params],
668
+ ) -> ContextStreamResponse[DepsT, FormattableT]:
669
+ """Stream an `llm.ContextStreamResponse` with a response format."""
670
+ ...
671
+
672
+ @overload
673
+ def context_stream(
674
+ self,
675
+ *,
676
+ ctx: Context[DepsT],
677
+ model_id: str,
678
+ messages: Sequence[Message],
679
+ tools: Sequence[Tool | ContextTool[DepsT]]
680
+ | ContextToolkit[DepsT]
681
+ | None = None,
682
+ format: type[FormattableT]
683
+ | Format[FormattableT]
684
+ | OutputParser[FormattableT]
685
+ | None,
686
+ **params: Unpack[Params],
687
+ ) -> (
688
+ ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
689
+ ):
690
+ """Stream an `llm.ContextStreamResponse` with an optional response format."""
691
+ ...
692
+
693
+ def context_stream(
694
+ self,
695
+ *,
696
+ ctx: Context[DepsT],
697
+ model_id: str,
698
+ messages: Sequence[Message],
699
+ tools: Sequence[Tool | ContextTool[DepsT]]
700
+ | ContextToolkit[DepsT]
701
+ | None = None,
702
+ format: type[FormattableT]
703
+ | Format[FormattableT]
704
+ | OutputParser[FormattableT]
705
+ | None = None,
706
+ **params: Unpack[Params],
707
+ ) -> (
708
+ ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
709
+ ):
710
+ """Generate an `llm.ContextStreamResponse` by synchronously streaming from this client's LLM provider.
711
+
712
+ Args:
713
+ ctx: Context object with dependencies for tools.
714
+ model_id: Model identifier to use.
715
+ messages: Messages to send to the LLM.
716
+ tools: Optional tools that the model may invoke.
717
+ format: Optional response format specifier.
718
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
719
+
720
+ Returns:
721
+ An `llm.ContextStreamResponse` object for iterating over the LLM-generated content.
722
+ """
723
+ with self._wrap_errors():
724
+ stream_response = self._context_stream(
725
+ ctx=ctx,
726
+ model_id=model_id,
727
+ messages=messages,
728
+ tools=tools,
729
+ format=format,
730
+ **params,
731
+ )
732
+ stream_response._chunk_iterator = self._wrap_iterator_errors( # pyright: ignore[reportPrivateUsage]
733
+ stream_response._chunk_iterator # pyright: ignore[reportPrivateUsage]
734
+ )
735
+ return stream_response
736
+
737
+ @abstractmethod
738
+ def _context_stream(
739
+ self,
740
+ *,
741
+ ctx: Context[DepsT],
742
+ model_id: str,
743
+ messages: Sequence[Message],
744
+ tools: Sequence[Tool | ContextTool[DepsT]]
745
+ | ContextToolkit[DepsT]
746
+ | None = None,
747
+ format: type[FormattableT]
748
+ | Format[FormattableT]
749
+ | OutputParser[FormattableT]
750
+ | None = None,
751
+ **params: Unpack[Params],
752
+ ) -> (
753
+ ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
754
+ ):
755
+ """Implementation for context_stream(). Subclasses override this method."""
756
+ ...
757
+
758
+ @overload
759
+ async def stream_async(
760
+ self,
761
+ *,
762
+ model_id: str,
763
+ messages: Sequence[Message],
764
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
765
+ format: None = None,
766
+ **params: Unpack[Params],
767
+ ) -> AsyncStreamResponse:
768
+ """Stream an `llm.AsyncStreamResponse` without a response format."""
769
+ ...
770
+
771
+ @overload
772
+ async def stream_async(
773
+ self,
774
+ *,
775
+ model_id: str,
776
+ messages: Sequence[Message],
777
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
778
+ format: type[FormattableT] | Format[FormattableT],
779
+ **params: Unpack[Params],
780
+ ) -> AsyncStreamResponse[FormattableT]:
781
+ """Stream an `llm.AsyncStreamResponse` with a response format."""
782
+ ...
783
+
784
+ @overload
785
+ async def stream_async(
786
+ self,
787
+ *,
788
+ model_id: str,
789
+ messages: Sequence[Message],
790
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
791
+ format: type[FormattableT]
792
+ | Format[FormattableT]
793
+ | OutputParser[FormattableT]
794
+ | None,
795
+ **params: Unpack[Params],
796
+ ) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
797
+ """Stream an `llm.AsyncStreamResponse` with an optional response format."""
798
+ ...
799
+
800
+ async def stream_async(
801
+ self,
802
+ *,
803
+ model_id: str,
804
+ messages: Sequence[Message],
805
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
806
+ format: type[FormattableT]
807
+ | Format[FormattableT]
808
+ | OutputParser[FormattableT]
809
+ | None = None,
810
+ **params: Unpack[Params],
811
+ ) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
812
+ """Generate an `llm.AsyncStreamResponse` by asynchronously streaming from this client's LLM provider.
813
+
814
+ Args:
815
+ model_id: Model identifier to use.
816
+ messages: Messages to send to the LLM.
817
+ tools: Optional tools that the model may invoke.
818
+ format: Optional response format specifier.
819
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
820
+
821
+ Returns:
822
+ An `llm.AsyncStreamResponse` object for asynchronously iterating over the LLM-generated content.
823
+ """
824
+ with self._wrap_errors():
825
+ stream_response = await self._stream_async(
826
+ model_id=model_id,
827
+ messages=messages,
828
+ tools=tools,
829
+ format=format,
830
+ **params,
831
+ )
832
+ stream_response._chunk_iterator = self._wrap_async_iterator_errors( # pyright: ignore[reportPrivateUsage]
833
+ stream_response._chunk_iterator # pyright: ignore[reportPrivateUsage]
834
+ )
835
+ return stream_response
836
+
837
+ @abstractmethod
838
+ async def _stream_async(
839
+ self,
840
+ *,
841
+ model_id: str,
842
+ messages: Sequence[Message],
843
+ tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
844
+ format: type[FormattableT]
845
+ | Format[FormattableT]
846
+ | OutputParser[FormattableT]
847
+ | None = None,
848
+ **params: Unpack[Params],
849
+ ) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
850
+ """Implementation for stream_async(). Subclasses override this method."""
851
+ ...
852
+
853
+ @overload
854
+ async def context_stream_async(
855
+ self,
856
+ *,
857
+ ctx: Context[DepsT],
858
+ model_id: str,
859
+ messages: Sequence[Message],
860
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
861
+ | AsyncContextToolkit[DepsT]
862
+ | None = None,
863
+ format: None = None,
864
+ **params: Unpack[Params],
865
+ ) -> AsyncContextStreamResponse[DepsT, None]:
866
+ """Stream an `llm.AsyncContextStreamResponse` without a response format."""
867
+ ...
868
+
869
+ @overload
870
+ async def context_stream_async(
871
+ self,
872
+ *,
873
+ ctx: Context[DepsT],
874
+ model_id: str,
875
+ messages: Sequence[Message],
876
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
877
+ | AsyncContextToolkit[DepsT]
878
+ | None = None,
879
+ format: type[FormattableT] | Format[FormattableT],
880
+ **params: Unpack[Params],
881
+ ) -> AsyncContextStreamResponse[DepsT, FormattableT]:
882
+ """Stream an `llm.AsyncContextStreamResponse` with a response format."""
883
+ ...
884
+
885
+ @overload
886
+ async def context_stream_async(
887
+ self,
888
+ *,
889
+ ctx: Context[DepsT],
890
+ model_id: str,
891
+ messages: Sequence[Message],
892
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
893
+ | AsyncContextToolkit[DepsT]
894
+ | None = None,
895
+ format: type[FormattableT]
896
+ | Format[FormattableT]
897
+ | OutputParser[FormattableT]
898
+ | None,
899
+ **params: Unpack[Params],
900
+ ) -> (
901
+ AsyncContextStreamResponse[DepsT, None]
902
+ | AsyncContextStreamResponse[DepsT, FormattableT]
903
+ ):
904
+ """Stream an `llm.AsyncContextStreamResponse` with an optional response format."""
905
+ ...
906
+
907
+ async def context_stream_async(
908
+ self,
909
+ *,
910
+ ctx: Context[DepsT],
911
+ model_id: str,
912
+ messages: Sequence[Message],
913
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
914
+ | AsyncContextToolkit[DepsT]
915
+ | None = None,
916
+ format: type[FormattableT]
917
+ | Format[FormattableT]
918
+ | OutputParser[FormattableT]
919
+ | None = None,
920
+ **params: Unpack[Params],
921
+ ) -> (
922
+ AsyncContextStreamResponse[DepsT, None]
923
+ | AsyncContextStreamResponse[DepsT, FormattableT]
924
+ ):
925
+ """Generate an `llm.AsyncContextStreamResponse` by asynchronously streaming from this client's LLM provider.
926
+
927
+ Args:
928
+ ctx: Context object with dependencies for tools.
929
+ model_id: Model identifier to use.
930
+ messages: Messages to send to the LLM.
931
+ tools: Optional tools that the model may invoke.
932
+ format: Optional response format specifier.
933
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
934
+
935
+ Returns:
936
+ An `llm.AsyncContextStreamResponse` object for asynchronously iterating over the LLM-generated content.
937
+ """
938
+ with self._wrap_errors():
939
+ stream_response = await self._context_stream_async(
940
+ ctx=ctx,
941
+ model_id=model_id,
942
+ messages=messages,
943
+ tools=tools,
944
+ format=format,
945
+ **params,
946
+ )
947
+ stream_response._chunk_iterator = self._wrap_async_iterator_errors( # pyright: ignore[reportPrivateUsage]
948
+ stream_response._chunk_iterator # pyright: ignore[reportPrivateUsage]
949
+ )
950
+ return stream_response
951
+
952
+ @abstractmethod
953
+ async def _context_stream_async(
954
+ self,
955
+ *,
956
+ ctx: Context[DepsT],
957
+ model_id: str,
958
+ messages: Sequence[Message],
959
+ tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
960
+ | AsyncContextToolkit[DepsT]
961
+ | None = None,
962
+ format: type[FormattableT]
963
+ | Format[FormattableT]
964
+ | OutputParser[FormattableT]
965
+ | None = None,
966
+ **params: Unpack[Params],
967
+ ) -> (
968
+ AsyncContextStreamResponse[DepsT, None]
969
+ | AsyncContextStreamResponse[DepsT, FormattableT]
970
+ ):
971
+ """Implementation for context_stream_async(). Subclasses override this method."""
972
+ ...
973
+
974
+ @overload
975
+ def resume(
976
+ self,
977
+ *,
978
+ model_id: str,
979
+ response: Response,
980
+ content: UserContent,
981
+ **params: Unpack[Params],
982
+ ) -> Response:
983
+ """Resume an `llm.Response` without a response format."""
984
+ ...
985
+
986
+ @overload
987
+ def resume(
988
+ self,
989
+ *,
990
+ model_id: str,
991
+ response: Response[FormattableT],
992
+ content: UserContent,
993
+ **params: Unpack[Params],
994
+ ) -> Response[FormattableT]:
995
+ """Resume an `llm.Response` with a response format."""
996
+ ...
997
+
998
+ @overload
999
+ def resume(
1000
+ self,
1001
+ *,
1002
+ model_id: str,
1003
+ response: Response | Response[FormattableT],
1004
+ content: UserContent,
1005
+ **params: Unpack[Params],
1006
+ ) -> Response | Response[FormattableT]:
1007
+ """Resume an `llm.Response` with an optional response format."""
1008
+ ...
1009
+
1010
+ def resume(
1011
+ self,
1012
+ *,
1013
+ model_id: str,
1014
+ response: Response | Response[FormattableT],
1015
+ content: UserContent,
1016
+ **params: Unpack[Params],
1017
+ ) -> Response | Response[FormattableT]:
1018
+ """Generate a new `llm.Response` by extending another response's messages with additional user content.
1019
+
1020
+ Args:
1021
+ model_id: Model identifier to use.
1022
+ response: Previous response to extend.
1023
+ content: Additional user content to append.
1024
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
1025
+
1026
+ Returns:
1027
+ A new `llm.Response` object containing the extended conversation.
1028
+
1029
+ Note:
1030
+ Uses the previous response's tools and output format. This base method wraps
1031
+ around calling `client.call()` with a messages array derived from the response
1032
+ messages. However, clients may override this with first-class resume logic.
1033
+ """
1034
+ messages = response.messages + [user(content)]
1035
+ return self.call(
1036
+ model_id=model_id,
1037
+ messages=messages,
1038
+ tools=response.toolkit,
1039
+ format=response.format,
1040
+ **params,
1041
+ )
1042
+
1043
+ @overload
1044
+ async def resume_async(
1045
+ self,
1046
+ *,
1047
+ model_id: str,
1048
+ response: AsyncResponse,
1049
+ content: UserContent,
1050
+ **params: Unpack[Params],
1051
+ ) -> AsyncResponse:
1052
+ """Resume an `llm.AsyncResponse` without a response format."""
1053
+ ...
1054
+
1055
+ @overload
1056
+ async def resume_async(
1057
+ self,
1058
+ *,
1059
+ model_id: str,
1060
+ response: AsyncResponse[FormattableT],
1061
+ content: UserContent,
1062
+ **params: Unpack[Params],
1063
+ ) -> AsyncResponse[FormattableT]:
1064
+ """Resume an `llm.AsyncResponse` with a response format."""
1065
+ ...
1066
+
1067
+ @overload
1068
+ async def resume_async(
1069
+ self,
1070
+ *,
1071
+ model_id: str,
1072
+ response: AsyncResponse | AsyncResponse[FormattableT],
1073
+ content: UserContent,
1074
+ **params: Unpack[Params],
1075
+ ) -> AsyncResponse | AsyncResponse[FormattableT]:
1076
+ """Resume an `llm.AsyncResponse` with an optional response format."""
1077
+ ...
1078
+
1079
+ async def resume_async(
1080
+ self,
1081
+ *,
1082
+ model_id: str,
1083
+ response: AsyncResponse | AsyncResponse[FormattableT],
1084
+ content: UserContent,
1085
+ **params: Unpack[Params],
1086
+ ) -> AsyncResponse | AsyncResponse[FormattableT]:
1087
+ """Generate a new `llm.AsyncResponse` by extending another response's messages with additional user content.
1088
+
1089
+ Args:
1090
+ model_id: Model identifier to use.
1091
+ response: Previous async response to extend.
1092
+ content: Additional user content to append.
1093
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
1094
+
1095
+ Returns:
1096
+ A new `llm.AsyncResponse` object containing the extended conversation.
1097
+
1098
+ Note:
1099
+ Uses the previous response's tools and output format. This base method wraps
1100
+ around calling `client.call_async()` with a messages array derived from the response
1101
+ messages. However, clients may override this with first-class resume logic.
1102
+ """
1103
+ messages = response.messages + [user(content)]
1104
+ return await self.call_async(
1105
+ model_id=model_id,
1106
+ messages=messages,
1107
+ tools=response.toolkit,
1108
+ format=response.format,
1109
+ **params,
1110
+ )
1111
+
1112
+ @overload
1113
+ def context_resume(
1114
+ self,
1115
+ *,
1116
+ ctx: Context[DepsT],
1117
+ model_id: str,
1118
+ response: ContextResponse[DepsT, None],
1119
+ content: UserContent,
1120
+ **params: Unpack[Params],
1121
+ ) -> ContextResponse[DepsT, None]:
1122
+ """Resume an `llm.ContextResponse` without a response format."""
1123
+ ...
1124
+
1125
+ @overload
1126
+ def context_resume(
1127
+ self,
1128
+ *,
1129
+ ctx: Context[DepsT],
1130
+ model_id: str,
1131
+ response: ContextResponse[DepsT, FormattableT],
1132
+ content: UserContent,
1133
+ **params: Unpack[Params],
1134
+ ) -> ContextResponse[DepsT, FormattableT]:
1135
+ """Resume an `llm.ContextResponse` with a response format."""
1136
+ ...
1137
+
1138
+ @overload
1139
+ def context_resume(
1140
+ self,
1141
+ *,
1142
+ ctx: Context[DepsT],
1143
+ model_id: str,
1144
+ response: ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT],
1145
+ content: UserContent,
1146
+ **params: Unpack[Params],
1147
+ ) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
1148
+ """Resume an `llm.ContextResponse` with an optional response format."""
1149
+ ...
1150
+
1151
+ def context_resume(
1152
+ self,
1153
+ *,
1154
+ ctx: Context[DepsT],
1155
+ model_id: str,
1156
+ response: ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT],
1157
+ content: UserContent,
1158
+ **params: Unpack[Params],
1159
+ ) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
1160
+ """Generate a new `llm.ContextResponse` by extending another response's messages with additional user content.
1161
+
1162
+ Args:
1163
+ ctx: Context object with dependencies for tools.
1164
+ model_id: Model identifier to use.
1165
+ response: Previous context response to extend.
1166
+ content: Additional user content to append.
1167
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
1168
+
1169
+ Returns:
1170
+ A new `llm.ContextResponse` object containing the extended conversation.
1171
+
1172
+ Note:
1173
+ Uses the previous response's tools and output format. This base method wraps
1174
+ around calling `client.context_call()` with a messages array derived from the response
1175
+ messages. However, clients may override this with first-class resume logic.
1176
+ """
1177
+ messages = response.messages + [user(content)]
1178
+ return self.context_call(
1179
+ ctx=ctx,
1180
+ model_id=model_id,
1181
+ messages=messages,
1182
+ tools=response.toolkit,
1183
+ format=response.format,
1184
+ **params,
1185
+ )
1186
+
1187
+ @overload
1188
+ async def context_resume_async(
1189
+ self,
1190
+ *,
1191
+ ctx: Context[DepsT],
1192
+ model_id: str,
1193
+ response: AsyncContextResponse[DepsT, None],
1194
+ content: UserContent,
1195
+ **params: Unpack[Params],
1196
+ ) -> AsyncContextResponse[DepsT, None]:
1197
+ """Resume an `llm.AsyncContextResponse` without a response format."""
1198
+ ...
1199
+
1200
+ @overload
1201
+ async def context_resume_async(
1202
+ self,
1203
+ *,
1204
+ ctx: Context[DepsT],
1205
+ model_id: str,
1206
+ response: AsyncContextResponse[DepsT, FormattableT],
1207
+ content: UserContent,
1208
+ **params: Unpack[Params],
1209
+ ) -> AsyncContextResponse[DepsT, FormattableT]:
1210
+ """Resume an `llm.AsyncContextResponse` with a response format."""
1211
+ ...
1212
+
1213
+ @overload
1214
+ async def context_resume_async(
1215
+ self,
1216
+ *,
1217
+ ctx: Context[DepsT],
1218
+ model_id: str,
1219
+ response: AsyncContextResponse[DepsT, None]
1220
+ | AsyncContextResponse[DepsT, FormattableT],
1221
+ content: UserContent,
1222
+ **params: Unpack[Params],
1223
+ ) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
1224
+ """Resume an `llm.AsyncContextResponse` with an optional response format."""
1225
+ ...
1226
+
1227
+ async def context_resume_async(
1228
+ self,
1229
+ *,
1230
+ ctx: Context[DepsT],
1231
+ model_id: str,
1232
+ response: AsyncContextResponse[DepsT, None]
1233
+ | AsyncContextResponse[DepsT, FormattableT],
1234
+ content: UserContent,
1235
+ **params: Unpack[Params],
1236
+ ) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
1237
+ """Generate a new `llm.AsyncContextResponse` by extending another response's messages with additional user content.
1238
+
1239
+ Args:
1240
+ ctx: Context object with dependencies for tools.
1241
+ model_id: Model identifier to use.
1242
+ response: Previous async context response to extend.
1243
+ content: Additional user content to append.
1244
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
1245
+
1246
+ Returns:
1247
+ A new `llm.AsyncContextResponse` object containing the extended conversation.
1248
+
1249
+ Note:
1250
+ Uses the previous response's tools and output format. This base method wraps
1251
+ around calling `client.context_call_async()` with a messages array derived from the response
1252
+ messages. However, clients may override this with first-class resume logic.
1253
+ """
1254
+ messages = response.messages + [user(content)]
1255
+ return await self.context_call_async(
1256
+ ctx=ctx,
1257
+ model_id=model_id,
1258
+ messages=messages,
1259
+ tools=response.toolkit,
1260
+ format=response.format,
1261
+ **params,
1262
+ )
1263
+
1264
+ @overload
1265
+ def resume_stream(
1266
+ self,
1267
+ *,
1268
+ model_id: str,
1269
+ response: StreamResponse,
1270
+ content: UserContent,
1271
+ **params: Unpack[Params],
1272
+ ) -> StreamResponse:
1273
+ """Resume an `llm.StreamResponse` without a response format."""
1274
+ ...
1275
+
1276
+ @overload
1277
+ def resume_stream(
1278
+ self,
1279
+ *,
1280
+ model_id: str,
1281
+ response: StreamResponse[FormattableT],
1282
+ content: UserContent,
1283
+ **params: Unpack[Params],
1284
+ ) -> StreamResponse[FormattableT]:
1285
+ """Resume an `llm.StreamResponse` with a response format."""
1286
+ ...
1287
+
1288
+ @overload
1289
+ def resume_stream(
1290
+ self,
1291
+ *,
1292
+ model_id: str,
1293
+ response: StreamResponse | StreamResponse[FormattableT],
1294
+ content: UserContent,
1295
+ **params: Unpack[Params],
1296
+ ) -> StreamResponse | StreamResponse[FormattableT]:
1297
+ """Resume an `llm.StreamResponse` with an optional response format."""
1298
+ ...
1299
+
1300
+ def resume_stream(
1301
+ self,
1302
+ *,
1303
+ model_id: str,
1304
+ response: StreamResponse | StreamResponse[FormattableT],
1305
+ content: UserContent,
1306
+ **params: Unpack[Params],
1307
+ ) -> StreamResponse | StreamResponse[FormattableT]:
1308
+ """Generate a new `llm.StreamResponse` by extending another response's messages with additional user content.
1309
+
1310
+ Args:
1311
+ model_id: Model identifier to use.
1312
+ response: Previous stream response to extend.
1313
+ content: Additional user content to append.
1314
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
1315
+
1316
+ Returns:
1317
+ A new `llm.StreamResponse` object for streaming the extended conversation.
1318
+
1319
+ Note:
1320
+ Uses the previous response's tools and output format. This base method wraps
1321
+ around calling `client.stream()` with a messages array derived from the response
1322
+ messages. However, clients may override this with first-class resume logic.
1323
+ """
1324
+ messages = response.messages + [user(content)]
1325
+ return self.stream(
1326
+ model_id=model_id,
1327
+ messages=messages,
1328
+ tools=response.toolkit,
1329
+ format=response.format,
1330
+ **params,
1331
+ )
1332
+
1333
+ @overload
1334
+ async def resume_stream_async(
1335
+ self,
1336
+ *,
1337
+ model_id: str,
1338
+ response: AsyncStreamResponse,
1339
+ content: UserContent,
1340
+ **params: Unpack[Params],
1341
+ ) -> AsyncStreamResponse:
1342
+ """Resume an `llm.AsyncStreamResponse` without a response format."""
1343
+ ...
1344
+
1345
+ @overload
1346
+ async def resume_stream_async(
1347
+ self,
1348
+ *,
1349
+ model_id: str,
1350
+ response: AsyncStreamResponse[FormattableT],
1351
+ content: UserContent,
1352
+ **params: Unpack[Params],
1353
+ ) -> AsyncStreamResponse[FormattableT]:
1354
+ """Resume an `llm.AsyncStreamResponse` with a response format."""
1355
+ ...
1356
+
1357
+ @overload
1358
+ async def resume_stream_async(
1359
+ self,
1360
+ *,
1361
+ model_id: str,
1362
+ response: AsyncStreamResponse | AsyncStreamResponse[FormattableT],
1363
+ content: UserContent,
1364
+ **params: Unpack[Params],
1365
+ ) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
1366
+ """Resume an `llm.AsyncStreamResponse` with an optional response format."""
1367
+ ...
1368
+
1369
+ async def resume_stream_async(
1370
+ self,
1371
+ *,
1372
+ model_id: str,
1373
+ response: AsyncStreamResponse | AsyncStreamResponse[FormattableT],
1374
+ content: UserContent,
1375
+ **params: Unpack[Params],
1376
+ ) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
1377
+ """Generate a new `llm.AsyncStreamResponse` by extending another response's messages with additional user content.
1378
+
1379
+ Args:
1380
+ model_id: Model identifier to use.
1381
+ response: Previous async stream response to extend.
1382
+ content: Additional user content to append.
1383
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
1384
+
1385
+ Returns:
1386
+ A new `llm.AsyncStreamResponse` object for asynchronously streaming the extended conversation.
1387
+
1388
+ Note:
1389
+ Uses the previous response's tools and output format. This base method wraps
1390
+ around calling `client.stream_async()` with a messages array derived from the response
1391
+ messages. However, clients may override this with first-class resume logic.
1392
+ """
1393
+ messages = response.messages + [user(content)]
1394
+ return await self.stream_async(
1395
+ model_id=model_id,
1396
+ messages=messages,
1397
+ tools=response.toolkit,
1398
+ format=response.format,
1399
+ **params,
1400
+ )
1401
+
1402
+ @overload
1403
+ def context_resume_stream(
1404
+ self,
1405
+ *,
1406
+ ctx: Context[DepsT],
1407
+ model_id: str,
1408
+ response: ContextStreamResponse[DepsT, None],
1409
+ content: UserContent,
1410
+ **params: Unpack[Params],
1411
+ ) -> ContextStreamResponse[DepsT, None]:
1412
+ """Resume an `llm.ContextStreamResponse` without a response format."""
1413
+ ...
1414
+
1415
+ @overload
1416
+ def context_resume_stream(
1417
+ self,
1418
+ *,
1419
+ ctx: Context[DepsT],
1420
+ model_id: str,
1421
+ response: ContextStreamResponse[DepsT, FormattableT],
1422
+ content: UserContent,
1423
+ **params: Unpack[Params],
1424
+ ) -> ContextStreamResponse[DepsT, FormattableT]:
1425
+ """Resume an `llm.ContextStreamResponse` with a response format."""
1426
+ ...
1427
+
1428
+ @overload
1429
+ def context_resume_stream(
1430
+ self,
1431
+ *,
1432
+ ctx: Context[DepsT],
1433
+ model_id: str,
1434
+ response: ContextStreamResponse[DepsT, None]
1435
+ | ContextStreamResponse[DepsT, FormattableT],
1436
+ content: UserContent,
1437
+ **params: Unpack[Params],
1438
+ ) -> (
1439
+ ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
1440
+ ):
1441
+ """Resume an `llm.ContextStreamResponse` with an optional response format."""
1442
+ ...
1443
+
1444
+ def context_resume_stream(
1445
+ self,
1446
+ *,
1447
+ ctx: Context[DepsT],
1448
+ model_id: str,
1449
+ response: ContextStreamResponse[DepsT, None]
1450
+ | ContextStreamResponse[DepsT, FormattableT],
1451
+ content: UserContent,
1452
+ **params: Unpack[Params],
1453
+ ) -> (
1454
+ ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
1455
+ ):
1456
+ """Generate a new `llm.ContextStreamResponse` by extending another response's messages with additional user content.
1457
+
1458
+ Args:
1459
+ ctx: Context object with dependencies for tools.
1460
+ model_id: Model identifier to use.
1461
+ response: Previous context stream response to extend.
1462
+ content: Additional user content to append.
1463
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
1464
+
1465
+ Returns:
1466
+ A new `llm.ContextStreamResponse` object for streaming the extended conversation.
1467
+
1468
+ Note:
1469
+ Uses the previous response's tools and output format. This base method wraps
1470
+ around calling `client.context_stream()` with a messages array derived from the response
1471
+ messages. However, clients may override this with first-class resume logic.
1472
+ """
1473
+ messages = response.messages + [user(content)]
1474
+ return self.context_stream(
1475
+ ctx=ctx,
1476
+ model_id=model_id,
1477
+ messages=messages,
1478
+ tools=response.toolkit,
1479
+ format=response.format,
1480
+ **params,
1481
+ )
1482
+
1483
+ @overload
1484
+ async def context_resume_stream_async(
1485
+ self,
1486
+ *,
1487
+ ctx: Context[DepsT],
1488
+ model_id: str,
1489
+ response: AsyncContextStreamResponse[DepsT, None],
1490
+ content: UserContent,
1491
+ **params: Unpack[Params],
1492
+ ) -> AsyncContextStreamResponse[DepsT, None]:
1493
+ """Resume an `llm.AsyncContextStreamResponse` without a response format."""
1494
+ ...
1495
+
1496
+ @overload
1497
+ async def context_resume_stream_async(
1498
+ self,
1499
+ *,
1500
+ ctx: Context[DepsT],
1501
+ model_id: str,
1502
+ response: AsyncContextStreamResponse[DepsT, FormattableT],
1503
+ content: UserContent,
1504
+ **params: Unpack[Params],
1505
+ ) -> AsyncContextStreamResponse[DepsT, FormattableT]:
1506
+ """Resume an `llm.AsyncContextStreamResponse` with a response format."""
1507
+ ...
1508
+
1509
+ @overload
1510
+ async def context_resume_stream_async(
1511
+ self,
1512
+ *,
1513
+ ctx: Context[DepsT],
1514
+ model_id: str,
1515
+ response: AsyncContextStreamResponse[DepsT, None]
1516
+ | AsyncContextStreamResponse[DepsT, FormattableT],
1517
+ content: UserContent,
1518
+ **params: Unpack[Params],
1519
+ ) -> (
1520
+ AsyncContextStreamResponse[DepsT, None]
1521
+ | AsyncContextStreamResponse[DepsT, FormattableT]
1522
+ ):
1523
+ """Resume an `llm.AsyncContextStreamResponse` with an optional response format."""
1524
+ ...
1525
+
1526
+ async def context_resume_stream_async(
1527
+ self,
1528
+ *,
1529
+ ctx: Context[DepsT],
1530
+ model_id: str,
1531
+ response: AsyncContextStreamResponse[DepsT, None]
1532
+ | AsyncContextStreamResponse[DepsT, FormattableT],
1533
+ content: UserContent,
1534
+ **params: Unpack[Params],
1535
+ ) -> (
1536
+ AsyncContextStreamResponse[DepsT, None]
1537
+ | AsyncContextStreamResponse[DepsT, FormattableT]
1538
+ ):
1539
+ """Generate a new `llm.AsyncContextStreamResponse` by extending another response's messages with additional user content.
1540
+
1541
+ Args:
1542
+ ctx: Context object with dependencies for tools.
1543
+ model_id: Model identifier to use.
1544
+ response: Previous async context stream response to extend.
1545
+ content: Additional user content to append.
1546
+ **params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
1547
+
1548
+ Returns:
1549
+ A new `llm.AsyncContextStreamResponse` object for asynchronously streaming the extended conversation.
1550
+
1551
+ Note:
1552
+ Uses the previous response's tools and output format. This base method wraps
1553
+ around calling `client.context_stream_async()` with a messages array derived from the response
1554
+ messages. However, clients may override this with first-class resume logic.
1555
+ """
1556
+ messages = response.messages + [user(content)]
1557
+ return await self.context_stream_async(
1558
+ ctx=ctx,
1559
+ model_id=model_id,
1560
+ messages=messages,
1561
+ tools=response.toolkit,
1562
+ format=response.format,
1563
+ **params,
1564
+ )
1565
+
1566
+ @abstractmethod
1567
+ def get_error_status(self, e: Exception) -> int | None:
1568
+ """Extract HTTP status code from provider-specific exception.
1569
+
1570
+ Different SDKs store status codes differently (e.g., .status_code vs .code).
1571
+ Each provider implements this to handle their SDK's convention.
1572
+
1573
+ Args:
1574
+ e: The exception to extract status code from.
1575
+
1576
+ Returns:
1577
+ The HTTP status code if available, None otherwise.
1578
+ """
1579
+ ...