mirascope 2.0.0a5__py3-none-any.whl → 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (349) hide show
  1. mirascope/__init__.py +10 -1
  2. mirascope/_stubs.py +363 -0
  3. mirascope/api/__init__.py +8 -0
  4. mirascope/api/_generated/__init__.py +285 -2
  5. mirascope/api/_generated/annotations/__init__.py +33 -0
  6. mirascope/api/_generated/annotations/client.py +506 -0
  7. mirascope/api/_generated/annotations/raw_client.py +1414 -0
  8. mirascope/api/_generated/annotations/types/__init__.py +31 -0
  9. mirascope/api/_generated/annotations/types/annotations_create_request_label.py +5 -0
  10. mirascope/api/_generated/annotations/types/annotations_create_response.py +48 -0
  11. mirascope/api/_generated/annotations/types/annotations_create_response_label.py +5 -0
  12. mirascope/api/_generated/annotations/types/annotations_get_response.py +48 -0
  13. mirascope/api/_generated/annotations/types/annotations_get_response_label.py +5 -0
  14. mirascope/api/_generated/annotations/types/annotations_list_request_label.py +5 -0
  15. mirascope/api/_generated/annotations/types/annotations_list_response.py +21 -0
  16. mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item.py +50 -0
  17. mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item_label.py +5 -0
  18. mirascope/api/_generated/annotations/types/annotations_update_request_label.py +5 -0
  19. mirascope/api/_generated/annotations/types/annotations_update_response.py +48 -0
  20. mirascope/api/_generated/annotations/types/annotations_update_response_label.py +5 -0
  21. mirascope/api/_generated/api_keys/__init__.py +12 -2
  22. mirascope/api/_generated/api_keys/client.py +77 -0
  23. mirascope/api/_generated/api_keys/raw_client.py +422 -39
  24. mirascope/api/_generated/api_keys/types/__init__.py +7 -1
  25. mirascope/api/_generated/api_keys/types/api_keys_create_response.py +4 -12
  26. mirascope/api/_generated/api_keys/types/api_keys_get_response.py +4 -12
  27. mirascope/api/_generated/api_keys/types/api_keys_list_all_for_org_response_item.py +40 -0
  28. mirascope/api/_generated/api_keys/types/api_keys_list_response_item.py +4 -12
  29. mirascope/api/_generated/client.py +42 -0
  30. mirascope/api/_generated/core/client_wrapper.py +2 -14
  31. mirascope/api/_generated/core/datetime_utils.py +1 -3
  32. mirascope/api/_generated/core/file.py +2 -5
  33. mirascope/api/_generated/core/http_client.py +36 -112
  34. mirascope/api/_generated/core/jsonable_encoder.py +1 -3
  35. mirascope/api/_generated/core/pydantic_utilities.py +19 -74
  36. mirascope/api/_generated/core/query_encoder.py +1 -3
  37. mirascope/api/_generated/core/serialization.py +4 -10
  38. mirascope/api/_generated/docs/client.py +2 -6
  39. mirascope/api/_generated/docs/raw_client.py +51 -5
  40. mirascope/api/_generated/environment.py +3 -3
  41. mirascope/api/_generated/environments/__init__.py +6 -0
  42. mirascope/api/_generated/environments/client.py +117 -0
  43. mirascope/api/_generated/environments/raw_client.py +530 -51
  44. mirascope/api/_generated/environments/types/__init__.py +10 -0
  45. mirascope/api/_generated/environments/types/environments_create_response.py +1 -3
  46. mirascope/api/_generated/environments/types/environments_get_analytics_response.py +60 -0
  47. mirascope/api/_generated/environments/types/environments_get_analytics_response_top_functions_item.py +24 -0
  48. mirascope/api/_generated/environments/types/environments_get_analytics_response_top_models_item.py +22 -0
  49. mirascope/api/_generated/environments/types/environments_get_response.py +1 -3
  50. mirascope/api/_generated/environments/types/environments_list_response_item.py +1 -3
  51. mirascope/api/_generated/environments/types/environments_update_response.py +1 -3
  52. mirascope/api/_generated/errors/__init__.py +8 -0
  53. mirascope/api/_generated/errors/bad_request_error.py +1 -2
  54. mirascope/api/_generated/errors/conflict_error.py +1 -2
  55. mirascope/api/_generated/errors/forbidden_error.py +1 -5
  56. mirascope/api/_generated/errors/internal_server_error.py +1 -6
  57. mirascope/api/_generated/errors/not_found_error.py +1 -5
  58. mirascope/api/_generated/errors/payment_required_error.py +15 -0
  59. mirascope/api/_generated/errors/service_unavailable_error.py +14 -0
  60. mirascope/api/_generated/errors/too_many_requests_error.py +15 -0
  61. mirascope/api/_generated/errors/unauthorized_error.py +11 -0
  62. mirascope/api/_generated/functions/__init__.py +39 -0
  63. mirascope/api/_generated/functions/client.py +647 -0
  64. mirascope/api/_generated/functions/raw_client.py +1890 -0
  65. mirascope/api/_generated/functions/types/__init__.py +53 -0
  66. mirascope/api/_generated/functions/types/functions_create_request_dependencies_value.py +20 -0
  67. mirascope/api/_generated/functions/types/functions_create_response.py +37 -0
  68. mirascope/api/_generated/functions/types/functions_create_response_dependencies_value.py +20 -0
  69. mirascope/api/_generated/functions/types/functions_find_by_hash_response.py +39 -0
  70. mirascope/api/_generated/functions/types/functions_find_by_hash_response_dependencies_value.py +20 -0
  71. mirascope/api/_generated/functions/types/functions_get_by_env_response.py +53 -0
  72. mirascope/api/_generated/functions/types/functions_get_by_env_response_dependencies_value.py +22 -0
  73. mirascope/api/_generated/functions/types/functions_get_response.py +37 -0
  74. mirascope/api/_generated/functions/types/functions_get_response_dependencies_value.py +20 -0
  75. mirascope/api/_generated/functions/types/functions_list_by_env_response.py +25 -0
  76. mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item.py +56 -0
  77. mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item_dependencies_value.py +22 -0
  78. mirascope/api/_generated/functions/types/functions_list_response.py +21 -0
  79. mirascope/api/_generated/functions/types/functions_list_response_functions_item.py +41 -0
  80. mirascope/api/_generated/functions/types/functions_list_response_functions_item_dependencies_value.py +20 -0
  81. mirascope/api/_generated/health/client.py +2 -6
  82. mirascope/api/_generated/health/raw_client.py +51 -5
  83. mirascope/api/_generated/health/types/health_check_response.py +1 -3
  84. mirascope/api/_generated/organization_invitations/__init__.py +33 -0
  85. mirascope/api/_generated/organization_invitations/client.py +546 -0
  86. mirascope/api/_generated/organization_invitations/raw_client.py +1519 -0
  87. mirascope/api/_generated/organization_invitations/types/__init__.py +53 -0
  88. mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response.py +34 -0
  89. mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response_role.py +7 -0
  90. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_request_role.py +7 -0
  91. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response.py +48 -0
  92. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_role.py +7 -0
  93. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_status.py +7 -0
  94. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response.py +48 -0
  95. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_role.py +7 -0
  96. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_status.py +7 -0
  97. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item.py +48 -0
  98. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_role.py +7 -0
  99. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_status.py +7 -0
  100. mirascope/api/_generated/organization_memberships/__init__.py +19 -0
  101. mirascope/api/_generated/organization_memberships/client.py +302 -0
  102. mirascope/api/_generated/organization_memberships/raw_client.py +736 -0
  103. mirascope/api/_generated/organization_memberships/types/__init__.py +27 -0
  104. mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item.py +33 -0
  105. mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item_role.py +7 -0
  106. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_request_role.py +7 -0
  107. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response.py +31 -0
  108. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response_role.py +7 -0
  109. mirascope/api/_generated/organizations/__init__.py +26 -0
  110. mirascope/api/_generated/organizations/client.py +465 -0
  111. mirascope/api/_generated/organizations/raw_client.py +1799 -108
  112. mirascope/api/_generated/organizations/types/__init__.py +48 -0
  113. mirascope/api/_generated/organizations/types/organizations_create_payment_intent_response.py +24 -0
  114. mirascope/api/_generated/organizations/types/organizations_create_response.py +4 -3
  115. mirascope/api/_generated/organizations/types/organizations_create_response_role.py +1 -3
  116. mirascope/api/_generated/organizations/types/organizations_get_response.py +4 -3
  117. mirascope/api/_generated/organizations/types/organizations_get_response_role.py +1 -3
  118. mirascope/api/_generated/organizations/types/organizations_list_response_item.py +4 -3
  119. mirascope/api/_generated/organizations/types/organizations_list_response_item_role.py +1 -3
  120. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_request_target_plan.py +7 -0
  121. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response.py +47 -0
  122. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item.py +33 -0
  123. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item_resource.py +7 -0
  124. mirascope/api/_generated/organizations/types/organizations_router_balance_response.py +24 -0
  125. mirascope/api/_generated/organizations/types/organizations_subscription_response.py +53 -0
  126. mirascope/api/_generated/organizations/types/organizations_subscription_response_current_plan.py +7 -0
  127. mirascope/api/_generated/organizations/types/organizations_subscription_response_payment_method.py +26 -0
  128. mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change.py +34 -0
  129. mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change_target_plan.py +7 -0
  130. mirascope/api/_generated/organizations/types/organizations_update_response.py +4 -3
  131. mirascope/api/_generated/organizations/types/organizations_update_response_role.py +1 -3
  132. mirascope/api/_generated/organizations/types/organizations_update_subscription_request_target_plan.py +7 -0
  133. mirascope/api/_generated/organizations/types/organizations_update_subscription_response.py +35 -0
  134. mirascope/api/_generated/project_memberships/__init__.py +25 -0
  135. mirascope/api/_generated/project_memberships/client.py +437 -0
  136. mirascope/api/_generated/project_memberships/raw_client.py +1039 -0
  137. mirascope/api/_generated/project_memberships/types/__init__.py +29 -0
  138. mirascope/api/_generated/project_memberships/types/project_memberships_create_request_role.py +7 -0
  139. mirascope/api/_generated/project_memberships/types/project_memberships_create_response.py +35 -0
  140. mirascope/api/_generated/project_memberships/types/project_memberships_create_response_role.py +7 -0
  141. mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item.py +33 -0
  142. mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item_role.py +7 -0
  143. mirascope/api/_generated/project_memberships/types/project_memberships_update_request_role.py +7 -0
  144. mirascope/api/_generated/project_memberships/types/project_memberships_update_response.py +35 -0
  145. mirascope/api/_generated/project_memberships/types/project_memberships_update_response_role.py +7 -0
  146. mirascope/api/_generated/projects/__init__.py +2 -12
  147. mirascope/api/_generated/projects/client.py +17 -71
  148. mirascope/api/_generated/projects/raw_client.py +295 -51
  149. mirascope/api/_generated/projects/types/__init__.py +1 -6
  150. mirascope/api/_generated/projects/types/projects_create_response.py +3 -9
  151. mirascope/api/_generated/projects/types/projects_get_response.py +3 -9
  152. mirascope/api/_generated/projects/types/projects_list_response_item.py +3 -9
  153. mirascope/api/_generated/projects/types/projects_update_response.py +3 -9
  154. mirascope/api/_generated/reference.md +3619 -182
  155. mirascope/api/_generated/tags/__init__.py +19 -0
  156. mirascope/api/_generated/tags/client.py +504 -0
  157. mirascope/api/_generated/tags/raw_client.py +1288 -0
  158. mirascope/api/_generated/tags/types/__init__.py +17 -0
  159. mirascope/api/_generated/tags/types/tags_create_response.py +41 -0
  160. mirascope/api/_generated/tags/types/tags_get_response.py +41 -0
  161. mirascope/api/_generated/tags/types/tags_list_response.py +23 -0
  162. mirascope/api/_generated/tags/types/tags_list_response_tags_item.py +41 -0
  163. mirascope/api/_generated/tags/types/tags_update_response.py +41 -0
  164. mirascope/api/_generated/token_cost/__init__.py +7 -0
  165. mirascope/api/_generated/token_cost/client.py +160 -0
  166. mirascope/api/_generated/token_cost/raw_client.py +264 -0
  167. mirascope/api/_generated/token_cost/types/__init__.py +8 -0
  168. mirascope/api/_generated/token_cost/types/token_cost_calculate_request_usage.py +54 -0
  169. mirascope/api/_generated/token_cost/types/token_cost_calculate_response.py +52 -0
  170. mirascope/api/_generated/traces/__init__.py +42 -0
  171. mirascope/api/_generated/traces/client.py +941 -0
  172. mirascope/api/_generated/traces/raw_client.py +2177 -23
  173. mirascope/api/_generated/traces/types/__init__.py +60 -0
  174. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +4 -11
  175. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +2 -6
  176. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +1 -3
  177. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +8 -24
  178. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +2 -6
  179. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +3 -9
  180. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +2 -6
  181. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +3 -9
  182. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +4 -8
  183. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +2 -6
  184. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +8 -24
  185. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +2 -6
  186. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +3 -9
  187. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value_values_item.py +1 -3
  188. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +6 -18
  189. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +3 -9
  190. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +8 -24
  191. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +2 -6
  192. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +2 -6
  193. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value_values_item.py +1 -3
  194. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +2 -6
  195. mirascope/api/_generated/traces/types/traces_create_response.py +2 -5
  196. mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +3 -9
  197. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response.py +60 -0
  198. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_functions_item.py +24 -0
  199. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_models_item.py +22 -0
  200. mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response.py +33 -0
  201. mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response_spans_item.py +88 -0
  202. mirascope/api/_generated/traces/types/traces_get_trace_detail_response.py +33 -0
  203. mirascope/api/_generated/traces/types/traces_get_trace_detail_response_spans_item.py +88 -0
  204. mirascope/api/_generated/traces/types/traces_list_by_function_hash_response.py +25 -0
  205. mirascope/api/_generated/traces/types/traces_list_by_function_hash_response_traces_item.py +44 -0
  206. mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item.py +26 -0
  207. mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item_operator.py +7 -0
  208. mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_by.py +7 -0
  209. mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_order.py +7 -0
  210. mirascope/api/_generated/traces/types/traces_search_by_env_response.py +26 -0
  211. mirascope/api/_generated/traces/types/traces_search_by_env_response_spans_item.py +50 -0
  212. mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item.py +26 -0
  213. mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item_operator.py +7 -0
  214. mirascope/api/_generated/traces/types/traces_search_request_sort_by.py +7 -0
  215. mirascope/api/_generated/traces/types/traces_search_request_sort_order.py +5 -0
  216. mirascope/api/_generated/traces/types/traces_search_response.py +26 -0
  217. mirascope/api/_generated/traces/types/traces_search_response_spans_item.py +50 -0
  218. mirascope/api/_generated/types/__init__.py +48 -0
  219. mirascope/api/_generated/types/already_exists_error.py +1 -3
  220. mirascope/api/_generated/types/bad_request_error_body.py +50 -0
  221. mirascope/api/_generated/types/click_house_error.py +22 -0
  222. mirascope/api/_generated/types/database_error.py +1 -3
  223. mirascope/api/_generated/types/date.py +3 -0
  224. mirascope/api/_generated/types/http_api_decode_error.py +1 -3
  225. mirascope/api/_generated/types/immutable_resource_error.py +22 -0
  226. mirascope/api/_generated/types/internal_server_error_body.py +49 -0
  227. mirascope/api/_generated/types/issue.py +1 -3
  228. mirascope/api/_generated/types/issue_tag.py +1 -8
  229. mirascope/api/_generated/types/not_found_error_body.py +1 -3
  230. mirascope/api/_generated/types/number_from_string.py +3 -0
  231. mirascope/api/_generated/types/permission_denied_error.py +1 -3
  232. mirascope/api/_generated/types/permission_denied_error_tag.py +1 -3
  233. mirascope/api/_generated/types/plan_limit_exceeded_error.py +32 -0
  234. mirascope/api/_generated/types/plan_limit_exceeded_error_tag.py +7 -0
  235. mirascope/api/_generated/types/pricing_unavailable_error.py +23 -0
  236. mirascope/api/_generated/types/property_key_key.py +1 -3
  237. mirascope/api/_generated/types/rate_limit_error.py +31 -0
  238. mirascope/api/_generated/types/rate_limit_error_tag.py +5 -0
  239. mirascope/api/_generated/types/service_unavailable_error_body.py +24 -0
  240. mirascope/api/_generated/types/service_unavailable_error_tag.py +7 -0
  241. mirascope/api/_generated/types/stripe_error.py +20 -0
  242. mirascope/api/_generated/types/subscription_past_due_error.py +31 -0
  243. mirascope/api/_generated/types/subscription_past_due_error_tag.py +7 -0
  244. mirascope/api/_generated/types/unauthorized_error_body.py +21 -0
  245. mirascope/api/_generated/types/unauthorized_error_tag.py +5 -0
  246. mirascope/api/settings.py +19 -1
  247. mirascope/llm/__init__.py +55 -8
  248. mirascope/llm/calls/__init__.py +2 -1
  249. mirascope/llm/calls/calls.py +3 -1
  250. mirascope/llm/calls/decorator.py +21 -7
  251. mirascope/llm/content/tool_call.py +6 -0
  252. mirascope/llm/content/tool_output.py +22 -5
  253. mirascope/llm/exceptions.py +284 -71
  254. mirascope/llm/formatting/__init__.py +19 -2
  255. mirascope/llm/formatting/format.py +219 -30
  256. mirascope/llm/formatting/output_parser.py +178 -0
  257. mirascope/llm/formatting/partial.py +80 -7
  258. mirascope/llm/formatting/primitives.py +192 -0
  259. mirascope/llm/formatting/types.py +21 -64
  260. mirascope/llm/mcp/__init__.py +2 -2
  261. mirascope/llm/mcp/mcp_client.py +130 -0
  262. mirascope/llm/messages/__init__.py +3 -0
  263. mirascope/llm/messages/_utils.py +34 -0
  264. mirascope/llm/models/__init__.py +5 -0
  265. mirascope/llm/models/models.py +137 -69
  266. mirascope/llm/{providers/base → models}/params.py +16 -37
  267. mirascope/llm/models/thinking_config.py +61 -0
  268. mirascope/llm/prompts/_utils.py +0 -32
  269. mirascope/llm/prompts/decorator.py +16 -5
  270. mirascope/llm/prompts/prompts.py +131 -68
  271. mirascope/llm/providers/__init__.py +18 -2
  272. mirascope/llm/providers/anthropic/__init__.py +3 -21
  273. mirascope/llm/providers/anthropic/_utils/__init__.py +2 -0
  274. mirascope/llm/providers/anthropic/_utils/beta_decode.py +22 -11
  275. mirascope/llm/providers/anthropic/_utils/beta_encode.py +75 -25
  276. mirascope/llm/providers/anthropic/_utils/decode.py +22 -11
  277. mirascope/llm/providers/anthropic/_utils/encode.py +82 -20
  278. mirascope/llm/providers/anthropic/_utils/errors.py +2 -2
  279. mirascope/llm/providers/anthropic/beta_provider.py +64 -18
  280. mirascope/llm/providers/anthropic/provider.py +91 -33
  281. mirascope/llm/providers/base/__init__.py +0 -2
  282. mirascope/llm/providers/base/_utils.py +55 -11
  283. mirascope/llm/providers/base/base_provider.py +116 -37
  284. mirascope/llm/providers/google/__init__.py +2 -17
  285. mirascope/llm/providers/google/_utils/__init__.py +2 -0
  286. mirascope/llm/providers/google/_utils/decode.py +37 -15
  287. mirascope/llm/providers/google/_utils/encode.py +127 -19
  288. mirascope/llm/providers/google/_utils/errors.py +3 -2
  289. mirascope/llm/providers/google/model_info.py +1 -0
  290. mirascope/llm/providers/google/provider.py +68 -19
  291. mirascope/llm/providers/mirascope/__init__.py +5 -0
  292. mirascope/llm/providers/mirascope/_utils.py +73 -0
  293. mirascope/llm/providers/mirascope/provider.py +349 -0
  294. mirascope/llm/providers/mlx/__init__.py +2 -17
  295. mirascope/llm/providers/mlx/_utils.py +8 -3
  296. mirascope/llm/providers/mlx/encoding/base.py +5 -2
  297. mirascope/llm/providers/mlx/encoding/transformers.py +5 -2
  298. mirascope/llm/providers/mlx/mlx.py +23 -6
  299. mirascope/llm/providers/mlx/provider.py +42 -13
  300. mirascope/llm/providers/ollama/__init__.py +1 -13
  301. mirascope/llm/providers/openai/_utils/errors.py +2 -2
  302. mirascope/llm/providers/openai/completions/__init__.py +2 -20
  303. mirascope/llm/providers/openai/completions/_utils/decode.py +14 -3
  304. mirascope/llm/providers/openai/completions/_utils/encode.py +35 -28
  305. mirascope/llm/providers/openai/completions/base_provider.py +40 -11
  306. mirascope/llm/providers/openai/provider.py +40 -10
  307. mirascope/llm/providers/openai/responses/__init__.py +1 -17
  308. mirascope/llm/providers/openai/responses/_utils/__init__.py +2 -0
  309. mirascope/llm/providers/openai/responses/_utils/decode.py +21 -8
  310. mirascope/llm/providers/openai/responses/_utils/encode.py +59 -19
  311. mirascope/llm/providers/openai/responses/provider.py +56 -18
  312. mirascope/llm/providers/provider_id.py +1 -0
  313. mirascope/llm/providers/provider_registry.py +96 -19
  314. mirascope/llm/providers/together/__init__.py +1 -13
  315. mirascope/llm/responses/__init__.py +6 -1
  316. mirascope/llm/responses/_utils.py +102 -12
  317. mirascope/llm/responses/base_response.py +5 -2
  318. mirascope/llm/responses/base_stream_response.py +139 -45
  319. mirascope/llm/responses/response.py +2 -1
  320. mirascope/llm/responses/root_response.py +89 -17
  321. mirascope/llm/responses/stream_response.py +6 -9
  322. mirascope/llm/tools/decorator.py +17 -8
  323. mirascope/llm/tools/tool_schema.py +43 -10
  324. mirascope/llm/tools/toolkit.py +35 -27
  325. mirascope/llm/tools/tools.py +123 -30
  326. mirascope/ops/__init__.py +64 -109
  327. mirascope/ops/_internal/configuration.py +82 -31
  328. mirascope/ops/_internal/exporters/exporters.py +64 -11
  329. mirascope/ops/_internal/instrumentation/llm/common.py +530 -0
  330. mirascope/ops/_internal/instrumentation/llm/cost.py +190 -0
  331. mirascope/ops/_internal/instrumentation/llm/encode.py +1 -1
  332. mirascope/ops/_internal/instrumentation/llm/llm.py +116 -1243
  333. mirascope/ops/_internal/instrumentation/llm/model.py +1798 -0
  334. mirascope/ops/_internal/instrumentation/llm/response.py +521 -0
  335. mirascope/ops/_internal/instrumentation/llm/serialize.py +300 -0
  336. mirascope/ops/_internal/protocols.py +83 -1
  337. mirascope/ops/_internal/traced_calls.py +4 -0
  338. mirascope/ops/_internal/traced_functions.py +141 -12
  339. mirascope/ops/_internal/tracing.py +78 -1
  340. mirascope/ops/_internal/utils.py +52 -4
  341. mirascope/ops/_internal/versioned_functions.py +54 -43
  342. {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/METADATA +14 -13
  343. mirascope-2.0.1.dist-info/RECORD +423 -0
  344. {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/licenses/LICENSE +1 -1
  345. mirascope/llm/formatting/_utils.py +0 -78
  346. mirascope/llm/mcp/client.py +0 -118
  347. mirascope/llm/providers/_missing_import_stubs.py +0 -49
  348. mirascope-2.0.0a5.dist-info/RECORD +0 -265
  349. {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/WHEEL +0 -0
@@ -9,8 +9,8 @@ from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypeAlias, cast, overl
9
9
  from typing_extensions import TypeVar, Unpack
10
10
 
11
11
  from ...context import Context, DepsT
12
- from ...exceptions import APIError, MirascopeLLMError
13
- from ...formatting import Format, FormattableT
12
+ from ...exceptions import APIError, ProviderError
13
+ from ...formatting import Format, FormattableT, OutputParser
14
14
  from ...messages import Message, UserContent, user
15
15
  from ...responses import (
16
16
  AsyncChunkIterator,
@@ -34,10 +34,9 @@ from ...tools import (
34
34
  Tool,
35
35
  Toolkit,
36
36
  )
37
- from .params import Params
38
37
 
39
38
  if TYPE_CHECKING:
40
- from ...exceptions import MirascopeLLMError
39
+ from ...models import Params
41
40
  from ..provider_id import ProviderId
42
41
 
43
42
  ProviderClientT = TypeVar("ProviderClientT")
@@ -47,7 +46,7 @@ Provider: TypeAlias = "BaseProvider[Any]"
47
46
 
48
47
  ProviderErrorMap: TypeAlias = Mapping[
49
48
  type[Exception],
50
- "type[MirascopeLLMError] | Callable[[Exception], type[MirascopeLLMError]]",
49
+ "type[ProviderError] | Callable[[Exception], type[ProviderError]]",
51
50
  ]
52
51
  """Mapping from provider SDK exceptions to Mirascope error types.
53
52
 
@@ -85,7 +84,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
85
84
  (e.g., lambda e: NotFoundError if e.code == "model_not_found" else BadRequestError)
86
85
 
87
86
  The mapping is walked via the exception's MRO, allowing both specific error handling
88
- and fallback to base SDK error types (e.g., AnthropicError -> APIError).
87
+ and fallback to base SDK error types (e.g., AnthropicError -> ProviderError).
89
88
  """
90
89
 
91
90
  client: ProviderClientT
@@ -96,7 +95,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
96
95
 
97
96
  Walks the exception's MRO to find the first matching error type in the
98
97
  provider's error_map, allowing both specific error handling and fallback
99
- to base SDK error types (e.g., AnthropicError -> APIError).
98
+ to base SDK error types (e.g., AnthropicError -> ProviderError).
100
99
  """
101
100
  try:
102
101
  yield
@@ -107,16 +106,24 @@ class BaseProvider(Generic[ProviderClientT], ABC):
107
106
  error_type_or_fn = self.error_map[error_class]
108
107
 
109
108
  if isinstance(error_type_or_fn, type):
110
- error_type = cast(type[MirascopeLLMError], error_type_or_fn)
109
+ error_type = cast(type[ProviderError], error_type_or_fn)
111
110
  else:
112
111
  error_type = error_type_or_fn(e)
113
112
 
114
113
  # Construct Mirascope error with metadata
115
- error: MirascopeLLMError = error_type(str(e))
116
- if isinstance(error, APIError):
117
- error.status_code = self.get_error_status(e)
118
- error.provider = self.id
119
- error.original_exception = e
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
+ )
120
127
  raise error from e
121
128
 
122
129
  # Not in error_map - not a provider error, re-raise as-is
@@ -170,7 +177,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
170
177
  model_id: str,
171
178
  messages: Sequence[Message],
172
179
  tools: Sequence[Tool] | Toolkit | None = None,
173
- format: type[FormattableT] | Format[FormattableT] | None,
180
+ format: type[FormattableT]
181
+ | Format[FormattableT]
182
+ | OutputParser[FormattableT]
183
+ | None,
174
184
  **params: Unpack[Params],
175
185
  ) -> Response | Response[FormattableT]:
176
186
  """Generate an `llm.Response` with an optional response format."""
@@ -182,7 +192,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
182
192
  model_id: str,
183
193
  messages: Sequence[Message],
184
194
  tools: Sequence[Tool] | Toolkit | None = None,
185
- format: type[FormattableT] | Format[FormattableT] | None = None,
195
+ format: type[FormattableT]
196
+ | Format[FormattableT]
197
+ | OutputParser[FormattableT]
198
+ | None = None,
186
199
  **params: Unpack[Params],
187
200
  ) -> Response | Response[FormattableT]:
188
201
  """Generate an `llm.Response` by synchronously calling this client's LLM provider.
@@ -213,7 +226,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
213
226
  model_id: str,
214
227
  messages: Sequence[Message],
215
228
  tools: Sequence[Tool] | Toolkit | None = None,
216
- format: type[FormattableT] | Format[FormattableT] | None = None,
229
+ format: type[FormattableT]
230
+ | Format[FormattableT]
231
+ | OutputParser[FormattableT]
232
+ | None = None,
217
233
  **params: Unpack[Params],
218
234
  ) -> Response | Response[FormattableT]:
219
235
  """Implementation for call(). Subclasses override this method."""
@@ -261,7 +277,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
261
277
  tools: Sequence[Tool | ContextTool[DepsT]]
262
278
  | ContextToolkit[DepsT]
263
279
  | None = None,
264
- format: type[FormattableT] | Format[FormattableT] | None,
280
+ format: type[FormattableT]
281
+ | Format[FormattableT]
282
+ | OutputParser[FormattableT]
283
+ | None,
265
284
  **params: Unpack[Params],
266
285
  ) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
267
286
  """Generate an `llm.ContextResponse` with an optional response format."""
@@ -276,7 +295,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
276
295
  tools: Sequence[Tool | ContextTool[DepsT]]
277
296
  | ContextToolkit[DepsT]
278
297
  | None = None,
279
- format: type[FormattableT] | Format[FormattableT] | None = None,
298
+ format: type[FormattableT]
299
+ | Format[FormattableT]
300
+ | OutputParser[FormattableT]
301
+ | None = None,
280
302
  **params: Unpack[Params],
281
303
  ) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
282
304
  """Generate an `llm.ContextResponse` by synchronously calling this client's LLM provider.
@@ -312,7 +334,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
312
334
  tools: Sequence[Tool | ContextTool[DepsT]]
313
335
  | ContextToolkit[DepsT]
314
336
  | None = None,
315
- format: type[FormattableT] | Format[FormattableT] | None = None,
337
+ format: type[FormattableT]
338
+ | Format[FormattableT]
339
+ | OutputParser[FormattableT]
340
+ | None = None,
316
341
  **params: Unpack[Params],
317
342
  ) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
318
343
  """Implementation for context_call(). Subclasses override this method."""
@@ -351,7 +376,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
351
376
  model_id: str,
352
377
  messages: Sequence[Message],
353
378
  tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
354
- format: type[FormattableT] | Format[FormattableT] | None,
379
+ format: type[FormattableT]
380
+ | Format[FormattableT]
381
+ | OutputParser[FormattableT]
382
+ | None,
355
383
  **params: Unpack[Params],
356
384
  ) -> AsyncResponse | AsyncResponse[FormattableT]:
357
385
  """Generate an `llm.AsyncResponse` with an optional response format."""
@@ -363,7 +391,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
363
391
  model_id: str,
364
392
  messages: Sequence[Message],
365
393
  tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
366
- format: type[FormattableT] | Format[FormattableT] | None = None,
394
+ format: type[FormattableT]
395
+ | Format[FormattableT]
396
+ | OutputParser[FormattableT]
397
+ | None = None,
367
398
  **params: Unpack[Params],
368
399
  ) -> AsyncResponse | AsyncResponse[FormattableT]:
369
400
  """Generate an `llm.AsyncResponse` by asynchronously calling this client's LLM provider.
@@ -394,7 +425,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
394
425
  model_id: str,
395
426
  messages: Sequence[Message],
396
427
  tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
397
- format: type[FormattableT] | Format[FormattableT] | None = None,
428
+ format: type[FormattableT]
429
+ | Format[FormattableT]
430
+ | OutputParser[FormattableT]
431
+ | None = None,
398
432
  **params: Unpack[Params],
399
433
  ) -> AsyncResponse | AsyncResponse[FormattableT]:
