mirascope 2.0.0__py3-none-any.whl → 2.0.0a0__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.
- mirascope/__init__.py +2 -11
- mirascope/graphs/__init__.py +22 -0
- mirascope/graphs/finite_state_machine.py +625 -0
- mirascope/llm/__init__.py +16 -101
- mirascope/llm/agents/__init__.py +15 -0
- mirascope/llm/agents/agent.py +97 -0
- mirascope/llm/agents/agent_template.py +45 -0
- mirascope/llm/agents/decorator.py +176 -0
- mirascope/llm/calls/__init__.py +1 -2
- mirascope/llm/calls/base_call.py +33 -0
- mirascope/llm/calls/calls.py +58 -84
- mirascope/llm/calls/decorator.py +120 -140
- mirascope/llm/clients/__init__.py +34 -0
- mirascope/llm/clients/anthropic/__init__.py +11 -0
- mirascope/llm/{providers/openai/completions → clients/anthropic}/_utils/__init__.py +0 -2
- mirascope/llm/{providers → clients}/anthropic/_utils/decode.py +22 -66
- mirascope/llm/clients/anthropic/_utils/encode.py +243 -0
- mirascope/llm/clients/anthropic/clients.py +819 -0
- mirascope/llm/clients/anthropic/model_ids.py +8 -0
- mirascope/llm/{providers → clients}/base/__init__.py +5 -4
- mirascope/llm/{providers → clients}/base/_utils.py +17 -78
- mirascope/llm/{providers/base/base_provider.py → clients/base/client.py} +145 -468
- mirascope/llm/{models → clients/base}/params.py +37 -16
- mirascope/llm/clients/google/__init__.py +6 -0
- mirascope/llm/{providers/openai/responses → clients/google}/_utils/__init__.py +0 -2
- mirascope/llm/{providers → clients}/google/_utils/decode.py +22 -98
- mirascope/llm/{providers → clients}/google/_utils/encode.py +46 -168
- mirascope/llm/clients/google/clients.py +853 -0
- mirascope/llm/clients/google/model_ids.py +15 -0
- mirascope/llm/clients/openai/__init__.py +25 -0
- mirascope/llm/clients/openai/completions/__init__.py +9 -0
- mirascope/llm/{providers/google → clients/openai/completions}/_utils/__init__.py +0 -4
- mirascope/llm/{providers → clients}/openai/completions/_utils/decode.py +9 -74
- mirascope/llm/{providers → clients}/openai/completions/_utils/encode.py +52 -70
- mirascope/llm/clients/openai/completions/_utils/model_features.py +81 -0
- mirascope/llm/clients/openai/completions/clients.py +833 -0
- mirascope/llm/clients/openai/completions/model_ids.py +8 -0
- mirascope/llm/clients/openai/responses/__init__.py +9 -0
- mirascope/llm/clients/openai/responses/_utils/__init__.py +13 -0
- mirascope/llm/{providers → clients}/openai/responses/_utils/decode.py +14 -80
- mirascope/llm/{providers → clients}/openai/responses/_utils/encode.py +41 -92
- mirascope/llm/clients/openai/responses/_utils/model_features.py +87 -0
- mirascope/llm/clients/openai/responses/clients.py +832 -0
- mirascope/llm/clients/openai/responses/model_ids.py +8 -0
- mirascope/llm/clients/openai/shared/__init__.py +7 -0
- mirascope/llm/clients/openai/shared/_utils.py +55 -0
- mirascope/llm/clients/providers.py +175 -0
- mirascope/llm/content/__init__.py +2 -3
- mirascope/llm/content/tool_call.py +0 -6
- mirascope/llm/content/tool_output.py +5 -22
- mirascope/llm/context/_utils.py +6 -19
- mirascope/llm/exceptions.py +43 -298
- mirascope/llm/formatting/__init__.py +2 -19
- mirascope/llm/formatting/_utils.py +74 -0
- mirascope/llm/formatting/format.py +30 -219
- mirascope/llm/formatting/from_call_args.py +2 -2
- mirascope/llm/formatting/partial.py +7 -80
- mirascope/llm/formatting/types.py +64 -21
- mirascope/llm/mcp/__init__.py +2 -2
- mirascope/llm/mcp/client.py +118 -0
- mirascope/llm/messages/__init__.py +0 -3
- mirascope/llm/messages/message.py +5 -13
- mirascope/llm/models/__init__.py +2 -7
- mirascope/llm/models/models.py +139 -315
- mirascope/llm/prompts/__init__.py +12 -13
- mirascope/llm/prompts/_utils.py +43 -14
- mirascope/llm/prompts/decorator.py +204 -144
- mirascope/llm/prompts/protocols.py +59 -25
- mirascope/llm/responses/__init__.py +1 -9
- mirascope/llm/responses/_utils.py +12 -102
- mirascope/llm/responses/base_response.py +6 -18
- mirascope/llm/responses/base_stream_response.py +50 -173
- mirascope/llm/responses/finish_reason.py +0 -1
- mirascope/llm/responses/response.py +13 -34
- mirascope/llm/responses/root_response.py +29 -100
- mirascope/llm/responses/stream_response.py +31 -40
- mirascope/llm/tools/__init__.py +2 -9
- mirascope/llm/tools/_utils.py +3 -12
- mirascope/llm/tools/decorator.py +16 -25
- mirascope/llm/tools/protocols.py +4 -4
- mirascope/llm/tools/tool_schema.py +19 -87
- mirascope/llm/tools/toolkit.py +27 -35
- mirascope/llm/tools/tools.py +41 -135
- {mirascope-2.0.0.dist-info → mirascope-2.0.0a0.dist-info}/METADATA +9 -95
- mirascope-2.0.0a0.dist-info/RECORD +101 -0
- {mirascope-2.0.0.dist-info → mirascope-2.0.0a0.dist-info}/WHEEL +1 -1
- {mirascope-2.0.0.dist-info → mirascope-2.0.0a0.dist-info}/licenses/LICENSE +1 -1
- mirascope/_stubs.py +0 -363
- mirascope/api/__init__.py +0 -14
- mirascope/api/_generated/README.md +0 -207
- mirascope/api/_generated/__init__.py +0 -440
- mirascope/api/_generated/annotations/__init__.py +0 -33
- mirascope/api/_generated/annotations/client.py +0 -506
- mirascope/api/_generated/annotations/raw_client.py +0 -1414
- mirascope/api/_generated/annotations/types/__init__.py +0 -31
- mirascope/api/_generated/annotations/types/annotations_create_request_label.py +0 -5
- mirascope/api/_generated/annotations/types/annotations_create_response.py +0 -48
- mirascope/api/_generated/annotations/types/annotations_create_response_label.py +0 -5
- mirascope/api/_generated/annotations/types/annotations_get_response.py +0 -48
- mirascope/api/_generated/annotations/types/annotations_get_response_label.py +0 -5
- mirascope/api/_generated/annotations/types/annotations_list_request_label.py +0 -5
- mirascope/api/_generated/annotations/types/annotations_list_response.py +0 -21
- mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item.py +0 -50
- mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item_label.py +0 -5
- mirascope/api/_generated/annotations/types/annotations_update_request_label.py +0 -5
- mirascope/api/_generated/annotations/types/annotations_update_response.py +0 -48
- mirascope/api/_generated/annotations/types/annotations_update_response_label.py +0 -5
- mirascope/api/_generated/api_keys/__init__.py +0 -17
- mirascope/api/_generated/api_keys/client.py +0 -530
- mirascope/api/_generated/api_keys/raw_client.py +0 -1236
- mirascope/api/_generated/api_keys/types/__init__.py +0 -15
- mirascope/api/_generated/api_keys/types/api_keys_create_response.py +0 -28
- mirascope/api/_generated/api_keys/types/api_keys_get_response.py +0 -27
- mirascope/api/_generated/api_keys/types/api_keys_list_all_for_org_response_item.py +0 -40
- mirascope/api/_generated/api_keys/types/api_keys_list_response_item.py +0 -27
- mirascope/api/_generated/client.py +0 -211
- mirascope/api/_generated/core/__init__.py +0 -52
- mirascope/api/_generated/core/api_error.py +0 -23
- mirascope/api/_generated/core/client_wrapper.py +0 -46
- mirascope/api/_generated/core/datetime_utils.py +0 -28
- mirascope/api/_generated/core/file.py +0 -67
- mirascope/api/_generated/core/force_multipart.py +0 -16
- mirascope/api/_generated/core/http_client.py +0 -543
- mirascope/api/_generated/core/http_response.py +0 -55
- mirascope/api/_generated/core/jsonable_encoder.py +0 -100
- mirascope/api/_generated/core/pydantic_utilities.py +0 -255
- mirascope/api/_generated/core/query_encoder.py +0 -58
- mirascope/api/_generated/core/remove_none_from_dict.py +0 -11
- mirascope/api/_generated/core/request_options.py +0 -35
- mirascope/api/_generated/core/serialization.py +0 -276
- mirascope/api/_generated/docs/__init__.py +0 -4
- mirascope/api/_generated/docs/client.py +0 -91
- mirascope/api/_generated/docs/raw_client.py +0 -178
- mirascope/api/_generated/environment.py +0 -9
- mirascope/api/_generated/environments/__init__.py +0 -23
- mirascope/api/_generated/environments/client.py +0 -649
- mirascope/api/_generated/environments/raw_client.py +0 -1567
- mirascope/api/_generated/environments/types/__init__.py +0 -25
- mirascope/api/_generated/environments/types/environments_create_response.py +0 -24
- mirascope/api/_generated/environments/types/environments_get_analytics_response.py +0 -60
- mirascope/api/_generated/environments/types/environments_get_analytics_response_top_functions_item.py +0 -24
- mirascope/api/_generated/environments/types/environments_get_analytics_response_top_models_item.py +0 -22
- mirascope/api/_generated/environments/types/environments_get_response.py +0 -24
- mirascope/api/_generated/environments/types/environments_list_response_item.py +0 -24
- mirascope/api/_generated/environments/types/environments_update_response.py +0 -24
- mirascope/api/_generated/errors/__init__.py +0 -25
- mirascope/api/_generated/errors/bad_request_error.py +0 -14
- mirascope/api/_generated/errors/conflict_error.py +0 -14
- mirascope/api/_generated/errors/forbidden_error.py +0 -11
- mirascope/api/_generated/errors/internal_server_error.py +0 -10
- mirascope/api/_generated/errors/not_found_error.py +0 -11
- mirascope/api/_generated/errors/payment_required_error.py +0 -15
- mirascope/api/_generated/errors/service_unavailable_error.py +0 -14
- mirascope/api/_generated/errors/too_many_requests_error.py +0 -15
- mirascope/api/_generated/errors/unauthorized_error.py +0 -11
- mirascope/api/_generated/functions/__init__.py +0 -39
- mirascope/api/_generated/functions/client.py +0 -647
- mirascope/api/_generated/functions/raw_client.py +0 -1890
- mirascope/api/_generated/functions/types/__init__.py +0 -53
- mirascope/api/_generated/functions/types/functions_create_request_dependencies_value.py +0 -20
- mirascope/api/_generated/functions/types/functions_create_response.py +0 -37
- mirascope/api/_generated/functions/types/functions_create_response_dependencies_value.py +0 -20
- mirascope/api/_generated/functions/types/functions_find_by_hash_response.py +0 -39
- mirascope/api/_generated/functions/types/functions_find_by_hash_response_dependencies_value.py +0 -20
- mirascope/api/_generated/functions/types/functions_get_by_env_response.py +0 -53
- mirascope/api/_generated/functions/types/functions_get_by_env_response_dependencies_value.py +0 -22
- mirascope/api/_generated/functions/types/functions_get_response.py +0 -37
- mirascope/api/_generated/functions/types/functions_get_response_dependencies_value.py +0 -20
- mirascope/api/_generated/functions/types/functions_list_by_env_response.py +0 -25
- mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item.py +0 -56
- mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item_dependencies_value.py +0 -22
- mirascope/api/_generated/functions/types/functions_list_response.py +0 -21
- mirascope/api/_generated/functions/types/functions_list_response_functions_item.py +0 -41
- mirascope/api/_generated/functions/types/functions_list_response_functions_item_dependencies_value.py +0 -20
- mirascope/api/_generated/health/__init__.py +0 -7
- mirascope/api/_generated/health/client.py +0 -92
- mirascope/api/_generated/health/raw_client.py +0 -175
- mirascope/api/_generated/health/types/__init__.py +0 -8
- mirascope/api/_generated/health/types/health_check_response.py +0 -22
- mirascope/api/_generated/health/types/health_check_response_status.py +0 -5
- mirascope/api/_generated/organization_invitations/__init__.py +0 -33
- mirascope/api/_generated/organization_invitations/client.py +0 -546
- mirascope/api/_generated/organization_invitations/raw_client.py +0 -1519
- mirascope/api/_generated/organization_invitations/types/__init__.py +0 -53
- mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response.py +0 -34
- mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response_role.py +0 -7
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_request_role.py +0 -7
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response.py +0 -48
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_role.py +0 -7
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_status.py +0 -7
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response.py +0 -48
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_role.py +0 -7
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_status.py +0 -7
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item.py +0 -48
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_role.py +0 -7
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_status.py +0 -7
- mirascope/api/_generated/organization_memberships/__init__.py +0 -19
- mirascope/api/_generated/organization_memberships/client.py +0 -302
- mirascope/api/_generated/organization_memberships/raw_client.py +0 -736
- mirascope/api/_generated/organization_memberships/types/__init__.py +0 -27
- mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item.py +0 -33
- mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item_role.py +0 -7
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_request_role.py +0 -7
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response.py +0 -31
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response_role.py +0 -7
- mirascope/api/_generated/organizations/__init__.py +0 -51
- mirascope/api/_generated/organizations/client.py +0 -869
- mirascope/api/_generated/organizations/raw_client.py +0 -2593
- mirascope/api/_generated/organizations/types/__init__.py +0 -71
- mirascope/api/_generated/organizations/types/organizations_create_payment_intent_response.py +0 -24
- mirascope/api/_generated/organizations/types/organizations_create_response.py +0 -26
- mirascope/api/_generated/organizations/types/organizations_create_response_role.py +0 -5
- mirascope/api/_generated/organizations/types/organizations_get_response.py +0 -26
- mirascope/api/_generated/organizations/types/organizations_get_response_role.py +0 -5
- mirascope/api/_generated/organizations/types/organizations_list_response_item.py +0 -26
- mirascope/api/_generated/organizations/types/organizations_list_response_item_role.py +0 -5
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_request_target_plan.py +0 -7
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response.py +0 -47
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item.py +0 -33
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item_resource.py +0 -7
- mirascope/api/_generated/organizations/types/organizations_router_balance_response.py +0 -24
- mirascope/api/_generated/organizations/types/organizations_subscription_response.py +0 -53
- mirascope/api/_generated/organizations/types/organizations_subscription_response_current_plan.py +0 -7
- mirascope/api/_generated/organizations/types/organizations_subscription_response_payment_method.py +0 -26
- mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change.py +0 -34
- mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change_target_plan.py +0 -7
- mirascope/api/_generated/organizations/types/organizations_update_response.py +0 -26
- mirascope/api/_generated/organizations/types/organizations_update_response_role.py +0 -5
- mirascope/api/_generated/organizations/types/organizations_update_subscription_request_target_plan.py +0 -7
- mirascope/api/_generated/organizations/types/organizations_update_subscription_response.py +0 -35
- mirascope/api/_generated/project_memberships/__init__.py +0 -25
- mirascope/api/_generated/project_memberships/client.py +0 -437
- mirascope/api/_generated/project_memberships/raw_client.py +0 -1039
- mirascope/api/_generated/project_memberships/types/__init__.py +0 -29
- mirascope/api/_generated/project_memberships/types/project_memberships_create_request_role.py +0 -7
- mirascope/api/_generated/project_memberships/types/project_memberships_create_response.py +0 -35
- mirascope/api/_generated/project_memberships/types/project_memberships_create_response_role.py +0 -7
- mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item.py +0 -33
- mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item_role.py +0 -7
- mirascope/api/_generated/project_memberships/types/project_memberships_update_request_role.py +0 -7
- mirascope/api/_generated/project_memberships/types/project_memberships_update_response.py +0 -35
- mirascope/api/_generated/project_memberships/types/project_memberships_update_response_role.py +0 -7
- mirascope/api/_generated/projects/__init__.py +0 -7
- mirascope/api/_generated/projects/client.py +0 -428
- mirascope/api/_generated/projects/raw_client.py +0 -1302
- mirascope/api/_generated/projects/types/__init__.py +0 -10
- mirascope/api/_generated/projects/types/projects_create_response.py +0 -25
- mirascope/api/_generated/projects/types/projects_get_response.py +0 -25
- mirascope/api/_generated/projects/types/projects_list_response_item.py +0 -25
- mirascope/api/_generated/projects/types/projects_update_response.py +0 -25
- mirascope/api/_generated/reference.md +0 -4915
- mirascope/api/_generated/tags/__init__.py +0 -19
- mirascope/api/_generated/tags/client.py +0 -504
- mirascope/api/_generated/tags/raw_client.py +0 -1288
- mirascope/api/_generated/tags/types/__init__.py +0 -17
- mirascope/api/_generated/tags/types/tags_create_response.py +0 -41
- mirascope/api/_generated/tags/types/tags_get_response.py +0 -41
- mirascope/api/_generated/tags/types/tags_list_response.py +0 -23
- mirascope/api/_generated/tags/types/tags_list_response_tags_item.py +0 -41
- mirascope/api/_generated/tags/types/tags_update_response.py +0 -41
- mirascope/api/_generated/token_cost/__init__.py +0 -7
- mirascope/api/_generated/token_cost/client.py +0 -160
- mirascope/api/_generated/token_cost/raw_client.py +0 -264
- mirascope/api/_generated/token_cost/types/__init__.py +0 -8
- mirascope/api/_generated/token_cost/types/token_cost_calculate_request_usage.py +0 -54
- mirascope/api/_generated/token_cost/types/token_cost_calculate_response.py +0 -52
- mirascope/api/_generated/traces/__init__.py +0 -97
- mirascope/api/_generated/traces/client.py +0 -1103
- mirascope/api/_generated/traces/raw_client.py +0 -2322
- mirascope/api/_generated/traces/types/__init__.py +0 -155
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +0 -29
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +0 -27
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +0 -23
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +0 -38
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +0 -19
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +0 -22
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +0 -20
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +0 -29
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +0 -31
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +0 -23
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +0 -38
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +0 -19
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +0 -22
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value_values_item.py +0 -22
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +0 -48
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +0 -23
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +0 -38
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +0 -19
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +0 -24
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value_values_item.py +0 -22
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +0 -20
- mirascope/api/_generated/traces/types/traces_create_response.py +0 -24
- mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +0 -22
- mirascope/api/_generated/traces/types/traces_get_analytics_summary_response.py +0 -60
- mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_functions_item.py +0 -24
- mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_models_item.py +0 -22
- mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response.py +0 -33
- mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response_spans_item.py +0 -88
- mirascope/api/_generated/traces/types/traces_get_trace_detail_response.py +0 -33
- mirascope/api/_generated/traces/types/traces_get_trace_detail_response_spans_item.py +0 -88
- mirascope/api/_generated/traces/types/traces_list_by_function_hash_response.py +0 -25
- mirascope/api/_generated/traces/types/traces_list_by_function_hash_response_traces_item.py +0 -44
- mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item.py +0 -26
- mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item_operator.py +0 -7
- mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_by.py +0 -7
- mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_order.py +0 -7
- mirascope/api/_generated/traces/types/traces_search_by_env_response.py +0 -26
- mirascope/api/_generated/traces/types/traces_search_by_env_response_spans_item.py +0 -50
- mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item.py +0 -26
- mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item_operator.py +0 -7
- mirascope/api/_generated/traces/types/traces_search_request_sort_by.py +0 -7
- mirascope/api/_generated/traces/types/traces_search_request_sort_order.py +0 -5
- mirascope/api/_generated/traces/types/traces_search_response.py +0 -26
- mirascope/api/_generated/traces/types/traces_search_response_spans_item.py +0 -50
- mirascope/api/_generated/types/__init__.py +0 -85
- mirascope/api/_generated/types/already_exists_error.py +0 -22
- mirascope/api/_generated/types/already_exists_error_tag.py +0 -5
- mirascope/api/_generated/types/bad_request_error_body.py +0 -50
- mirascope/api/_generated/types/click_house_error.py +0 -22
- mirascope/api/_generated/types/database_error.py +0 -22
- mirascope/api/_generated/types/database_error_tag.py +0 -5
- mirascope/api/_generated/types/date.py +0 -3
- mirascope/api/_generated/types/http_api_decode_error.py +0 -27
- mirascope/api/_generated/types/http_api_decode_error_tag.py +0 -5
- mirascope/api/_generated/types/immutable_resource_error.py +0 -22
- mirascope/api/_generated/types/internal_server_error_body.py +0 -49
- mirascope/api/_generated/types/issue.py +0 -38
- mirascope/api/_generated/types/issue_tag.py +0 -10
- mirascope/api/_generated/types/not_found_error_body.py +0 -22
- mirascope/api/_generated/types/not_found_error_tag.py +0 -5
- mirascope/api/_generated/types/number_from_string.py +0 -3
- mirascope/api/_generated/types/permission_denied_error.py +0 -22
- mirascope/api/_generated/types/permission_denied_error_tag.py +0 -5
- mirascope/api/_generated/types/plan_limit_exceeded_error.py +0 -32
- mirascope/api/_generated/types/plan_limit_exceeded_error_tag.py +0 -7
- mirascope/api/_generated/types/pricing_unavailable_error.py +0 -23
- mirascope/api/_generated/types/property_key.py +0 -7
- mirascope/api/_generated/types/property_key_key.py +0 -25
- mirascope/api/_generated/types/property_key_key_tag.py +0 -5
- mirascope/api/_generated/types/rate_limit_error.py +0 -31
- mirascope/api/_generated/types/rate_limit_error_tag.py +0 -5
- mirascope/api/_generated/types/service_unavailable_error_body.py +0 -24
- mirascope/api/_generated/types/service_unavailable_error_tag.py +0 -7
- mirascope/api/_generated/types/stripe_error.py +0 -20
- mirascope/api/_generated/types/subscription_past_due_error.py +0 -31
- mirascope/api/_generated/types/subscription_past_due_error_tag.py +0 -7
- mirascope/api/_generated/types/unauthorized_error_body.py +0 -21
- mirascope/api/_generated/types/unauthorized_error_tag.py +0 -5
- mirascope/api/client.py +0 -255
- mirascope/api/settings.py +0 -99
- mirascope/llm/formatting/output_parser.py +0 -178
- mirascope/llm/formatting/primitives.py +0 -192
- mirascope/llm/mcp/mcp_client.py +0 -130
- mirascope/llm/messages/_utils.py +0 -34
- mirascope/llm/models/thinking_config.py +0 -61
- mirascope/llm/prompts/prompts.py +0 -487
- mirascope/llm/providers/__init__.py +0 -62
- mirascope/llm/providers/anthropic/__init__.py +0 -11
- mirascope/llm/providers/anthropic/_utils/__init__.py +0 -27
- mirascope/llm/providers/anthropic/_utils/beta_decode.py +0 -282
- mirascope/llm/providers/anthropic/_utils/beta_encode.py +0 -266
- mirascope/llm/providers/anthropic/_utils/encode.py +0 -418
- mirascope/llm/providers/anthropic/_utils/errors.py +0 -46
- mirascope/llm/providers/anthropic/beta_provider.py +0 -374
- mirascope/llm/providers/anthropic/model_id.py +0 -23
- mirascope/llm/providers/anthropic/model_info.py +0 -87
- mirascope/llm/providers/anthropic/provider.py +0 -479
- mirascope/llm/providers/google/__init__.py +0 -6
- mirascope/llm/providers/google/_utils/errors.py +0 -50
- mirascope/llm/providers/google/model_id.py +0 -22
- mirascope/llm/providers/google/model_info.py +0 -63
- mirascope/llm/providers/google/provider.py +0 -492
- mirascope/llm/providers/mirascope/__init__.py +0 -5
- mirascope/llm/providers/mirascope/_utils.py +0 -73
- mirascope/llm/providers/mirascope/provider.py +0 -349
- mirascope/llm/providers/mlx/__init__.py +0 -9
- mirascope/llm/providers/mlx/_utils.py +0 -141
- mirascope/llm/providers/mlx/encoding/__init__.py +0 -8
- mirascope/llm/providers/mlx/encoding/base.py +0 -72
- mirascope/llm/providers/mlx/encoding/transformers.py +0 -150
- mirascope/llm/providers/mlx/mlx.py +0 -254
- mirascope/llm/providers/mlx/model_id.py +0 -17
- mirascope/llm/providers/mlx/provider.py +0 -452
- mirascope/llm/providers/model_id.py +0 -16
- mirascope/llm/providers/ollama/__init__.py +0 -7
- mirascope/llm/providers/ollama/provider.py +0 -71
- mirascope/llm/providers/openai/__init__.py +0 -15
- mirascope/llm/providers/openai/_utils/__init__.py +0 -5
- mirascope/llm/providers/openai/_utils/errors.py +0 -46
- mirascope/llm/providers/openai/completions/__init__.py +0 -7
- mirascope/llm/providers/openai/completions/base_provider.py +0 -542
- mirascope/llm/providers/openai/completions/provider.py +0 -22
- mirascope/llm/providers/openai/model_id.py +0 -31
- mirascope/llm/providers/openai/model_info.py +0 -303
- mirascope/llm/providers/openai/provider.py +0 -441
- mirascope/llm/providers/openai/responses/__init__.py +0 -5
- mirascope/llm/providers/openai/responses/provider.py +0 -513
- mirascope/llm/providers/provider_id.py +0 -24
- mirascope/llm/providers/provider_registry.py +0 -299
- mirascope/llm/providers/together/__init__.py +0 -7
- mirascope/llm/providers/together/provider.py +0 -40
- mirascope/llm/responses/usage.py +0 -95
- mirascope/ops/__init__.py +0 -111
- mirascope/ops/_internal/__init__.py +0 -5
- mirascope/ops/_internal/closure.py +0 -1169
- mirascope/ops/_internal/configuration.py +0 -177
- mirascope/ops/_internal/context.py +0 -76
- mirascope/ops/_internal/exporters/__init__.py +0 -26
- mirascope/ops/_internal/exporters/exporters.py +0 -395
- mirascope/ops/_internal/exporters/processors.py +0 -104
- mirascope/ops/_internal/exporters/types.py +0 -165
- mirascope/ops/_internal/exporters/utils.py +0 -29
- mirascope/ops/_internal/instrumentation/__init__.py +0 -8
- mirascope/ops/_internal/instrumentation/llm/__init__.py +0 -8
- mirascope/ops/_internal/instrumentation/llm/common.py +0 -530
- mirascope/ops/_internal/instrumentation/llm/cost.py +0 -190
- mirascope/ops/_internal/instrumentation/llm/encode.py +0 -238
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/__init__.py +0 -38
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_input_messages.py +0 -31
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_output_messages.py +0 -38
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_system_instructions.py +0 -18
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/shared.py +0 -100
- mirascope/ops/_internal/instrumentation/llm/llm.py +0 -161
- mirascope/ops/_internal/instrumentation/llm/model.py +0 -1798
- mirascope/ops/_internal/instrumentation/llm/response.py +0 -521
- mirascope/ops/_internal/instrumentation/llm/serialize.py +0 -300
- mirascope/ops/_internal/propagation.py +0 -198
- mirascope/ops/_internal/protocols.py +0 -133
- mirascope/ops/_internal/session.py +0 -139
- mirascope/ops/_internal/spans.py +0 -232
- mirascope/ops/_internal/traced_calls.py +0 -375
- mirascope/ops/_internal/traced_functions.py +0 -523
- mirascope/ops/_internal/tracing.py +0 -353
- mirascope/ops/_internal/types.py +0 -13
- mirascope/ops/_internal/utils.py +0 -123
- mirascope/ops/_internal/versioned_calls.py +0 -512
- mirascope/ops/_internal/versioned_functions.py +0 -357
- mirascope/ops/_internal/versioning.py +0 -303
- mirascope/ops/exceptions.py +0 -21
- mirascope-2.0.0.dist-info/RECORD +0 -423
- /mirascope/llm/{providers → clients}/base/kwargs.py +0 -0
- /mirascope/llm/{providers → clients}/google/message.py +0 -0
|
@@ -3,22 +3,20 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from abc import ABC, abstractmethod
|
|
6
|
-
from collections.abc import
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
from
|
|
6
|
+
from collections.abc import Sequence
|
|
7
|
+
from contextvars import ContextVar, Token
|
|
8
|
+
from types import TracebackType
|
|
9
|
+
from typing import Generic, overload
|
|
10
|
+
from typing_extensions import Self, TypeVar, Unpack
|
|
10
11
|
|
|
11
12
|
from ...context import Context, DepsT
|
|
12
|
-
from ...
|
|
13
|
-
from ...formatting import Format, FormattableT, OutputParser
|
|
13
|
+
from ...formatting import Format, FormattableT
|
|
14
14
|
from ...messages import Message, UserContent, user
|
|
15
15
|
from ...responses import (
|
|
16
|
-
AsyncChunkIterator,
|
|
17
16
|
AsyncContextResponse,
|
|
18
17
|
AsyncContextStreamResponse,
|
|
19
18
|
AsyncResponse,
|
|
20
19
|
AsyncStreamResponse,
|
|
21
|
-
ChunkIterator,
|
|
22
20
|
ContextResponse,
|
|
23
21
|
ContextStreamResponse,
|
|
24
22
|
Response,
|
|
@@ -34,121 +32,53 @@ from ...tools import (
|
|
|
34
32
|
Tool,
|
|
35
33
|
Toolkit,
|
|
36
34
|
)
|
|
35
|
+
from .params import Params
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
from ...models import Params
|
|
40
|
-
from ..provider_id import ProviderId
|
|
41
|
-
|
|
37
|
+
ModelIdT = TypeVar("ModelIdT", bound=str)
|
|
42
38
|
ProviderClientT = TypeVar("ProviderClientT")
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
"""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
|
-
"""
|
|
40
|
+
ClientT = TypeVar("ClientT", bound="BaseClient")
|
|
41
|
+
"""Type variable for an LLM client."""
|
|
58
42
|
|
|
59
43
|
|
|
60
|
-
class
|
|
61
|
-
"""Base abstract
|
|
44
|
+
class BaseClient(Generic[ModelIdT, ProviderClientT], ABC):
|
|
45
|
+
"""Base abstract client for provider-specific implementations.
|
|
62
46
|
|
|
63
47
|
This class defines explicit methods for each type of call, eliminating
|
|
64
48
|
the need for complex overloads in provider implementations.
|
|
65
49
|
"""
|
|
66
50
|
|
|
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
51
|
client: ProviderClientT
|
|
52
|
+
_token: Token | None = None
|
|
91
53
|
|
|
92
|
-
@
|
|
93
|
-
|
|
94
|
-
|
|
54
|
+
@property
|
|
55
|
+
@abstractmethod
|
|
56
|
+
def _context_var(self) -> ContextVar:
|
|
57
|
+
"""The ContextVar for this client type."""
|
|
58
|
+
...
|
|
95
59
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
|
60
|
+
def __enter__(self) -> Self:
|
|
61
|
+
"""Sets the client context and stores the token."""
|
|
62
|
+
self._token = self._context_var.set(self)
|
|
63
|
+
return self
|
|
64
|
+
|
|
65
|
+
def __exit__(
|
|
66
|
+
self,
|
|
67
|
+
exc_type: type[BaseException] | None,
|
|
68
|
+
exc_val: BaseException | None,
|
|
69
|
+
exc_tb: TracebackType | None,
|
|
70
|
+
) -> None:
|
|
71
|
+
"""Restores the client context to the token from the last setting."""
|
|
72
|
+
if self._token is not None:
|
|
73
|
+
self._context_var.reset(self._token)
|
|
74
|
+
self._token = None
|
|
146
75
|
|
|
147
76
|
@overload
|
|
77
|
+
@abstractmethod
|
|
148
78
|
def call(
|
|
149
79
|
self,
|
|
150
80
|
*,
|
|
151
|
-
model_id:
|
|
81
|
+
model_id: ModelIdT,
|
|
152
82
|
messages: Sequence[Message],
|
|
153
83
|
tools: Sequence[Tool] | Toolkit | None = None,
|
|
154
84
|
format: None = None,
|
|
@@ -158,10 +88,11 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
158
88
|
...
|
|
159
89
|
|
|
160
90
|
@overload
|
|
91
|
+
@abstractmethod
|
|
161
92
|
def call(
|
|
162
93
|
self,
|
|
163
94
|
*,
|
|
164
|
-
model_id:
|
|
95
|
+
model_id: ModelIdT,
|
|
165
96
|
messages: Sequence[Message],
|
|
166
97
|
tools: Sequence[Tool] | Toolkit | None = None,
|
|
167
98
|
format: type[FormattableT] | Format[FormattableT],
|
|
@@ -171,31 +102,27 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
171
102
|
...
|
|
172
103
|
|
|
173
104
|
@overload
|
|
105
|
+
@abstractmethod
|
|
174
106
|
def call(
|
|
175
107
|
self,
|
|
176
108
|
*,
|
|
177
|
-
model_id:
|
|
109
|
+
model_id: ModelIdT,
|
|
178
110
|
messages: Sequence[Message],
|
|
179
111
|
tools: Sequence[Tool] | Toolkit | None = None,
|
|
180
|
-
format: type[FormattableT]
|
|
181
|
-
| Format[FormattableT]
|
|
182
|
-
| OutputParser[FormattableT]
|
|
183
|
-
| None,
|
|
112
|
+
format: type[FormattableT] | Format[FormattableT] | None,
|
|
184
113
|
**params: Unpack[Params],
|
|
185
114
|
) -> Response | Response[FormattableT]:
|
|
186
115
|
"""Generate an `llm.Response` with an optional response format."""
|
|
187
116
|
...
|
|
188
117
|
|
|
118
|
+
@abstractmethod
|
|
189
119
|
def call(
|
|
190
120
|
self,
|
|
191
121
|
*,
|
|
192
|
-
model_id:
|
|
122
|
+
model_id: ModelIdT,
|
|
193
123
|
messages: Sequence[Message],
|
|
194
124
|
tools: Sequence[Tool] | Toolkit | None = None,
|
|
195
|
-
format: type[FormattableT]
|
|
196
|
-
| Format[FormattableT]
|
|
197
|
-
| OutputParser[FormattableT]
|
|
198
|
-
| None = None,
|
|
125
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
199
126
|
**params: Unpack[Params],
|
|
200
127
|
) -> Response | Response[FormattableT]:
|
|
201
128
|
"""Generate an `llm.Response` by synchronously calling this client's LLM provider.
|
|
@@ -210,37 +137,15 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
210
137
|
Returns:
|
|
211
138
|
An `llm.Response` object containing the LLM-generated content.
|
|
212
139
|
"""
|
|
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
140
|
...
|
|
237
141
|
|
|
238
142
|
@overload
|
|
143
|
+
@abstractmethod
|
|
239
144
|
def context_call(
|
|
240
145
|
self,
|
|
241
146
|
*,
|
|
242
147
|
ctx: Context[DepsT],
|
|
243
|
-
model_id:
|
|
148
|
+
model_id: ModelIdT,
|
|
244
149
|
messages: Sequence[Message],
|
|
245
150
|
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
246
151
|
| ContextToolkit[DepsT]
|
|
@@ -252,11 +157,12 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
252
157
|
...
|
|
253
158
|
|
|
254
159
|
@overload
|
|
160
|
+
@abstractmethod
|
|
255
161
|
def context_call(
|
|
256
162
|
self,
|
|
257
163
|
*,
|
|
258
164
|
ctx: Context[DepsT],
|
|
259
|
-
model_id:
|
|
165
|
+
model_id: ModelIdT,
|
|
260
166
|
messages: Sequence[Message],
|
|
261
167
|
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
262
168
|
| ContextToolkit[DepsT]
|
|
@@ -268,37 +174,33 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
268
174
|
...
|
|
269
175
|
|
|
270
176
|
@overload
|
|
177
|
+
@abstractmethod
|
|
271
178
|
def context_call(
|
|
272
179
|
self,
|
|
273
180
|
*,
|
|
274
181
|
ctx: Context[DepsT],
|
|
275
|
-
model_id:
|
|
182
|
+
model_id: ModelIdT,
|
|
276
183
|
messages: Sequence[Message],
|
|
277
184
|
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
278
185
|
| ContextToolkit[DepsT]
|
|
279
186
|
| None = None,
|
|
280
|
-
format: type[FormattableT]
|
|
281
|
-
| Format[FormattableT]
|
|
282
|
-
| OutputParser[FormattableT]
|
|
283
|
-
| None,
|
|
187
|
+
format: type[FormattableT] | Format[FormattableT] | None,
|
|
284
188
|
**params: Unpack[Params],
|
|
285
189
|
) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
|
|
286
190
|
"""Generate an `llm.ContextResponse` with an optional response format."""
|
|
287
191
|
...
|
|
288
192
|
|
|
193
|
+
@abstractmethod
|
|
289
194
|
def context_call(
|
|
290
195
|
self,
|
|
291
196
|
*,
|
|
292
197
|
ctx: Context[DepsT],
|
|
293
|
-
model_id:
|
|
198
|
+
model_id: ModelIdT,
|
|
294
199
|
messages: Sequence[Message],
|
|
295
200
|
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
296
201
|
| ContextToolkit[DepsT]
|
|
297
202
|
| None = None,
|
|
298
|
-
format: type[FormattableT]
|
|
299
|
-
| Format[FormattableT]
|
|
300
|
-
| OutputParser[FormattableT]
|
|
301
|
-
| None = None,
|
|
203
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
302
204
|
**params: Unpack[Params],
|
|
303
205
|
) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
|
|
304
206
|
"""Generate an `llm.ContextResponse` by synchronously calling this client's LLM provider.
|
|
@@ -314,40 +216,14 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
314
216
|
Returns:
|
|
315
217
|
An `llm.ContextResponse` object containing the LLM-generated content.
|
|
316
218
|
"""
|
|
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
219
|
...
|
|
345
220
|
|
|
346
221
|
@overload
|
|
222
|
+
@abstractmethod
|
|
347
223
|
async def call_async(
|
|
348
224
|
self,
|
|
349
225
|
*,
|
|
350
|
-
model_id:
|
|
226
|
+
model_id: ModelIdT,
|
|
351
227
|
messages: Sequence[Message],
|
|
352
228
|
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
353
229
|
format: None = None,
|
|
@@ -357,10 +233,11 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
357
233
|
...
|
|
358
234
|
|
|
359
235
|
@overload
|
|
236
|
+
@abstractmethod
|
|
360
237
|
async def call_async(
|
|
361
238
|
self,
|
|
362
239
|
*,
|
|
363
|
-
model_id:
|
|
240
|
+
model_id: ModelIdT,
|
|
364
241
|
messages: Sequence[Message],
|
|
365
242
|
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
366
243
|
format: type[FormattableT] | Format[FormattableT],
|
|
@@ -370,31 +247,27 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
370
247
|
...
|
|
371
248
|
|
|
372
249
|
@overload
|
|
250
|
+
@abstractmethod
|
|
373
251
|
async def call_async(
|
|
374
252
|
self,
|
|
375
253
|
*,
|
|
376
|
-
model_id:
|
|
254
|
+
model_id: ModelIdT,
|
|
377
255
|
messages: Sequence[Message],
|
|
378
256
|
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
379
|
-
format: type[FormattableT]
|
|
380
|
-
| Format[FormattableT]
|
|
381
|
-
| OutputParser[FormattableT]
|
|
382
|
-
| None,
|
|
257
|
+
format: type[FormattableT] | Format[FormattableT] | None,
|
|
383
258
|
**params: Unpack[Params],
|
|
384
259
|
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
385
260
|
"""Generate an `llm.AsyncResponse` with an optional response format."""
|
|
386
261
|
...
|
|
387
262
|
|
|
263
|
+
@abstractmethod
|
|
388
264
|
async def call_async(
|
|
389
265
|
self,
|
|
390
266
|
*,
|
|
391
|
-
model_id:
|
|
267
|
+
model_id: ModelIdT,
|
|
392
268
|
messages: Sequence[Message],
|
|
393
269
|
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
394
|
-
format: type[FormattableT]
|
|
395
|
-
| Format[FormattableT]
|
|
396
|
-
| OutputParser[FormattableT]
|
|
397
|
-
| None = None,
|
|
270
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
398
271
|
**params: Unpack[Params],
|
|
399
272
|
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
400
273
|
"""Generate an `llm.AsyncResponse` by asynchronously calling this client's LLM provider.
|
|
@@ -409,37 +282,15 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
409
282
|
Returns:
|
|
410
283
|
An `llm.AsyncResponse` object containing the LLM-generated content.
|
|
411
284
|
"""
|
|
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
285
|
...
|
|
436
286
|
|
|
437
287
|
@overload
|
|
288
|
+
@abstractmethod
|
|
438
289
|
async def context_call_async(
|
|
439
290
|
self,
|
|
440
291
|
*,
|
|
441
292
|
ctx: Context[DepsT],
|
|
442
|
-
model_id:
|
|
293
|
+
model_id: ModelIdT,
|
|
443
294
|
messages: Sequence[Message],
|
|
444
295
|
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
445
296
|
| AsyncContextToolkit[DepsT]
|
|
@@ -451,11 +302,12 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
451
302
|
...
|
|
452
303
|
|
|
453
304
|
@overload
|
|
305
|
+
@abstractmethod
|
|
454
306
|
async def context_call_async(
|
|
455
307
|
self,
|
|
456
308
|
*,
|
|
457
309
|
ctx: Context[DepsT],
|
|
458
|
-
model_id:
|
|
310
|
+
model_id: ModelIdT,
|
|
459
311
|
messages: Sequence[Message],
|
|
460
312
|
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
461
313
|
| AsyncContextToolkit[DepsT]
|
|
@@ -467,37 +319,33 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
467
319
|
...
|
|
468
320
|
|
|
469
321
|
@overload
|
|
322
|
+
@abstractmethod
|
|
470
323
|
async def context_call_async(
|
|
471
324
|
self,
|
|
472
325
|
*,
|
|
473
326
|
ctx: Context[DepsT],
|
|
474
|
-
model_id:
|
|
327
|
+
model_id: ModelIdT,
|
|
475
328
|
messages: Sequence[Message],
|
|
476
329
|
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
477
330
|
| AsyncContextToolkit[DepsT]
|
|
478
331
|
| None = None,
|
|
479
|
-
format: type[FormattableT]
|
|
480
|
-
| Format[FormattableT]
|
|
481
|
-
| OutputParser[FormattableT]
|
|
482
|
-
| None,
|
|
332
|
+
format: type[FormattableT] | Format[FormattableT] | None,
|
|
483
333
|
**params: Unpack[Params],
|
|
484
334
|
) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
|
|
485
335
|
"""Generate an `llm.AsyncContextResponse` with an optional response format."""
|
|
486
336
|
...
|
|
487
337
|
|
|
338
|
+
@abstractmethod
|
|
488
339
|
async def context_call_async(
|
|
489
340
|
self,
|
|
490
341
|
*,
|
|
491
342
|
ctx: Context[DepsT],
|
|
492
|
-
model_id:
|
|
343
|
+
model_id: ModelIdT,
|
|
493
344
|
messages: Sequence[Message],
|
|
494
345
|
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
495
346
|
| AsyncContextToolkit[DepsT]
|
|
496
347
|
| None = None,
|
|
497
|
-
format: type[FormattableT]
|
|
498
|
-
| Format[FormattableT]
|
|
499
|
-
| OutputParser[FormattableT]
|
|
500
|
-
| None = None,
|
|
348
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
501
349
|
**params: Unpack[Params],
|
|
502
350
|
) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
|
|
503
351
|
"""Generate an `llm.AsyncContextResponse` by asynchronously calling this client's LLM provider.
|
|
@@ -513,40 +361,14 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
513
361
|
Returns:
|
|
514
362
|
An `llm.AsyncContextResponse` object containing the LLM-generated content.
|
|
515
363
|
"""
|
|
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
364
|
...
|
|
544
365
|
|
|
545
366
|
@overload
|
|
367
|
+
@abstractmethod
|
|
546
368
|
def stream(
|
|
547
369
|
self,
|
|
548
370
|
*,
|
|
549
|
-
model_id:
|
|
371
|
+
model_id: ModelIdT,
|
|
550
372
|
messages: Sequence[Message],
|
|
551
373
|
tools: Sequence[Tool] | Toolkit | None = None,
|
|
552
374
|
format: None = None,
|
|
@@ -556,10 +378,11 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
556
378
|
...
|
|
557
379
|
|
|
558
380
|
@overload
|
|
381
|
+
@abstractmethod
|
|
559
382
|
def stream(
|
|
560
383
|
self,
|
|
561
384
|
*,
|
|
562
|
-
model_id:
|
|
385
|
+
model_id: ModelIdT,
|
|
563
386
|
messages: Sequence[Message],
|
|
564
387
|
tools: Sequence[Tool] | Toolkit | None = None,
|
|
565
388
|
format: type[FormattableT] | Format[FormattableT],
|
|
@@ -569,31 +392,27 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
569
392
|
...
|
|
570
393
|
|
|
571
394
|
@overload
|
|
395
|
+
@abstractmethod
|
|
572
396
|
def stream(
|
|
573
397
|
self,
|
|
574
398
|
*,
|
|
575
|
-
model_id:
|
|
399
|
+
model_id: ModelIdT,
|
|
576
400
|
messages: Sequence[Message],
|
|
577
401
|
tools: Sequence[Tool] | Toolkit | None = None,
|
|
578
|
-
format: type[FormattableT]
|
|
579
|
-
| Format[FormattableT]
|
|
580
|
-
| OutputParser[FormattableT]
|
|
581
|
-
| None,
|
|
402
|
+
format: type[FormattableT] | Format[FormattableT] | None,
|
|
582
403
|
**params: Unpack[Params],
|
|
583
404
|
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
584
405
|
"""Stream an `llm.StreamResponse` with an optional response format."""
|
|
585
406
|
...
|
|
586
407
|
|
|
408
|
+
@abstractmethod
|
|
587
409
|
def stream(
|
|
588
410
|
self,
|
|
589
411
|
*,
|
|
590
|
-
model_id:
|
|
412
|
+
model_id: ModelIdT,
|
|
591
413
|
messages: Sequence[Message],
|
|
592
414
|
tools: Sequence[Tool] | Toolkit | None = None,
|
|
593
|
-
format: type[FormattableT]
|
|
594
|
-
| Format[FormattableT]
|
|
595
|
-
| OutputParser[FormattableT]
|
|
596
|
-
| None = None,
|
|
415
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
597
416
|
**params: Unpack[Params],
|
|
598
417
|
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
599
418
|
"""Generate an `llm.StreamResponse` by synchronously streaming from this client's LLM provider.
|
|
@@ -608,41 +427,15 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
608
427
|
Returns:
|
|
609
428
|
An `llm.StreamResponse` object for iterating over the LLM-generated content.
|
|
610
429
|
"""
|
|
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
430
|
...
|
|
639
431
|
|
|
640
432
|
@overload
|
|
433
|
+
@abstractmethod
|
|
641
434
|
def context_stream(
|
|
642
435
|
self,
|
|
643
436
|
*,
|
|
644
437
|
ctx: Context[DepsT],
|
|
645
|
-
model_id:
|
|
438
|
+
model_id: ModelIdT,
|
|
646
439
|
messages: Sequence[Message],
|
|
647
440
|
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
648
441
|
| ContextToolkit[DepsT]
|
|
@@ -654,11 +447,12 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
654
447
|
...
|
|
655
448
|
|
|
656
449
|
@overload
|
|
450
|
+
@abstractmethod
|
|
657
451
|
def context_stream(
|
|
658
452
|
self,
|
|
659
453
|
*,
|
|
660
454
|
ctx: Context[DepsT],
|
|
661
|
-
model_id:
|
|
455
|
+
model_id: ModelIdT,
|
|
662
456
|
messages: Sequence[Message],
|
|
663
457
|
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
664
458
|
| ContextToolkit[DepsT]
|
|
@@ -670,19 +464,17 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
670
464
|
...
|
|
671
465
|
|
|
672
466
|
@overload
|
|
467
|
+
@abstractmethod
|
|
673
468
|
def context_stream(
|
|
674
469
|
self,
|
|
675
470
|
*,
|
|
676
471
|
ctx: Context[DepsT],
|
|
677
|
-
model_id:
|
|
472
|
+
model_id: ModelIdT,
|
|
678
473
|
messages: Sequence[Message],
|
|
679
474
|
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
680
475
|
| ContextToolkit[DepsT]
|
|
681
476
|
| None = None,
|
|
682
|
-
format: type[FormattableT]
|
|
683
|
-
| Format[FormattableT]
|
|
684
|
-
| OutputParser[FormattableT]
|
|
685
|
-
| None,
|
|
477
|
+
format: type[FormattableT] | Format[FormattableT] | None,
|
|
686
478
|
**params: Unpack[Params],
|
|
687
479
|
) -> (
|
|
688
480
|
ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
|
|
@@ -690,19 +482,17 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
690
482
|
"""Stream an `llm.ContextStreamResponse` with an optional response format."""
|
|
691
483
|
...
|
|
692
484
|
|
|
485
|
+
@abstractmethod
|
|
693
486
|
def context_stream(
|
|
694
487
|
self,
|
|
695
488
|
*,
|
|
696
489
|
ctx: Context[DepsT],
|
|
697
|
-
model_id:
|
|
490
|
+
model_id: ModelIdT,
|
|
698
491
|
messages: Sequence[Message],
|
|
699
492
|
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
700
493
|
| ContextToolkit[DepsT]
|
|
701
494
|
| None = None,
|
|
702
|
-
format: type[FormattableT]
|
|
703
|
-
| Format[FormattableT]
|
|
704
|
-
| OutputParser[FormattableT]
|
|
705
|
-
| None = None,
|
|
495
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
706
496
|
**params: Unpack[Params],
|
|
707
497
|
) -> (
|
|
708
498
|
ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
|
|
@@ -720,46 +510,14 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
720
510
|
Returns:
|
|
721
511
|
An `llm.ContextStreamResponse` object for iterating over the LLM-generated content.
|
|
722
512
|
"""
|
|
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
513
|
...
|
|
757
514
|
|
|
758
515
|
@overload
|
|
516
|
+
@abstractmethod
|
|
759
517
|
async def stream_async(
|
|
760
518
|
self,
|
|
761
519
|
*,
|
|
762
|
-
model_id:
|
|
520
|
+
model_id: ModelIdT,
|
|
763
521
|
messages: Sequence[Message],
|
|
764
522
|
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
765
523
|
format: None = None,
|
|
@@ -769,10 +527,11 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
769
527
|
...
|
|
770
528
|
|
|
771
529
|
@overload
|
|
530
|
+
@abstractmethod
|
|
772
531
|
async def stream_async(
|
|
773
532
|
self,
|
|
774
533
|
*,
|
|
775
|
-
model_id:
|
|
534
|
+
model_id: ModelIdT,
|
|
776
535
|
messages: Sequence[Message],
|
|
777
536
|
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
778
537
|
format: type[FormattableT] | Format[FormattableT],
|
|
@@ -782,31 +541,27 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
782
541
|
...
|
|
783
542
|
|
|
784
543
|
@overload
|
|
544
|
+
@abstractmethod
|
|
785
545
|
async def stream_async(
|
|
786
546
|
self,
|
|
787
547
|
*,
|
|
788
|
-
model_id:
|
|
548
|
+
model_id: ModelIdT,
|
|
789
549
|
messages: Sequence[Message],
|
|
790
550
|
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
791
|
-
format: type[FormattableT]
|
|
792
|
-
| Format[FormattableT]
|
|
793
|
-
| OutputParser[FormattableT]
|
|
794
|
-
| None,
|
|
551
|
+
format: type[FormattableT] | Format[FormattableT] | None,
|
|
795
552
|
**params: Unpack[Params],
|
|
796
553
|
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
797
554
|
"""Stream an `llm.AsyncStreamResponse` with an optional response format."""
|
|
798
555
|
...
|
|
799
556
|
|
|
557
|
+
@abstractmethod
|
|
800
558
|
async def stream_async(
|
|
801
559
|
self,
|
|
802
560
|
*,
|
|
803
|
-
model_id:
|
|
561
|
+
model_id: ModelIdT,
|
|
804
562
|
messages: Sequence[Message],
|
|
805
563
|
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
806
|
-
format: type[FormattableT]
|
|
807
|
-
| Format[FormattableT]
|
|
808
|
-
| OutputParser[FormattableT]
|
|
809
|
-
| None = None,
|
|
564
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
810
565
|
**params: Unpack[Params],
|
|
811
566
|
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
812
567
|
"""Generate an `llm.AsyncStreamResponse` by asynchronously streaming from this client's LLM provider.
|
|
@@ -821,41 +576,15 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
821
576
|
Returns:
|
|
822
577
|
An `llm.AsyncStreamResponse` object for asynchronously iterating over the LLM-generated content.
|
|
823
578
|
"""
|
|
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
579
|
...
|
|
852
580
|
|
|
853
581
|
@overload
|
|
582
|
+
@abstractmethod
|
|
854
583
|
async def context_stream_async(
|
|
855
584
|
self,
|
|
856
585
|
*,
|
|
857
586
|
ctx: Context[DepsT],
|
|
858
|
-
model_id:
|
|
587
|
+
model_id: ModelIdT,
|
|
859
588
|
messages: Sequence[Message],
|
|
860
589
|
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
861
590
|
| AsyncContextToolkit[DepsT]
|
|
@@ -867,11 +596,12 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
867
596
|
...
|
|
868
597
|
|
|
869
598
|
@overload
|
|
599
|
+
@abstractmethod
|
|
870
600
|
async def context_stream_async(
|
|
871
601
|
self,
|
|
872
602
|
*,
|
|
873
603
|
ctx: Context[DepsT],
|
|
874
|
-
model_id:
|
|
604
|
+
model_id: ModelIdT,
|
|
875
605
|
messages: Sequence[Message],
|
|
876
606
|
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
877
607
|
| AsyncContextToolkit[DepsT]
|
|
@@ -883,19 +613,17 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
883
613
|
...
|
|
884
614
|
|
|
885
615
|
@overload
|
|
616
|
+
@abstractmethod
|
|
886
617
|
async def context_stream_async(
|
|
887
618
|
self,
|
|
888
619
|
*,
|
|
889
620
|
ctx: Context[DepsT],
|
|
890
|
-
model_id:
|
|
621
|
+
model_id: ModelIdT,
|
|
891
622
|
messages: Sequence[Message],
|
|
892
623
|
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
893
624
|
| AsyncContextToolkit[DepsT]
|
|
894
625
|
| None = None,
|
|
895
|
-
format: type[FormattableT]
|
|
896
|
-
| Format[FormattableT]
|
|
897
|
-
| OutputParser[FormattableT]
|
|
898
|
-
| None,
|
|
626
|
+
format: type[FormattableT] | Format[FormattableT] | None,
|
|
899
627
|
**params: Unpack[Params],
|
|
900
628
|
) -> (
|
|
901
629
|
AsyncContextStreamResponse[DepsT, None]
|
|
@@ -904,19 +632,17 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
904
632
|
"""Stream an `llm.AsyncContextStreamResponse` with an optional response format."""
|
|
905
633
|
...
|
|
906
634
|
|
|
635
|
+
@abstractmethod
|
|
907
636
|
async def context_stream_async(
|
|
908
637
|
self,
|
|
909
638
|
*,
|
|
910
639
|
ctx: Context[DepsT],
|
|
911
|
-
model_id:
|
|
640
|
+
model_id: ModelIdT,
|
|
912
641
|
messages: Sequence[Message],
|
|
913
642
|
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
914
643
|
| AsyncContextToolkit[DepsT]
|
|
915
644
|
| None = None,
|
|
916
|
-
format: type[FormattableT]
|
|
917
|
-
| Format[FormattableT]
|
|
918
|
-
| OutputParser[FormattableT]
|
|
919
|
-
| None = None,
|
|
645
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
920
646
|
**params: Unpack[Params],
|
|
921
647
|
) -> (
|
|
922
648
|
AsyncContextStreamResponse[DepsT, None]
|
|
@@ -935,47 +661,13 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
935
661
|
Returns:
|
|
936
662
|
An `llm.AsyncContextStreamResponse` object for asynchronously iterating over the LLM-generated content.
|
|
937
663
|
"""
|
|
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
664
|
...
|
|
973
665
|
|
|
974
666
|
@overload
|
|
975
667
|
def resume(
|
|
976
668
|
self,
|
|
977
669
|
*,
|
|
978
|
-
model_id:
|
|
670
|
+
model_id: ModelIdT,
|
|
979
671
|
response: Response,
|
|
980
672
|
content: UserContent,
|
|
981
673
|
**params: Unpack[Params],
|
|
@@ -987,7 +679,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
987
679
|
def resume(
|
|
988
680
|
self,
|
|
989
681
|
*,
|
|
990
|
-
model_id:
|
|
682
|
+
model_id: ModelIdT,
|
|
991
683
|
response: Response[FormattableT],
|
|
992
684
|
content: UserContent,
|
|
993
685
|
**params: Unpack[Params],
|
|
@@ -999,7 +691,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
999
691
|
def resume(
|
|
1000
692
|
self,
|
|
1001
693
|
*,
|
|
1002
|
-
model_id:
|
|
694
|
+
model_id: ModelIdT,
|
|
1003
695
|
response: Response | Response[FormattableT],
|
|
1004
696
|
content: UserContent,
|
|
1005
697
|
**params: Unpack[Params],
|
|
@@ -1010,7 +702,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1010
702
|
def resume(
|
|
1011
703
|
self,
|
|
1012
704
|
*,
|
|
1013
|
-
model_id:
|
|
705
|
+
model_id: ModelIdT,
|
|
1014
706
|
response: Response | Response[FormattableT],
|
|
1015
707
|
content: UserContent,
|
|
1016
708
|
**params: Unpack[Params],
|
|
@@ -1044,7 +736,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1044
736
|
async def resume_async(
|
|
1045
737
|
self,
|
|
1046
738
|
*,
|
|
1047
|
-
model_id:
|
|
739
|
+
model_id: ModelIdT,
|
|
1048
740
|
response: AsyncResponse,
|
|
1049
741
|
content: UserContent,
|
|
1050
742
|
**params: Unpack[Params],
|
|
@@ -1056,7 +748,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1056
748
|
async def resume_async(
|
|
1057
749
|
self,
|
|
1058
750
|
*,
|
|
1059
|
-
model_id:
|
|
751
|
+
model_id: ModelIdT,
|
|
1060
752
|
response: AsyncResponse[FormattableT],
|
|
1061
753
|
content: UserContent,
|
|
1062
754
|
**params: Unpack[Params],
|
|
@@ -1068,7 +760,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1068
760
|
async def resume_async(
|
|
1069
761
|
self,
|
|
1070
762
|
*,
|
|
1071
|
-
model_id:
|
|
763
|
+
model_id: ModelIdT,
|
|
1072
764
|
response: AsyncResponse | AsyncResponse[FormattableT],
|
|
1073
765
|
content: UserContent,
|
|
1074
766
|
**params: Unpack[Params],
|
|
@@ -1079,7 +771,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1079
771
|
async def resume_async(
|
|
1080
772
|
self,
|
|
1081
773
|
*,
|
|
1082
|
-
model_id:
|
|
774
|
+
model_id: ModelIdT,
|
|
1083
775
|
response: AsyncResponse | AsyncResponse[FormattableT],
|
|
1084
776
|
content: UserContent,
|
|
1085
777
|
**params: Unpack[Params],
|
|
@@ -1114,7 +806,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1114
806
|
self,
|
|
1115
807
|
*,
|
|
1116
808
|
ctx: Context[DepsT],
|
|
1117
|
-
model_id:
|
|
809
|
+
model_id: ModelIdT,
|
|
1118
810
|
response: ContextResponse[DepsT, None],
|
|
1119
811
|
content: UserContent,
|
|
1120
812
|
**params: Unpack[Params],
|
|
@@ -1127,7 +819,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1127
819
|
self,
|
|
1128
820
|
*,
|
|
1129
821
|
ctx: Context[DepsT],
|
|
1130
|
-
model_id:
|
|
822
|
+
model_id: ModelIdT,
|
|
1131
823
|
response: ContextResponse[DepsT, FormattableT],
|
|
1132
824
|
content: UserContent,
|
|
1133
825
|
**params: Unpack[Params],
|
|
@@ -1140,7 +832,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1140
832
|
self,
|
|
1141
833
|
*,
|
|
1142
834
|
ctx: Context[DepsT],
|
|
1143
|
-
model_id:
|
|
835
|
+
model_id: ModelIdT,
|
|
1144
836
|
response: ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT],
|
|
1145
837
|
content: UserContent,
|
|
1146
838
|
**params: Unpack[Params],
|
|
@@ -1152,7 +844,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1152
844
|
self,
|
|
1153
845
|
*,
|
|
1154
846
|
ctx: Context[DepsT],
|
|
1155
|
-
model_id:
|
|
847
|
+
model_id: ModelIdT,
|
|
1156
848
|
response: ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT],
|
|
1157
849
|
content: UserContent,
|
|
1158
850
|
**params: Unpack[Params],
|
|
@@ -1189,7 +881,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1189
881
|
self,
|
|
1190
882
|
*,
|
|
1191
883
|
ctx: Context[DepsT],
|
|
1192
|
-
model_id:
|
|
884
|
+
model_id: ModelIdT,
|
|
1193
885
|
response: AsyncContextResponse[DepsT, None],
|
|
1194
886
|
content: UserContent,
|
|
1195
887
|
**params: Unpack[Params],
|
|
@@ -1202,7 +894,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1202
894
|
self,
|
|
1203
895
|
*,
|
|
1204
896
|
ctx: Context[DepsT],
|
|
1205
|
-
model_id:
|
|
897
|
+
model_id: ModelIdT,
|
|
1206
898
|
response: AsyncContextResponse[DepsT, FormattableT],
|
|
1207
899
|
content: UserContent,
|
|
1208
900
|
**params: Unpack[Params],
|
|
@@ -1215,7 +907,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1215
907
|
self,
|
|
1216
908
|
*,
|
|
1217
909
|
ctx: Context[DepsT],
|
|
1218
|
-
model_id:
|
|
910
|
+
model_id: ModelIdT,
|
|
1219
911
|
response: AsyncContextResponse[DepsT, None]
|
|
1220
912
|
| AsyncContextResponse[DepsT, FormattableT],
|
|
1221
913
|
content: UserContent,
|
|
@@ -1228,7 +920,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1228
920
|
self,
|
|
1229
921
|
*,
|
|
1230
922
|
ctx: Context[DepsT],
|
|
1231
|
-
model_id:
|
|
923
|
+
model_id: ModelIdT,
|
|
1232
924
|
response: AsyncContextResponse[DepsT, None]
|
|
1233
925
|
| AsyncContextResponse[DepsT, FormattableT],
|
|
1234
926
|
content: UserContent,
|
|
@@ -1265,7 +957,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1265
957
|
def resume_stream(
|
|
1266
958
|
self,
|
|
1267
959
|
*,
|
|
1268
|
-
model_id:
|
|
960
|
+
model_id: ModelIdT,
|
|
1269
961
|
response: StreamResponse,
|
|
1270
962
|
content: UserContent,
|
|
1271
963
|
**params: Unpack[Params],
|
|
@@ -1277,7 +969,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1277
969
|
def resume_stream(
|
|
1278
970
|
self,
|
|
1279
971
|
*,
|
|
1280
|
-
model_id:
|
|
972
|
+
model_id: ModelIdT,
|
|
1281
973
|
response: StreamResponse[FormattableT],
|
|
1282
974
|
content: UserContent,
|
|
1283
975
|
**params: Unpack[Params],
|
|
@@ -1289,7 +981,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1289
981
|
def resume_stream(
|
|
1290
982
|
self,
|
|
1291
983
|
*,
|
|
1292
|
-
model_id:
|
|
984
|
+
model_id: ModelIdT,
|
|
1293
985
|
response: StreamResponse | StreamResponse[FormattableT],
|
|
1294
986
|
content: UserContent,
|
|
1295
987
|
**params: Unpack[Params],
|
|
@@ -1300,7 +992,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1300
992
|
def resume_stream(
|
|
1301
993
|
self,
|
|
1302
994
|
*,
|
|
1303
|
-
model_id:
|
|
995
|
+
model_id: ModelIdT,
|
|
1304
996
|
response: StreamResponse | StreamResponse[FormattableT],
|
|
1305
997
|
content: UserContent,
|
|
1306
998
|
**params: Unpack[Params],
|
|
@@ -1334,7 +1026,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1334
1026
|
async def resume_stream_async(
|
|
1335
1027
|
self,
|
|
1336
1028
|
*,
|
|
1337
|
-
model_id:
|
|
1029
|
+
model_id: ModelIdT,
|
|
1338
1030
|
response: AsyncStreamResponse,
|
|
1339
1031
|
content: UserContent,
|
|
1340
1032
|
**params: Unpack[Params],
|
|
@@ -1346,7 +1038,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1346
1038
|
async def resume_stream_async(
|
|
1347
1039
|
self,
|
|
1348
1040
|
*,
|
|
1349
|
-
model_id:
|
|
1041
|
+
model_id: ModelIdT,
|
|
1350
1042
|
response: AsyncStreamResponse[FormattableT],
|
|
1351
1043
|
content: UserContent,
|
|
1352
1044
|
**params: Unpack[Params],
|
|
@@ -1358,7 +1050,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1358
1050
|
async def resume_stream_async(
|
|
1359
1051
|
self,
|
|
1360
1052
|
*,
|
|
1361
|
-
model_id:
|
|
1053
|
+
model_id: ModelIdT,
|
|
1362
1054
|
response: AsyncStreamResponse | AsyncStreamResponse[FormattableT],
|
|
1363
1055
|
content: UserContent,
|
|
1364
1056
|
**params: Unpack[Params],
|
|
@@ -1369,7 +1061,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1369
1061
|
async def resume_stream_async(
|
|
1370
1062
|
self,
|
|
1371
1063
|
*,
|
|
1372
|
-
model_id:
|
|
1064
|
+
model_id: ModelIdT,
|
|
1373
1065
|
response: AsyncStreamResponse | AsyncStreamResponse[FormattableT],
|
|
1374
1066
|
content: UserContent,
|
|
1375
1067
|
**params: Unpack[Params],
|
|
@@ -1404,7 +1096,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1404
1096
|
self,
|
|
1405
1097
|
*,
|
|
1406
1098
|
ctx: Context[DepsT],
|
|
1407
|
-
model_id:
|
|
1099
|
+
model_id: ModelIdT,
|
|
1408
1100
|
response: ContextStreamResponse[DepsT, None],
|
|
1409
1101
|
content: UserContent,
|
|
1410
1102
|
**params: Unpack[Params],
|
|
@@ -1417,7 +1109,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1417
1109
|
self,
|
|
1418
1110
|
*,
|
|
1419
1111
|
ctx: Context[DepsT],
|
|
1420
|
-
model_id:
|
|
1112
|
+
model_id: ModelIdT,
|
|
1421
1113
|
response: ContextStreamResponse[DepsT, FormattableT],
|
|
1422
1114
|
content: UserContent,
|
|
1423
1115
|
**params: Unpack[Params],
|
|
@@ -1430,7 +1122,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1430
1122
|
self,
|
|
1431
1123
|
*,
|
|
1432
1124
|
ctx: Context[DepsT],
|
|
1433
|
-
model_id:
|
|
1125
|
+
model_id: ModelIdT,
|
|
1434
1126
|
response: ContextStreamResponse[DepsT, None]
|
|
1435
1127
|
| ContextStreamResponse[DepsT, FormattableT],
|
|
1436
1128
|
content: UserContent,
|
|
@@ -1445,7 +1137,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1445
1137
|
self,
|
|
1446
1138
|
*,
|
|
1447
1139
|
ctx: Context[DepsT],
|
|
1448
|
-
model_id:
|
|
1140
|
+
model_id: ModelIdT,
|
|
1449
1141
|
response: ContextStreamResponse[DepsT, None]
|
|
1450
1142
|
| ContextStreamResponse[DepsT, FormattableT],
|
|
1451
1143
|
content: UserContent,
|
|
@@ -1485,7 +1177,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1485
1177
|
self,
|
|
1486
1178
|
*,
|
|
1487
1179
|
ctx: Context[DepsT],
|
|
1488
|
-
model_id:
|
|
1180
|
+
model_id: ModelIdT,
|
|
1489
1181
|
response: AsyncContextStreamResponse[DepsT, None],
|
|
1490
1182
|
content: UserContent,
|
|
1491
1183
|
**params: Unpack[Params],
|
|
@@ -1498,7 +1190,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1498
1190
|
self,
|
|
1499
1191
|
*,
|
|
1500
1192
|
ctx: Context[DepsT],
|
|
1501
|
-
model_id:
|
|
1193
|
+
model_id: ModelIdT,
|
|
1502
1194
|
response: AsyncContextStreamResponse[DepsT, FormattableT],
|
|
1503
1195
|
content: UserContent,
|
|
1504
1196
|
**params: Unpack[Params],
|
|
@@ -1511,7 +1203,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1511
1203
|
self,
|
|
1512
1204
|
*,
|
|
1513
1205
|
ctx: Context[DepsT],
|
|
1514
|
-
model_id:
|
|
1206
|
+
model_id: ModelIdT,
|
|
1515
1207
|
response: AsyncContextStreamResponse[DepsT, None]
|
|
1516
1208
|
| AsyncContextStreamResponse[DepsT, FormattableT],
|
|
1517
1209
|
content: UserContent,
|
|
@@ -1527,7 +1219,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1527
1219
|
self,
|
|
1528
1220
|
*,
|
|
1529
1221
|
ctx: Context[DepsT],
|
|
1530
|
-
model_id:
|
|
1222
|
+
model_id: ModelIdT,
|
|
1531
1223
|
response: AsyncContextStreamResponse[DepsT, None]
|
|
1532
1224
|
| AsyncContextStreamResponse[DepsT, FormattableT],
|
|
1533
1225
|
content: UserContent,
|
|
@@ -1562,18 +1254,3 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1562
1254
|
format=response.format,
|
|
1563
1255
|
**params,
|
|
1564
1256
|
)
|
|
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
|
-
...
|