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.
- mirascope/__init__.py +10 -1
- mirascope/_stubs.py +363 -0
- mirascope/api/__init__.py +8 -0
- mirascope/api/_generated/__init__.py +285 -2
- mirascope/api/_generated/annotations/__init__.py +33 -0
- mirascope/api/_generated/annotations/client.py +506 -0
- mirascope/api/_generated/annotations/raw_client.py +1414 -0
- mirascope/api/_generated/annotations/types/__init__.py +31 -0
- mirascope/api/_generated/annotations/types/annotations_create_request_label.py +5 -0
- mirascope/api/_generated/annotations/types/annotations_create_response.py +48 -0
- mirascope/api/_generated/annotations/types/annotations_create_response_label.py +5 -0
- mirascope/api/_generated/annotations/types/annotations_get_response.py +48 -0
- mirascope/api/_generated/annotations/types/annotations_get_response_label.py +5 -0
- mirascope/api/_generated/annotations/types/annotations_list_request_label.py +5 -0
- mirascope/api/_generated/annotations/types/annotations_list_response.py +21 -0
- mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item.py +50 -0
- mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item_label.py +5 -0
- mirascope/api/_generated/annotations/types/annotations_update_request_label.py +5 -0
- mirascope/api/_generated/annotations/types/annotations_update_response.py +48 -0
- mirascope/api/_generated/annotations/types/annotations_update_response_label.py +5 -0
- mirascope/api/_generated/api_keys/__init__.py +12 -2
- mirascope/api/_generated/api_keys/client.py +77 -0
- mirascope/api/_generated/api_keys/raw_client.py +422 -39
- mirascope/api/_generated/api_keys/types/__init__.py +7 -1
- mirascope/api/_generated/api_keys/types/api_keys_create_response.py +4 -12
- mirascope/api/_generated/api_keys/types/api_keys_get_response.py +4 -12
- mirascope/api/_generated/api_keys/types/api_keys_list_all_for_org_response_item.py +40 -0
- mirascope/api/_generated/api_keys/types/api_keys_list_response_item.py +4 -12
- mirascope/api/_generated/client.py +42 -0
- mirascope/api/_generated/core/client_wrapper.py +2 -14
- mirascope/api/_generated/core/datetime_utils.py +1 -3
- mirascope/api/_generated/core/file.py +2 -5
- mirascope/api/_generated/core/http_client.py +36 -112
- mirascope/api/_generated/core/jsonable_encoder.py +1 -3
- mirascope/api/_generated/core/pydantic_utilities.py +19 -74
- mirascope/api/_generated/core/query_encoder.py +1 -3
- mirascope/api/_generated/core/serialization.py +4 -10
- mirascope/api/_generated/docs/client.py +2 -6
- mirascope/api/_generated/docs/raw_client.py +51 -5
- mirascope/api/_generated/environment.py +3 -3
- mirascope/api/_generated/environments/__init__.py +6 -0
- mirascope/api/_generated/environments/client.py +117 -0
- mirascope/api/_generated/environments/raw_client.py +530 -51
- mirascope/api/_generated/environments/types/__init__.py +10 -0
- mirascope/api/_generated/environments/types/environments_create_response.py +1 -3
- mirascope/api/_generated/environments/types/environments_get_analytics_response.py +60 -0
- mirascope/api/_generated/environments/types/environments_get_analytics_response_top_functions_item.py +24 -0
- mirascope/api/_generated/environments/types/environments_get_analytics_response_top_models_item.py +22 -0
- mirascope/api/_generated/environments/types/environments_get_response.py +1 -3
- mirascope/api/_generated/environments/types/environments_list_response_item.py +1 -3
- mirascope/api/_generated/environments/types/environments_update_response.py +1 -3
- mirascope/api/_generated/errors/__init__.py +8 -0
- mirascope/api/_generated/errors/bad_request_error.py +1 -2
- mirascope/api/_generated/errors/conflict_error.py +1 -2
- mirascope/api/_generated/errors/forbidden_error.py +1 -5
- mirascope/api/_generated/errors/internal_server_error.py +1 -6
- mirascope/api/_generated/errors/not_found_error.py +1 -5
- mirascope/api/_generated/errors/payment_required_error.py +15 -0
- mirascope/api/_generated/errors/service_unavailable_error.py +14 -0
- mirascope/api/_generated/errors/too_many_requests_error.py +15 -0
- mirascope/api/_generated/errors/unauthorized_error.py +11 -0
- mirascope/api/_generated/functions/__init__.py +39 -0
- mirascope/api/_generated/functions/client.py +647 -0
- mirascope/api/_generated/functions/raw_client.py +1890 -0
- mirascope/api/_generated/functions/types/__init__.py +53 -0
- mirascope/api/_generated/functions/types/functions_create_request_dependencies_value.py +20 -0
- mirascope/api/_generated/functions/types/functions_create_response.py +37 -0
- mirascope/api/_generated/functions/types/functions_create_response_dependencies_value.py +20 -0
- mirascope/api/_generated/functions/types/functions_find_by_hash_response.py +39 -0
- mirascope/api/_generated/functions/types/functions_find_by_hash_response_dependencies_value.py +20 -0
- mirascope/api/_generated/functions/types/functions_get_by_env_response.py +53 -0
- mirascope/api/_generated/functions/types/functions_get_by_env_response_dependencies_value.py +22 -0
- mirascope/api/_generated/functions/types/functions_get_response.py +37 -0
- mirascope/api/_generated/functions/types/functions_get_response_dependencies_value.py +20 -0
- mirascope/api/_generated/functions/types/functions_list_by_env_response.py +25 -0
- mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item.py +56 -0
- mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item_dependencies_value.py +22 -0
- mirascope/api/_generated/functions/types/functions_list_response.py +21 -0
- mirascope/api/_generated/functions/types/functions_list_response_functions_item.py +41 -0
- mirascope/api/_generated/functions/types/functions_list_response_functions_item_dependencies_value.py +20 -0
- mirascope/api/_generated/health/client.py +2 -6
- mirascope/api/_generated/health/raw_client.py +51 -5
- mirascope/api/_generated/health/types/health_check_response.py +1 -3
- mirascope/api/_generated/organization_invitations/__init__.py +33 -0
- mirascope/api/_generated/organization_invitations/client.py +546 -0
- mirascope/api/_generated/organization_invitations/raw_client.py +1519 -0
- mirascope/api/_generated/organization_invitations/types/__init__.py +53 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response.py +34 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_request_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response.py +48 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_status.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response.py +48 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_status.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item.py +48 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_status.py +7 -0
- mirascope/api/_generated/organization_memberships/__init__.py +19 -0
- mirascope/api/_generated/organization_memberships/client.py +302 -0
- mirascope/api/_generated/organization_memberships/raw_client.py +736 -0
- mirascope/api/_generated/organization_memberships/types/__init__.py +27 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item.py +33 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item_role.py +7 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_request_role.py +7 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response.py +31 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response_role.py +7 -0
- mirascope/api/_generated/organizations/__init__.py +26 -0
- mirascope/api/_generated/organizations/client.py +465 -0
- mirascope/api/_generated/organizations/raw_client.py +1799 -108
- mirascope/api/_generated/organizations/types/__init__.py +48 -0
- mirascope/api/_generated/organizations/types/organizations_create_payment_intent_response.py +24 -0
- mirascope/api/_generated/organizations/types/organizations_create_response.py +4 -3
- mirascope/api/_generated/organizations/types/organizations_create_response_role.py +1 -3
- mirascope/api/_generated/organizations/types/organizations_get_response.py +4 -3
- mirascope/api/_generated/organizations/types/organizations_get_response_role.py +1 -3
- mirascope/api/_generated/organizations/types/organizations_list_response_item.py +4 -3
- mirascope/api/_generated/organizations/types/organizations_list_response_item_role.py +1 -3
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_request_target_plan.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response.py +47 -0
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item.py +33 -0
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item_resource.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_router_balance_response.py +24 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response.py +53 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response_current_plan.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response_payment_method.py +26 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change.py +34 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change_target_plan.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_update_response.py +4 -3
- mirascope/api/_generated/organizations/types/organizations_update_response_role.py +1 -3
- mirascope/api/_generated/organizations/types/organizations_update_subscription_request_target_plan.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_update_subscription_response.py +35 -0
- mirascope/api/_generated/project_memberships/__init__.py +25 -0
- mirascope/api/_generated/project_memberships/client.py +437 -0
- mirascope/api/_generated/project_memberships/raw_client.py +1039 -0
- mirascope/api/_generated/project_memberships/types/__init__.py +29 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_create_request_role.py +7 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_create_response.py +35 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_create_response_role.py +7 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item.py +33 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item_role.py +7 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_update_request_role.py +7 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_update_response.py +35 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_update_response_role.py +7 -0
- mirascope/api/_generated/projects/__init__.py +2 -12
- mirascope/api/_generated/projects/client.py +17 -71
- mirascope/api/_generated/projects/raw_client.py +295 -51
- mirascope/api/_generated/projects/types/__init__.py +1 -6
- mirascope/api/_generated/projects/types/projects_create_response.py +3 -9
- mirascope/api/_generated/projects/types/projects_get_response.py +3 -9
- mirascope/api/_generated/projects/types/projects_list_response_item.py +3 -9
- mirascope/api/_generated/projects/types/projects_update_response.py +3 -9
- mirascope/api/_generated/reference.md +3619 -182
- mirascope/api/_generated/tags/__init__.py +19 -0
- mirascope/api/_generated/tags/client.py +504 -0
- mirascope/api/_generated/tags/raw_client.py +1288 -0
- mirascope/api/_generated/tags/types/__init__.py +17 -0
- mirascope/api/_generated/tags/types/tags_create_response.py +41 -0
- mirascope/api/_generated/tags/types/tags_get_response.py +41 -0
- mirascope/api/_generated/tags/types/tags_list_response.py +23 -0
- mirascope/api/_generated/tags/types/tags_list_response_tags_item.py +41 -0
- mirascope/api/_generated/tags/types/tags_update_response.py +41 -0
- mirascope/api/_generated/token_cost/__init__.py +7 -0
- mirascope/api/_generated/token_cost/client.py +160 -0
- mirascope/api/_generated/token_cost/raw_client.py +264 -0
- mirascope/api/_generated/token_cost/types/__init__.py +8 -0
- mirascope/api/_generated/token_cost/types/token_cost_calculate_request_usage.py +54 -0
- mirascope/api/_generated/token_cost/types/token_cost_calculate_response.py +52 -0
- mirascope/api/_generated/traces/__init__.py +42 -0
- mirascope/api/_generated/traces/client.py +941 -0
- mirascope/api/_generated/traces/raw_client.py +2177 -23
- mirascope/api/_generated/traces/types/__init__.py +60 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +4 -11
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +2 -6
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +1 -3
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +8 -24
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +2 -6
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +3 -9
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +2 -6
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +3 -9
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +4 -8
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +2 -6
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +8 -24
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +2 -6
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +3 -9
- 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
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +6 -18
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +3 -9
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +8 -24
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +2 -6
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +2 -6
- 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
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +2 -6
- mirascope/api/_generated/traces/types/traces_create_response.py +2 -5
- mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +3 -9
- mirascope/api/_generated/traces/types/traces_get_analytics_summary_response.py +60 -0
- mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_functions_item.py +24 -0
- mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_models_item.py +22 -0
- mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response.py +33 -0
- mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response_spans_item.py +88 -0
- mirascope/api/_generated/traces/types/traces_get_trace_detail_response.py +33 -0
- mirascope/api/_generated/traces/types/traces_get_trace_detail_response_spans_item.py +88 -0
- mirascope/api/_generated/traces/types/traces_list_by_function_hash_response.py +25 -0
- mirascope/api/_generated/traces/types/traces_list_by_function_hash_response_traces_item.py +44 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item.py +26 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item_operator.py +7 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_by.py +7 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_order.py +7 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_response.py +26 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_response_spans_item.py +50 -0
- mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item.py +26 -0
- mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item_operator.py +7 -0
- mirascope/api/_generated/traces/types/traces_search_request_sort_by.py +7 -0
- mirascope/api/_generated/traces/types/traces_search_request_sort_order.py +5 -0
- mirascope/api/_generated/traces/types/traces_search_response.py +26 -0
- mirascope/api/_generated/traces/types/traces_search_response_spans_item.py +50 -0
- mirascope/api/_generated/types/__init__.py +48 -0
- mirascope/api/_generated/types/already_exists_error.py +1 -3
- mirascope/api/_generated/types/bad_request_error_body.py +50 -0
- mirascope/api/_generated/types/click_house_error.py +22 -0
- mirascope/api/_generated/types/database_error.py +1 -3
- mirascope/api/_generated/types/date.py +3 -0
- mirascope/api/_generated/types/http_api_decode_error.py +1 -3
- mirascope/api/_generated/types/immutable_resource_error.py +22 -0
- mirascope/api/_generated/types/internal_server_error_body.py +49 -0
- mirascope/api/_generated/types/issue.py +1 -3
- mirascope/api/_generated/types/issue_tag.py +1 -8
- mirascope/api/_generated/types/not_found_error_body.py +1 -3
- mirascope/api/_generated/types/number_from_string.py +3 -0
- mirascope/api/_generated/types/permission_denied_error.py +1 -3
- mirascope/api/_generated/types/permission_denied_error_tag.py +1 -3
- mirascope/api/_generated/types/plan_limit_exceeded_error.py +32 -0
- mirascope/api/_generated/types/plan_limit_exceeded_error_tag.py +7 -0
- mirascope/api/_generated/types/pricing_unavailable_error.py +23 -0
- mirascope/api/_generated/types/property_key_key.py +1 -3
- mirascope/api/_generated/types/rate_limit_error.py +31 -0
- mirascope/api/_generated/types/rate_limit_error_tag.py +5 -0
- mirascope/api/_generated/types/service_unavailable_error_body.py +24 -0
- mirascope/api/_generated/types/service_unavailable_error_tag.py +7 -0
- mirascope/api/_generated/types/stripe_error.py +20 -0
- mirascope/api/_generated/types/subscription_past_due_error.py +31 -0
- mirascope/api/_generated/types/subscription_past_due_error_tag.py +7 -0
- mirascope/api/_generated/types/unauthorized_error_body.py +21 -0
- mirascope/api/_generated/types/unauthorized_error_tag.py +5 -0
- mirascope/api/settings.py +19 -1
- mirascope/llm/__init__.py +55 -8
- mirascope/llm/calls/__init__.py +2 -1
- mirascope/llm/calls/calls.py +3 -1
- mirascope/llm/calls/decorator.py +21 -7
- mirascope/llm/content/tool_call.py +6 -0
- mirascope/llm/content/tool_output.py +22 -5
- mirascope/llm/exceptions.py +284 -71
- mirascope/llm/formatting/__init__.py +19 -2
- mirascope/llm/formatting/format.py +219 -30
- mirascope/llm/formatting/output_parser.py +178 -0
- mirascope/llm/formatting/partial.py +80 -7
- mirascope/llm/formatting/primitives.py +192 -0
- mirascope/llm/formatting/types.py +21 -64
- mirascope/llm/mcp/__init__.py +2 -2
- mirascope/llm/mcp/mcp_client.py +130 -0
- mirascope/llm/messages/__init__.py +3 -0
- mirascope/llm/messages/_utils.py +34 -0
- mirascope/llm/models/__init__.py +5 -0
- mirascope/llm/models/models.py +137 -69
- mirascope/llm/{providers/base → models}/params.py +16 -37
- mirascope/llm/models/thinking_config.py +61 -0
- mirascope/llm/prompts/_utils.py +0 -32
- mirascope/llm/prompts/decorator.py +16 -5
- mirascope/llm/prompts/prompts.py +131 -68
- mirascope/llm/providers/__init__.py +18 -2
- mirascope/llm/providers/anthropic/__init__.py +3 -21
- mirascope/llm/providers/anthropic/_utils/__init__.py +2 -0
- mirascope/llm/providers/anthropic/_utils/beta_decode.py +22 -11
- mirascope/llm/providers/anthropic/_utils/beta_encode.py +75 -25
- mirascope/llm/providers/anthropic/_utils/decode.py +22 -11
- mirascope/llm/providers/anthropic/_utils/encode.py +82 -20
- mirascope/llm/providers/anthropic/_utils/errors.py +2 -2
- mirascope/llm/providers/anthropic/beta_provider.py +64 -18
- mirascope/llm/providers/anthropic/provider.py +91 -33
- mirascope/llm/providers/base/__init__.py +0 -2
- mirascope/llm/providers/base/_utils.py +55 -11
- mirascope/llm/providers/base/base_provider.py +116 -37
- mirascope/llm/providers/google/__init__.py +2 -17
- mirascope/llm/providers/google/_utils/__init__.py +2 -0
- mirascope/llm/providers/google/_utils/decode.py +37 -15
- mirascope/llm/providers/google/_utils/encode.py +127 -19
- mirascope/llm/providers/google/_utils/errors.py +3 -2
- mirascope/llm/providers/google/model_info.py +1 -0
- mirascope/llm/providers/google/provider.py +68 -19
- mirascope/llm/providers/mirascope/__init__.py +5 -0
- mirascope/llm/providers/mirascope/_utils.py +73 -0
- mirascope/llm/providers/mirascope/provider.py +349 -0
- mirascope/llm/providers/mlx/__init__.py +2 -17
- mirascope/llm/providers/mlx/_utils.py +8 -3
- mirascope/llm/providers/mlx/encoding/base.py +5 -2
- mirascope/llm/providers/mlx/encoding/transformers.py +5 -2
- mirascope/llm/providers/mlx/mlx.py +23 -6
- mirascope/llm/providers/mlx/provider.py +42 -13
- mirascope/llm/providers/ollama/__init__.py +1 -13
- mirascope/llm/providers/openai/_utils/errors.py +2 -2
- mirascope/llm/providers/openai/completions/__init__.py +2 -20
- mirascope/llm/providers/openai/completions/_utils/decode.py +14 -3
- mirascope/llm/providers/openai/completions/_utils/encode.py +35 -28
- mirascope/llm/providers/openai/completions/base_provider.py +40 -11
- mirascope/llm/providers/openai/provider.py +40 -10
- mirascope/llm/providers/openai/responses/__init__.py +1 -17
- mirascope/llm/providers/openai/responses/_utils/__init__.py +2 -0
- mirascope/llm/providers/openai/responses/_utils/decode.py +21 -8
- mirascope/llm/providers/openai/responses/_utils/encode.py +59 -19
- mirascope/llm/providers/openai/responses/provider.py +56 -18
- mirascope/llm/providers/provider_id.py +1 -0
- mirascope/llm/providers/provider_registry.py +96 -19
- mirascope/llm/providers/together/__init__.py +1 -13
- mirascope/llm/responses/__init__.py +6 -1
- mirascope/llm/responses/_utils.py +102 -12
- mirascope/llm/responses/base_response.py +5 -2
- mirascope/llm/responses/base_stream_response.py +139 -45
- mirascope/llm/responses/response.py +2 -1
- mirascope/llm/responses/root_response.py +89 -17
- mirascope/llm/responses/stream_response.py +6 -9
- mirascope/llm/tools/decorator.py +17 -8
- mirascope/llm/tools/tool_schema.py +43 -10
- mirascope/llm/tools/toolkit.py +35 -27
- mirascope/llm/tools/tools.py +123 -30
- mirascope/ops/__init__.py +64 -109
- mirascope/ops/_internal/configuration.py +82 -31
- mirascope/ops/_internal/exporters/exporters.py +64 -11
- mirascope/ops/_internal/instrumentation/llm/common.py +530 -0
- mirascope/ops/_internal/instrumentation/llm/cost.py +190 -0
- mirascope/ops/_internal/instrumentation/llm/encode.py +1 -1
- mirascope/ops/_internal/instrumentation/llm/llm.py +116 -1243
- mirascope/ops/_internal/instrumentation/llm/model.py +1798 -0
- mirascope/ops/_internal/instrumentation/llm/response.py +521 -0
- mirascope/ops/_internal/instrumentation/llm/serialize.py +300 -0
- mirascope/ops/_internal/protocols.py +83 -1
- mirascope/ops/_internal/traced_calls.py +4 -0
- mirascope/ops/_internal/traced_functions.py +141 -12
- mirascope/ops/_internal/tracing.py +78 -1
- mirascope/ops/_internal/utils.py +52 -4
- mirascope/ops/_internal/versioned_functions.py +54 -43
- {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/METADATA +14 -13
- mirascope-2.0.1.dist-info/RECORD +423 -0
- {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/licenses/LICENSE +1 -1
- mirascope/llm/formatting/_utils.py +0 -78
- mirascope/llm/mcp/client.py +0 -118
- mirascope/llm/providers/_missing_import_stubs.py +0 -49
- mirascope-2.0.0a5.dist-info/RECORD +0 -265
- {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
# isort: skip_file
|
|
4
|
+
|
|
5
|
+
from .tags_create_response import TagsCreateResponse
|
|
6
|
+
from .tags_get_response import TagsGetResponse
|
|
7
|
+
from .tags_list_response import TagsListResponse
|
|
8
|
+
from .tags_list_response_tags_item import TagsListResponseTagsItem
|
|
9
|
+
from .tags_update_response import TagsUpdateResponse
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"TagsCreateResponse",
|
|
13
|
+
"TagsGetResponse",
|
|
14
|
+
"TagsListResponse",
|
|
15
|
+
"TagsListResponseTagsItem",
|
|
16
|
+
"TagsUpdateResponse",
|
|
17
|
+
]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
import typing_extensions
|
|
7
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
8
|
+
from ...core.serialization import FieldMetadata
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TagsCreateResponse(UniversalBaseModel):
|
|
12
|
+
id: str
|
|
13
|
+
name: str = pydantic.Field()
|
|
14
|
+
"""
|
|
15
|
+
a string at most 100 character(s) long
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
project_id: typing_extensions.Annotated[str, FieldMetadata(alias="projectId")]
|
|
19
|
+
organization_id: typing_extensions.Annotated[
|
|
20
|
+
str, FieldMetadata(alias="organizationId")
|
|
21
|
+
]
|
|
22
|
+
created_by: typing_extensions.Annotated[
|
|
23
|
+
typing.Optional[str], FieldMetadata(alias="createdBy")
|
|
24
|
+
] = None
|
|
25
|
+
created_at: typing_extensions.Annotated[
|
|
26
|
+
typing.Optional[str], FieldMetadata(alias="createdAt")
|
|
27
|
+
] = None
|
|
28
|
+
updated_at: typing_extensions.Annotated[
|
|
29
|
+
typing.Optional[str], FieldMetadata(alias="updatedAt")
|
|
30
|
+
] = None
|
|
31
|
+
|
|
32
|
+
if IS_PYDANTIC_V2:
|
|
33
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
34
|
+
extra="allow", frozen=True
|
|
35
|
+
) # type: ignore # Pydantic v2
|
|
36
|
+
else:
|
|
37
|
+
|
|
38
|
+
class Config:
|
|
39
|
+
frozen = True
|
|
40
|
+
smart_union = True
|
|
41
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
import typing_extensions
|
|
7
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
8
|
+
from ...core.serialization import FieldMetadata
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TagsGetResponse(UniversalBaseModel):
|
|
12
|
+
id: str
|
|
13
|
+
name: str = pydantic.Field()
|
|
14
|
+
"""
|
|
15
|
+
a string at most 100 character(s) long
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
project_id: typing_extensions.Annotated[str, FieldMetadata(alias="projectId")]
|
|
19
|
+
organization_id: typing_extensions.Annotated[
|
|
20
|
+
str, FieldMetadata(alias="organizationId")
|
|
21
|
+
]
|
|
22
|
+
created_by: typing_extensions.Annotated[
|
|
23
|
+
typing.Optional[str], FieldMetadata(alias="createdBy")
|
|
24
|
+
] = None
|
|
25
|
+
created_at: typing_extensions.Annotated[
|
|
26
|
+
typing.Optional[str], FieldMetadata(alias="createdAt")
|
|
27
|
+
] = None
|
|
28
|
+
updated_at: typing_extensions.Annotated[
|
|
29
|
+
typing.Optional[str], FieldMetadata(alias="updatedAt")
|
|
30
|
+
] = None
|
|
31
|
+
|
|
32
|
+
if IS_PYDANTIC_V2:
|
|
33
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
34
|
+
extra="allow", frozen=True
|
|
35
|
+
) # type: ignore # Pydantic v2
|
|
36
|
+
else:
|
|
37
|
+
|
|
38
|
+
class Config:
|
|
39
|
+
frozen = True
|
|
40
|
+
smart_union = True
|
|
41
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
|
+
from .tags_list_response_tags_item import TagsListResponseTagsItem
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TagsListResponse(UniversalBaseModel):
|
|
11
|
+
tags: typing.List[TagsListResponseTagsItem]
|
|
12
|
+
total: float
|
|
13
|
+
|
|
14
|
+
if IS_PYDANTIC_V2:
|
|
15
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
16
|
+
extra="allow", frozen=True
|
|
17
|
+
) # type: ignore # Pydantic v2
|
|
18
|
+
else:
|
|
19
|
+
|
|
20
|
+
class Config:
|
|
21
|
+
frozen = True
|
|
22
|
+
smart_union = True
|
|
23
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
import typing_extensions
|
|
7
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
8
|
+
from ...core.serialization import FieldMetadata
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TagsListResponseTagsItem(UniversalBaseModel):
|
|
12
|
+
id: str
|
|
13
|
+
name: str = pydantic.Field()
|
|
14
|
+
"""
|
|
15
|
+
a string at most 100 character(s) long
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
project_id: typing_extensions.Annotated[str, FieldMetadata(alias="projectId")]
|
|
19
|
+
organization_id: typing_extensions.Annotated[
|
|
20
|
+
str, FieldMetadata(alias="organizationId")
|
|
21
|
+
]
|
|
22
|
+
created_by: typing_extensions.Annotated[
|
|
23
|
+
typing.Optional[str], FieldMetadata(alias="createdBy")
|
|
24
|
+
] = None
|
|
25
|
+
created_at: typing_extensions.Annotated[
|
|
26
|
+
typing.Optional[str], FieldMetadata(alias="createdAt")
|
|
27
|
+
] = None
|
|
28
|
+
updated_at: typing_extensions.Annotated[
|
|
29
|
+
typing.Optional[str], FieldMetadata(alias="updatedAt")
|
|
30
|
+
] = None
|
|
31
|
+
|
|
32
|
+
if IS_PYDANTIC_V2:
|
|
33
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
34
|
+
extra="allow", frozen=True
|
|
35
|
+
) # type: ignore # Pydantic v2
|
|
36
|
+
else:
|
|
37
|
+
|
|
38
|
+
class Config:
|
|
39
|
+
frozen = True
|
|
40
|
+
smart_union = True
|
|
41
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
import typing_extensions
|
|
7
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
8
|
+
from ...core.serialization import FieldMetadata
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TagsUpdateResponse(UniversalBaseModel):
|
|
12
|
+
id: str
|
|
13
|
+
name: str = pydantic.Field()
|
|
14
|
+
"""
|
|
15
|
+
a string at most 100 character(s) long
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
project_id: typing_extensions.Annotated[str, FieldMetadata(alias="projectId")]
|
|
19
|
+
organization_id: typing_extensions.Annotated[
|
|
20
|
+
str, FieldMetadata(alias="organizationId")
|
|
21
|
+
]
|
|
22
|
+
created_by: typing_extensions.Annotated[
|
|
23
|
+
typing.Optional[str], FieldMetadata(alias="createdBy")
|
|
24
|
+
] = None
|
|
25
|
+
created_at: typing_extensions.Annotated[
|
|
26
|
+
typing.Optional[str], FieldMetadata(alias="createdAt")
|
|
27
|
+
] = None
|
|
28
|
+
updated_at: typing_extensions.Annotated[
|
|
29
|
+
typing.Optional[str], FieldMetadata(alias="updatedAt")
|
|
30
|
+
] = None
|
|
31
|
+
|
|
32
|
+
if IS_PYDANTIC_V2:
|
|
33
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
34
|
+
extra="allow", frozen=True
|
|
35
|
+
) # type: ignore # Pydantic v2
|
|
36
|
+
else:
|
|
37
|
+
|
|
38
|
+
class Config:
|
|
39
|
+
frozen = True
|
|
40
|
+
smart_union = True
|
|
41
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
6
|
+
from ..core.request_options import RequestOptions
|
|
7
|
+
from .raw_client import AsyncRawTokenCostClient, RawTokenCostClient
|
|
8
|
+
from .types.token_cost_calculate_request_usage import TokenCostCalculateRequestUsage
|
|
9
|
+
from .types.token_cost_calculate_response import TokenCostCalculateResponse
|
|
10
|
+
|
|
11
|
+
# this is used as the default value for optional parameters
|
|
12
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TokenCostClient:
|
|
16
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
17
|
+
self._raw_client = RawTokenCostClient(client_wrapper=client_wrapper)
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def with_raw_response(self) -> RawTokenCostClient:
|
|
21
|
+
"""
|
|
22
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
23
|
+
|
|
24
|
+
Returns
|
|
25
|
+
-------
|
|
26
|
+
RawTokenCostClient
|
|
27
|
+
"""
|
|
28
|
+
return self._raw_client
|
|
29
|
+
|
|
30
|
+
def calculate(
|
|
31
|
+
self,
|
|
32
|
+
*,
|
|
33
|
+
provider: str,
|
|
34
|
+
model: str,
|
|
35
|
+
usage: TokenCostCalculateRequestUsage,
|
|
36
|
+
via_router: typing.Optional[bool] = OMIT,
|
|
37
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
38
|
+
) -> TokenCostCalculateResponse:
|
|
39
|
+
"""
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
provider : str
|
|
43
|
+
a non empty string
|
|
44
|
+
|
|
45
|
+
model : str
|
|
46
|
+
a non empty string
|
|
47
|
+
|
|
48
|
+
usage : TokenCostCalculateRequestUsage
|
|
49
|
+
|
|
50
|
+
via_router : typing.Optional[bool]
|
|
51
|
+
|
|
52
|
+
request_options : typing.Optional[RequestOptions]
|
|
53
|
+
Request-specific configuration.
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
TokenCostCalculateResponse
|
|
58
|
+
Success
|
|
59
|
+
|
|
60
|
+
Examples
|
|
61
|
+
--------
|
|
62
|
+
from mirascope.api._generated import Mirascope
|
|
63
|
+
from mirascope.api._generated.token_cost import TokenCostCalculateRequestUsage
|
|
64
|
+
|
|
65
|
+
client = Mirascope()
|
|
66
|
+
client.token_cost.calculate(
|
|
67
|
+
provider="provider",
|
|
68
|
+
model="model",
|
|
69
|
+
usage=TokenCostCalculateRequestUsage(
|
|
70
|
+
input_tokens=1.1,
|
|
71
|
+
output_tokens=1.1,
|
|
72
|
+
),
|
|
73
|
+
)
|
|
74
|
+
"""
|
|
75
|
+
_response = self._raw_client.calculate(
|
|
76
|
+
provider=provider,
|
|
77
|
+
model=model,
|
|
78
|
+
usage=usage,
|
|
79
|
+
via_router=via_router,
|
|
80
|
+
request_options=request_options,
|
|
81
|
+
)
|
|
82
|
+
return _response.data
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class AsyncTokenCostClient:
|
|
86
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
87
|
+
self._raw_client = AsyncRawTokenCostClient(client_wrapper=client_wrapper)
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def with_raw_response(self) -> AsyncRawTokenCostClient:
|
|
91
|
+
"""
|
|
92
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
93
|
+
|
|
94
|
+
Returns
|
|
95
|
+
-------
|
|
96
|
+
AsyncRawTokenCostClient
|
|
97
|
+
"""
|
|
98
|
+
return self._raw_client
|
|
99
|
+
|
|
100
|
+
async def calculate(
|
|
101
|
+
self,
|
|
102
|
+
*,
|
|
103
|
+
provider: str,
|
|
104
|
+
model: str,
|
|
105
|
+
usage: TokenCostCalculateRequestUsage,
|
|
106
|
+
via_router: typing.Optional[bool] = OMIT,
|
|
107
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
108
|
+
) -> TokenCostCalculateResponse:
|
|
109
|
+
"""
|
|
110
|
+
Parameters
|
|
111
|
+
----------
|
|
112
|
+
provider : str
|
|
113
|
+
a non empty string
|
|
114
|
+
|
|
115
|
+
model : str
|
|
116
|
+
a non empty string
|
|
117
|
+
|
|
118
|
+
usage : TokenCostCalculateRequestUsage
|
|
119
|
+
|
|
120
|
+
via_router : typing.Optional[bool]
|
|
121
|
+
|
|
122
|
+
request_options : typing.Optional[RequestOptions]
|
|
123
|
+
Request-specific configuration.
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
TokenCostCalculateResponse
|
|
128
|
+
Success
|
|
129
|
+
|
|
130
|
+
Examples
|
|
131
|
+
--------
|
|
132
|
+
import asyncio
|
|
133
|
+
|
|
134
|
+
from mirascope.api._generated import AsyncMirascope
|
|
135
|
+
from mirascope.api._generated.token_cost import TokenCostCalculateRequestUsage
|
|
136
|
+
|
|
137
|
+
client = AsyncMirascope()
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
async def main() -> None:
|
|
141
|
+
await client.token_cost.calculate(
|
|
142
|
+
provider="provider",
|
|
143
|
+
model="model",
|
|
144
|
+
usage=TokenCostCalculateRequestUsage(
|
|
145
|
+
input_tokens=1.1,
|
|
146
|
+
output_tokens=1.1,
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
asyncio.run(main())
|
|
152
|
+
"""
|
|
153
|
+
_response = await self._raw_client.calculate(
|
|
154
|
+
provider=provider,
|
|
155
|
+
model=model,
|
|
156
|
+
usage=usage,
|
|
157
|
+
via_router=via_router,
|
|
158
|
+
request_options=request_options,
|
|
159
|
+
)
|
|
160
|
+
return _response.data
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from json.decoder import JSONDecodeError
|
|
5
|
+
|
|
6
|
+
from ..core.api_error import ApiError
|
|
7
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
8
|
+
from ..core.http_response import AsyncHttpResponse, HttpResponse
|
|
9
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
10
|
+
from ..core.request_options import RequestOptions
|
|
11
|
+
from ..core.serialization import convert_and_respect_annotation_metadata
|
|
12
|
+
from ..errors.bad_request_error import BadRequestError
|
|
13
|
+
from ..errors.service_unavailable_error import ServiceUnavailableError
|
|
14
|
+
from ..errors.too_many_requests_error import TooManyRequestsError
|
|
15
|
+
from ..errors.unauthorized_error import UnauthorizedError
|
|
16
|
+
from ..types.rate_limit_error import RateLimitError
|
|
17
|
+
from ..types.unauthorized_error_body import UnauthorizedErrorBody
|
|
18
|
+
from .types.token_cost_calculate_request_usage import TokenCostCalculateRequestUsage
|
|
19
|
+
from .types.token_cost_calculate_response import TokenCostCalculateResponse
|
|
20
|
+
|
|
21
|
+
# this is used as the default value for optional parameters
|
|
22
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class RawTokenCostClient:
|
|
26
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
27
|
+
self._client_wrapper = client_wrapper
|
|
28
|
+
|
|
29
|
+
def calculate(
|
|
30
|
+
self,
|
|
31
|
+
*,
|
|
32
|
+
provider: str,
|
|
33
|
+
model: str,
|
|
34
|
+
usage: TokenCostCalculateRequestUsage,
|
|
35
|
+
via_router: typing.Optional[bool] = OMIT,
|
|
36
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
37
|
+
) -> HttpResponse[TokenCostCalculateResponse]:
|
|
38
|
+
"""
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
provider : str
|
|
42
|
+
a non empty string
|
|
43
|
+
|
|
44
|
+
model : str
|
|
45
|
+
a non empty string
|
|
46
|
+
|
|
47
|
+
usage : TokenCostCalculateRequestUsage
|
|
48
|
+
|
|
49
|
+
via_router : typing.Optional[bool]
|
|
50
|
+
|
|
51
|
+
request_options : typing.Optional[RequestOptions]
|
|
52
|
+
Request-specific configuration.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
HttpResponse[TokenCostCalculateResponse]
|
|
57
|
+
Success
|
|
58
|
+
"""
|
|
59
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
60
|
+
"token-cost",
|
|
61
|
+
method="POST",
|
|
62
|
+
json={
|
|
63
|
+
"provider": provider,
|
|
64
|
+
"model": model,
|
|
65
|
+
"usage": convert_and_respect_annotation_metadata(
|
|
66
|
+
object_=usage,
|
|
67
|
+
annotation=TokenCostCalculateRequestUsage,
|
|
68
|
+
direction="write",
|
|
69
|
+
),
|
|
70
|
+
"viaRouter": via_router,
|
|
71
|
+
},
|
|
72
|
+
headers={
|
|
73
|
+
"content-type": "application/json",
|
|
74
|
+
},
|
|
75
|
+
request_options=request_options,
|
|
76
|
+
omit=OMIT,
|
|
77
|
+
)
|
|
78
|
+
try:
|
|
79
|
+
if 200 <= _response.status_code < 300:
|
|
80
|
+
_data = typing.cast(
|
|
81
|
+
TokenCostCalculateResponse,
|
|
82
|
+
parse_obj_as(
|
|
83
|
+
type_=TokenCostCalculateResponse, # type: ignore
|
|
84
|
+
object_=_response.json(),
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
return HttpResponse(response=_response, data=_data)
|
|
88
|
+
if _response.status_code == 400:
|
|
89
|
+
raise BadRequestError(
|
|
90
|
+
headers=dict(_response.headers),
|
|
91
|
+
body=typing.cast(
|
|
92
|
+
typing.Optional[typing.Any],
|
|
93
|
+
parse_obj_as(
|
|
94
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
95
|
+
object_=_response.json(),
|
|
96
|
+
),
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
if _response.status_code == 401:
|
|
100
|
+
raise UnauthorizedError(
|
|
101
|
+
headers=dict(_response.headers),
|
|
102
|
+
body=typing.cast(
|
|
103
|
+
UnauthorizedErrorBody,
|
|
104
|
+
parse_obj_as(
|
|
105
|
+
type_=UnauthorizedErrorBody, # type: ignore
|
|
106
|
+
object_=_response.json(),
|
|
107
|
+
),
|
|
108
|
+
),
|
|
109
|
+
)
|
|
110
|
+
if _response.status_code == 429:
|
|
111
|
+
raise TooManyRequestsError(
|
|
112
|
+
headers=dict(_response.headers),
|
|
113
|
+
body=typing.cast(
|
|
114
|
+
RateLimitError,
|
|
115
|
+
parse_obj_as(
|
|
116
|
+
type_=RateLimitError, # type: ignore
|
|
117
|
+
object_=_response.json(),
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
if _response.status_code == 503:
|
|
122
|
+
raise ServiceUnavailableError(
|
|
123
|
+
headers=dict(_response.headers),
|
|
124
|
+
body=typing.cast(
|
|
125
|
+
typing.Optional[typing.Any],
|
|
126
|
+
parse_obj_as(
|
|
127
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
128
|
+
object_=_response.json(),
|
|
129
|
+
),
|
|
130
|
+
),
|
|
131
|
+
)
|
|
132
|
+
_response_json = _response.json()
|
|
133
|
+
except JSONDecodeError:
|
|
134
|
+
raise ApiError(
|
|
135
|
+
status_code=_response.status_code,
|
|
136
|
+
headers=dict(_response.headers),
|
|
137
|
+
body=_response.text,
|
|
138
|
+
)
|
|
139
|
+
raise ApiError(
|
|
140
|
+
status_code=_response.status_code,
|
|
141
|
+
headers=dict(_response.headers),
|
|
142
|
+
body=_response_json,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class AsyncRawTokenCostClient:
|
|
147
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
148
|
+
self._client_wrapper = client_wrapper
|
|
149
|
+
|
|
150
|
+
async def calculate(
|
|
151
|
+
self,
|
|
152
|
+
*,
|
|
153
|
+
provider: str,
|
|
154
|
+
model: str,
|
|
155
|
+
usage: TokenCostCalculateRequestUsage,
|
|
156
|
+
via_router: typing.Optional[bool] = OMIT,
|
|
157
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
158
|
+
) -> AsyncHttpResponse[TokenCostCalculateResponse]:
|
|
159
|
+
"""
|
|
160
|
+
Parameters
|
|
161
|
+
----------
|
|
162
|
+
provider : str
|
|
163
|
+
a non empty string
|
|
164
|
+
|
|
165
|
+
model : str
|
|
166
|
+
a non empty string
|
|
167
|
+
|
|
168
|
+
usage : TokenCostCalculateRequestUsage
|
|
169
|
+
|
|
170
|
+
via_router : typing.Optional[bool]
|
|
171
|
+
|
|
172
|
+
request_options : typing.Optional[RequestOptions]
|
|
173
|
+
Request-specific configuration.
|
|
174
|
+
|
|
175
|
+
Returns
|
|
176
|
+
-------
|
|
177
|
+
AsyncHttpResponse[TokenCostCalculateResponse]
|
|
178
|
+
Success
|
|
179
|
+
"""
|
|
180
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
181
|
+
"token-cost",
|
|
182
|
+
method="POST",
|
|
183
|
+
json={
|
|
184
|
+
"provider": provider,
|
|
185
|
+
"model": model,
|
|
186
|
+
"usage": convert_and_respect_annotation_metadata(
|
|
187
|
+
object_=usage,
|
|
188
|
+
annotation=TokenCostCalculateRequestUsage,
|
|
189
|
+
direction="write",
|
|
190
|
+
),
|
|
191
|
+
"viaRouter": via_router,
|
|
192
|
+
},
|
|
193
|
+
headers={
|
|
194
|
+
"content-type": "application/json",
|
|
195
|
+
},
|
|
196
|
+
request_options=request_options,
|
|
197
|
+
omit=OMIT,
|
|
198
|
+
)
|
|
199
|
+
try:
|
|
200
|
+
if 200 <= _response.status_code < 300:
|
|
201
|
+
_data = typing.cast(
|
|
202
|
+
TokenCostCalculateResponse,
|
|
203
|
+
parse_obj_as(
|
|
204
|
+
type_=TokenCostCalculateResponse, # type: ignore
|
|
205
|
+
object_=_response.json(),
|
|
206
|
+
),
|
|
207
|
+
)
|
|
208
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
209
|
+
if _response.status_code == 400:
|
|
210
|
+
raise BadRequestError(
|
|
211
|
+
headers=dict(_response.headers),
|
|
212
|
+
body=typing.cast(
|
|
213
|
+
typing.Optional[typing.Any],
|
|
214
|
+
parse_obj_as(
|
|
215
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
216
|
+
object_=_response.json(),
|
|
217
|
+
),
|
|
218
|
+
),
|
|
219
|
+
)
|
|
220
|
+
if _response.status_code == 401:
|
|
221
|
+
raise UnauthorizedError(
|
|
222
|
+
headers=dict(_response.headers),
|
|
223
|
+
body=typing.cast(
|
|
224
|
+
UnauthorizedErrorBody,
|
|
225
|
+
parse_obj_as(
|
|
226
|
+
type_=UnauthorizedErrorBody, # type: ignore
|
|
227
|
+
object_=_response.json(),
|
|
228
|
+
),
|
|
229
|
+
),
|
|
230
|
+
)
|
|
231
|
+
if _response.status_code == 429:
|
|
232
|
+
raise TooManyRequestsError(
|
|
233
|
+
headers=dict(_response.headers),
|
|
234
|
+
body=typing.cast(
|
|
235
|
+
RateLimitError,
|
|
236
|
+
parse_obj_as(
|
|
237
|
+
type_=RateLimitError, # type: ignore
|
|
238
|
+
object_=_response.json(),
|
|
239
|
+
),
|
|
240
|
+
),
|
|
241
|
+
)
|
|
242
|
+
if _response.status_code == 503:
|
|
243
|
+
raise ServiceUnavailableError(
|
|
244
|
+
headers=dict(_response.headers),
|
|
245
|
+
body=typing.cast(
|
|
246
|
+
typing.Optional[typing.Any],
|
|
247
|
+
parse_obj_as(
|
|
248
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
249
|
+
object_=_response.json(),
|
|
250
|
+
),
|
|
251
|
+
),
|
|
252
|
+
)
|
|
253
|
+
_response_json = _response.json()
|
|
254
|
+
except JSONDecodeError:
|
|
255
|
+
raise ApiError(
|
|
256
|
+
status_code=_response.status_code,
|
|
257
|
+
headers=dict(_response.headers),
|
|
258
|
+
body=_response.text,
|
|
259
|
+
)
|
|
260
|
+
raise ApiError(
|
|
261
|
+
status_code=_response.status_code,
|
|
262
|
+
headers=dict(_response.headers),
|
|
263
|
+
body=_response_json,
|
|
264
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
# isort: skip_file
|
|
4
|
+
|
|
5
|
+
from .token_cost_calculate_request_usage import TokenCostCalculateRequestUsage
|
|
6
|
+
from .token_cost_calculate_response import TokenCostCalculateResponse
|
|
7
|
+
|
|
8
|
+
__all__ = ["TokenCostCalculateRequestUsage", "TokenCostCalculateResponse"]
|