400
434
  """Implementation for call_async(). Subclasses override this method."""
@@ -442,7 +476,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
442
476
  tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
443
477
  | AsyncContextToolkit[DepsT]
444
478
  | None = None,
445
- format: type[FormattableT] | Format[FormattableT] | None,
479
+ format: type[FormattableT]
480
+ | Format[FormattableT]
481
+ | OutputParser[FormattableT]
482
+ | None,
446
483
  **params: Unpack[Params],
447
484
  ) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
448
485
  """Generate an `llm.AsyncContextResponse` with an optional response format."""
@@ -457,7 +494,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
457
494
  tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
458
495
  | AsyncContextToolkit[DepsT]
459
496
  | None = None,
460
- format: type[FormattableT] | Format[FormattableT] | None = None,
497
+ format: type[FormattableT]
498
+ | Format[FormattableT]
499
+ | OutputParser[FormattableT]
500
+ | None = None,
461
501
  **params: Unpack[Params],
462
502
  ) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
463
503
  """Generate an `llm.AsyncContextResponse` by asynchronously calling this client's LLM provider.
@@ -493,7 +533,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
493
533
  tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
494
534
  | AsyncContextToolkit[DepsT]
495
535
  | None = None,
496
- format: type[FormattableT] | Format[FormattableT] | None = None,
536
+ format: type[FormattableT]
537
+ | Format[FormattableT]
538
+ | OutputParser[FormattableT]
539
+ | None = None,
497
540
  **params: Unpack[Params],
498
541
  ) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
499
542
  """Implementation for context_call_async(). Subclasses override this method."""
@@ -532,7 +575,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
532
575
  model_id: str,
533
576
  messages: Sequence[Message],
534
577
  tools: Sequence[Tool] | Toolkit | None = None,
535
- format: type[FormattableT] | Format[FormattableT] | None,
578
+ format: type[FormattableT]
579
+ | Format[FormattableT]
580
+ | OutputParser[FormattableT]
581
+ | None,
536
582
  **params: Unpack[Params],
537
583
  ) -> StreamResponse | StreamResponse[FormattableT]:
538
584
  """Stream an `llm.StreamResponse` with an optional response format."""
@@ -544,7 +590,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
544
590
  model_id: str,
545
591
  messages: Sequence[Message],
546
592
  tools: Sequence[Tool] | Toolkit | None = None,
547
- format: type[FormattableT] | Format[FormattableT] | None = None,
593
+ format: type[FormattableT]
594
+ | Format[FormattableT]
595
+ | OutputParser[FormattableT]
596
+ | None = None,
548
597
  **params: Unpack[Params],
549
598
  ) -> StreamResponse | StreamResponse[FormattableT]:
550
599
  """Generate an `llm.StreamResponse` by synchronously streaming from this client's LLM provider.
@@ -579,7 +628,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
579
628
  model_id: str,
580
629
  messages: Sequence[Message],
581
630
  tools: Sequence[Tool] | Toolkit | None = None,
582
- format: type[FormattableT] | Format[FormattableT] | None = None,
631
+ format: type[FormattableT]
632
+ | Format[FormattableT]
633
+ | OutputParser[FormattableT]
634
+ | None = None,
583
635
  **params: Unpack[Params],
584
636
  ) -> StreamResponse | StreamResponse[FormattableT]:
585
637
  """Implementation for stream(). Subclasses override this method."""
@@ -627,7 +679,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
627
679
  tools: Sequence[Tool | ContextTool[DepsT]]
628
680
  | ContextToolkit[DepsT]
629
681
  | None = None,
630
- format: type[FormattableT] | Format[FormattableT] | None,
682
+ format: type[FormattableT]
683
+ | Format[FormattableT]
684
+ | OutputParser[FormattableT]
685
+ | None,
631
686
  **params: Unpack[Params],
632
687
  ) -> (
633
688
  ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
@@ -644,7 +699,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
644
699
  tools: Sequence[Tool | ContextTool[DepsT]]
645
700
  | ContextToolkit[DepsT]
646
701
  | None = None,
647
- format: type[FormattableT] | Format[FormattableT] | None = None,
702
+ format: type[FormattableT]
703
+ | Format[FormattableT]
704
+ | OutputParser[FormattableT]
705
+ | None = None,
648
706
  **params: Unpack[Params],
649
707
  ) -> (
650
708
  ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
@@ -686,7 +744,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
686
744
  tools: Sequence[Tool | ContextTool[DepsT]]
687
745
  | ContextToolkit[DepsT]
688
746
  | None = None,
689
- format: type[FormattableT] | Format[FormattableT] | None = None,
747
+ format: type[FormattableT]
748
+ | Format[FormattableT]
749
+ | OutputParser[FormattableT]
750
+ | None = None,
690
751
  **params: Unpack[Params],
691
752
  ) -> (
692
753
  ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
@@ -727,7 +788,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
727
788
  model_id: str,
728
789
  messages: Sequence[Message],
729
790
  tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
730
- format: type[FormattableT] | Format[FormattableT] | None,
791
+ format: type[FormattableT]
792
+ | Format[FormattableT]
793
+ | OutputParser[FormattableT]
794
+ | None,
731
795
  **params: Unpack[Params],
732
796
  ) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
733
797
  """Stream an `llm.AsyncStreamResponse` with an optional response format."""
@@ -739,7 +803,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
739
803
  model_id: str,
740
804
  messages: Sequence[Message],
741
805
  tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
742
- format: type[FormattableT] | Format[FormattableT] | None = None,
806
+ format: type[FormattableT]
807
+ | Format[FormattableT]
808
+ | OutputParser[FormattableT]
809
+ | None = None,
743
810
  **params: Unpack[Params],
744
811
  ) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
745
812
  """Generate an `llm.AsyncStreamResponse` by asynchronously streaming from this client's LLM provider.
@@ -774,7 +841,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
774
841
  model_id: str,
775
842
  messages: Sequence[Message],
776
843
  tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
777
- format: type[FormattableT] | Format[FormattableT] | None = None,
844
+ format: type[FormattableT]
845
+ | Format[FormattableT]
846
+ | OutputParser[FormattableT]
847
+ | None = None,
778
848
  **params: Unpack[Params],
779
849
  ) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
780
850
  """Implementation for stream_async(). Subclasses override this method."""
@@ -822,7 +892,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
822
892
  tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
823
893
  | AsyncContextToolkit[DepsT]
824
894
  | None = None,
825
- format: type[FormattableT] | Format[FormattableT] | None,
895
+ format: type[FormattableT]
896
+ | Format[FormattableT]
897
+ | OutputParser[FormattableT]
898
+ | None,
826
899
  **params: Unpack[Params],
827
900
  ) -> (
828
901
  AsyncContextStreamResponse[DepsT, None]
@@ -840,7 +913,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
840
913
  tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
841
914
  | AsyncContextToolkit[DepsT]
842
915
  | None = None,
843
- format: type[FormattableT] | Format[FormattableT] | None = None,
916
+ format: type[FormattableT]
917
+ | Format[FormattableT]
918
+ | OutputParser[FormattableT]
919
+ | None = None,
844
920
  **params: Unpack[Params],
845
921
  ) -> (
846
922
  AsyncContextStreamResponse[DepsT, None]
@@ -883,7 +959,10 @@ class BaseProvider(Generic[ProviderClientT], ABC):
883
959
  tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
884
960
  | AsyncContextToolkit[DepsT]
885
961
  | None = None,
886
- format: type[FormattableT] | Format[FormattableT] | None = None,
962
+ format: type[FormattableT]
963
+ | Format[FormattableT]
964
+ | OutputParser[FormattableT]
965
+ | None = None,
887
966
  **params: Unpack[Params],
888
967
  ) -> (
889
968
  AsyncContextStreamResponse[DepsT, None]
@@ -1,21 +1,6 @@
1
1
  """Google client implementation."""
2
2
 
3
- from typing import TYPE_CHECKING
4
-
5
- if TYPE_CHECKING:
6
- from .model_id import GoogleModelId
7
- from .provider import GoogleProvider
8
- else:
9
- try:
10
- from .model_id import GoogleModelId
11
- from .provider import GoogleProvider
12
- except ImportError: # pragma: no cover
13
- from .._missing_import_stubs import (
14
- create_import_error_stub,
15
- create_provider_stub,
16
- )
17
-
18
- GoogleProvider = create_provider_stub("google", "GoogleProvider")
19
- GoogleModelId = str
3
+ from .model_id import GoogleModelId
4
+ from .provider import GoogleProvider
20
5
 
21
6
  __all__ = ["GoogleModelId", "GoogleProvider"]
@@ -1,3 +1,4 @@
1
+ from ...base._utils import get_include_thoughts
1
2
  from .decode import (
2
3
  decode_async_stream,
3
4
  decode_response,
@@ -12,4 +13,5 @@ __all__ = [
12
13
  "decode_response",
13
14
  "decode_stream",
14
15
  "encode_request",
16
+ "get_include_thoughts",
15
17
  ]
@@ -126,6 +126,8 @@ def _decode_candidate_content(
126
126
  def decode_response(
127
127
  response: genai_types.GenerateContentResponse,
128
128
  model_id: GoogleModelId,
129
+ *,
130
+ include_thoughts: bool,
129
131
  ) -> tuple[AssistantMessage, FinishReason | None, Usage | None]:
130
132
  """Returns an `AssistantMessage`, `FinishReason`, and `Usage` extracted from a `GenerateContentResponse`"""
131
133
  content: Sequence[AssistantContentPart] = []
@@ -134,6 +136,8 @@ def decode_response(
134
136
 
135
137
  if response.candidates and (candidate := response.candidates[0]):
136
138
  content = _decode_candidate_content(candidate)
139
+ if not include_thoughts:
140
+ content = [part for part in content if part.type != "thought"]
137
141
  candidate_content = candidate.content
138
142
  if candidate.finish_reason:
139
143
  finish_reason = GOOGLE_FINISH_REASON_MAP.get(candidate.finish_reason)
@@ -155,12 +159,13 @@ def decode_response(
155
159
  class _GoogleChunkProcessor:
156
160
  """Processes Google stream chunks and maintains state across chunks."""
157
161
 
158
- def __init__(self) -> None:
162
+ def __init__(self, *, include_thoughts: bool) -> None:
159
163
  self.current_content_type: Literal["text", "tool_call", "thought"] | None = None
160
164
  self.accumulated_parts: list[genai_types.Part] = []
161
165
  self.reconstructed_content = genai_types.Content(parts=[])
162
166
  # Track previous cumulative usage to compute deltas
163
167
  self.prev_usage = Usage()
168
+ self.include_thoughts = include_thoughts
164
169
 
165
170
  def process_chunk(
166
171
  self, chunk: genai_types.GenerateContentResponse
@@ -175,27 +180,34 @@ class _GoogleChunkProcessor:
175
180
  for part in candidate.content.parts:
176
181
  self.accumulated_parts.append(part)
177
182
  if self.current_content_type == "thought" and not part.thought:
178
- yield ThoughtEndChunk()
183
+ if self.include_thoughts:
184
+ yield ThoughtEndChunk()
179
185
  self.current_content_type = None
180
- elif self.current_content_type == "text" and not part.text:
181
- yield TextEndChunk() # pragma: no cover
182
- self.current_content_type = None # pragma: no cover
183
- elif self.current_content_type == "tool_call" and not part.function_call:
186
+ elif (
187
+ self.current_content_type == "text" and not part.text
188
+ ): # pragma: no cover
189
+ yield TextEndChunk()
190
+ self.current_content_type = None
191
+ elif (
192
+ self.current_content_type == "tool_call" and not part.function_call
193
+ ): # pragma: no cover
184
194
  # In testing, Gemini never emits tool calls and text in the same message
185
195
  # (even when specifically asked in system and user prompt), so
186
196
  # the following code is uncovered but included for completeness
187
- yield ToolCallEndChunk() # pragma: no cover
188
- self.current_content_type = None # pragma: no cover
197
+ yield ToolCallEndChunk(id=UNKNOWN_TOOL_ID)
198
+ self.current_content_type = None
189
199
 
190
200
  if part.thought:
191
201
  if self.current_content_type is None:
192
- yield ThoughtStartChunk()
202
+ if self.include_thoughts:
203
+ yield ThoughtStartChunk()
193
204
  self.current_content_type = "thought"
194
205
  if not part.text:
195
206
  raise ValueError(
196
207
  "Inside thought part with no text content"
197
208
  ) # pragma: no cover
198
- yield ThoughtChunk(delta=part.text)
209
+ if self.include_thoughts:
210
+ yield ThoughtChunk(delta=part.text)
199
211
 
200
212
  elif part.text:
201
213
  if self.current_content_type is None:
@@ -210,23 +222,29 @@ class _GoogleChunkProcessor:
210
222
  "Required name missing on Google function call"
211
223
  ) # pragma: no cover
212
224
 
225
+ tool_id = function_call.id or UNKNOWN_TOOL_ID
226
+ self.current_content_type = "tool_call"
227
+
213
228
  yield ToolCallStartChunk(
214
- id=function_call.id or UNKNOWN_TOOL_ID,
229
+ id=tool_id,
215
230
  name=function_call.name,
216
231
  )
217
232
 
218
233
  yield ToolCallChunk(
234
+ id=tool_id,
219
235
  delta=json.dumps(function_call.args)
220
236
  if function_call.args
221
237
  else "{}",
222
238
  )
223
- yield ToolCallEndChunk()
239
+ yield ToolCallEndChunk(id=tool_id)
240
+ self.current_content_type = None
224
241
 
225
242
  if candidate.finish_reason:
226
243
  if self.current_content_type == "text":
227
244
  yield TextEndChunk()
228
245
  elif self.current_content_type == "thought":
229
- yield ThoughtEndChunk() # pragma: no cover
246
+ if self.include_thoughts: # pragma: no cover
247
+ yield ThoughtEndChunk()
230
248
  elif self.current_content_type is not None:
231
249
  raise NotImplementedError
232
250
 
@@ -266,9 +284,11 @@ class _GoogleChunkProcessor:
266
284
 
267
285
  def decode_stream(
268
286
  google_stream: Iterator[genai_types.GenerateContentResponse],
287
+ *,
288
+ include_thoughts: bool,
269
289
  ) -> ChunkIterator:
270
290
  """Returns a ChunkIterator converted from a Google stream."""
271
- processor = _GoogleChunkProcessor()
291
+ processor = _GoogleChunkProcessor(include_thoughts=include_thoughts)
272
292
  for chunk in google_stream:
273
293
  yield from processor.process_chunk(chunk)
274
294
  yield processor.raw_message_chunk()
@@ -276,9 +296,11 @@ def decode_stream(
276
296
 
277
297
  async def decode_async_stream(
278
298
  google_stream: AsyncIterator[genai_types.GenerateContentResponse],
299
+ *,
300
+ include_thoughts: bool,
279
301
  ) -> AsyncChunkIterator:
280
302
  """Returns an AsyncChunkIterator converted from a Google async stream."""
281
- processor = _GoogleChunkProcessor()
303
+ processor = _GoogleChunkProcessor(include_thoughts=include_thoughts)
282
304
  async for chunk in google_stream:
283
305
  for item in processor.process_chunk(chunk):
284
306
  yield item