blaxel 0.2.31rc120__py3-none-any.whl → 0.2.32__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.
- blaxel/__init__.py +3 -3
- blaxel/core/agents/__init__.py +16 -7
- blaxel/core/authentication/__init__.py +2 -1
- blaxel/core/authentication/devicemode.py +9 -1
- blaxel/core/authentication/oauth.py +13 -6
- blaxel/core/authentication/types.py +1 -0
- blaxel/core/cache/cache.py +10 -3
- blaxel/core/client/api/agents/create_agent.py +5 -5
- blaxel/core/client/api/agents/delete_agent.py +5 -5
- blaxel/core/client/api/agents/get_agent.py +4 -4
- blaxel/core/client/api/agents/list_agent_revisions.py +8 -6
- blaxel/core/client/api/agents/list_agents.py +5 -5
- blaxel/core/client/api/agents/update_agent.py +5 -5
- blaxel/core/client/api/compute/create_sandbox.py +5 -5
- blaxel/core/client/api/compute/create_sandbox_preview.py +5 -5
- blaxel/core/client/api/compute/create_sandbox_preview_token.py +5 -5
- blaxel/core/client/api/compute/delete_sandbox.py +5 -5
- blaxel/core/client/api/compute/delete_sandbox_preview.py +5 -5
- blaxel/core/client/api/compute/delete_sandbox_preview_token.py +11 -7
- blaxel/core/client/api/compute/get_sandbox.py +4 -4
- blaxel/core/client/api/compute/get_sandbox_preview.py +5 -5
- blaxel/core/client/api/compute/list_sandbox_preview_tokens.py +5 -5
- blaxel/core/client/api/compute/list_sandbox_previews.py +5 -5
- blaxel/core/client/api/compute/list_sandboxes.py +5 -5
- blaxel/core/client/api/compute/update_sandbox.py +5 -5
- blaxel/core/client/api/compute/update_sandbox_preview.py +5 -5
- blaxel/core/client/api/configurations/get_configuration.py +5 -5
- blaxel/core/client/api/customdomains/create_custom_domain.py +5 -5
- blaxel/core/client/api/customdomains/delete_custom_domain.py +5 -5
- blaxel/core/client/api/customdomains/get_custom_domain.py +5 -5
- blaxel/core/client/api/customdomains/list_custom_domains.py +5 -5
- blaxel/core/client/api/customdomains/update_custom_domain.py +5 -5
- blaxel/core/client/api/customdomains/verify_custom_domain.py +5 -5
- blaxel/core/client/api/default/get_template.py +5 -5
- blaxel/core/client/api/default/list_mcp_hub_definitions.py +5 -5
- blaxel/core/client/api/default/list_sandbox_hub_definitions.py +11 -7
- blaxel/core/client/api/functions/create_function.py +5 -5
- blaxel/core/client/api/functions/delete_function.py +5 -5
- blaxel/core/client/api/functions/get_function.py +4 -4
- blaxel/core/client/api/functions/list_function_revisions.py +8 -6
- blaxel/core/client/api/functions/list_functions.py +5 -5
- blaxel/core/client/api/functions/update_function.py +5 -5
- blaxel/core/client/api/images/cleanup_images.py +8 -6
- blaxel/core/client/api/images/delete_image.py +4 -4
- blaxel/core/client/api/images/delete_image_tag.py +4 -4
- blaxel/core/client/api/images/get_image.py +5 -5
- blaxel/core/client/api/images/list_images.py +5 -5
- blaxel/core/client/api/integrations/create_integration_connection.py +5 -5
- blaxel/core/client/api/integrations/delete_integration_connection.py +5 -5
- blaxel/core/client/api/integrations/get_integration.py +5 -5
- blaxel/core/client/api/integrations/get_integration_connection.py +5 -5
- blaxel/core/client/api/integrations/get_integration_connection_model.py +3 -3
- blaxel/core/client/api/integrations/get_integration_connection_model_endpoint_configurations.py +3 -3
- blaxel/core/client/api/integrations/list_integration_connection_models.py +3 -3
- blaxel/core/client/api/integrations/list_integration_connections.py +11 -7
- blaxel/core/client/api/integrations/update_integration_connection.py +5 -5
- blaxel/core/client/api/invitations/list_all_pending_invitations.py +7 -5
- blaxel/core/client/api/jobs/create_job.py +5 -5
- blaxel/core/client/api/jobs/create_job_execution.py +7 -5
- blaxel/core/client/api/jobs/delete_job.py +5 -5
- blaxel/core/client/api/jobs/delete_job_execution.py +7 -5
- blaxel/core/client/api/jobs/get_job.py +4 -4
- blaxel/core/client/api/jobs/get_job_execution.py +7 -5
- blaxel/core/client/api/jobs/list_job_executions.py +10 -6
- blaxel/core/client/api/jobs/list_job_revisions.py +8 -6
- blaxel/core/client/api/jobs/list_jobs.py +5 -5
- blaxel/core/client/api/jobs/update_job.py +5 -5
- blaxel/core/client/api/locations/list_locations.py +8 -6
- blaxel/core/client/api/models/create_model.py +5 -5
- blaxel/core/client/api/models/delete_model.py +5 -5
- blaxel/core/client/api/models/get_model.py +5 -5
- blaxel/core/client/api/models/list_model_revisions.py +8 -6
- blaxel/core/client/api/models/list_models.py +5 -5
- blaxel/core/client/api/models/update_model.py +5 -5
- blaxel/core/client/api/policies/create_policy.py +5 -5
- blaxel/core/client/api/policies/delete_policy.py +5 -5
- blaxel/core/client/api/policies/get_policy.py +5 -5
- blaxel/core/client/api/policies/list_policies.py +5 -5
- blaxel/core/client/api/policies/update_policy.py +5 -5
- blaxel/core/client/api/public_ipslist/list_public_ips.py +5 -5
- blaxel/core/client/api/service_accounts/create_api_key_for_service_account.py +5 -5
- blaxel/core/client/api/service_accounts/create_workspace_service_account.py +11 -7
- blaxel/core/client/api/service_accounts/delete_api_key_for_service_account.py +3 -3
- blaxel/core/client/api/service_accounts/delete_workspace_service_account.py +11 -7
- blaxel/core/client/api/service_accounts/get_workspace_service_accounts.py +8 -6
- blaxel/core/client/api/service_accounts/list_api_keys_for_service_account.py +5 -5
- blaxel/core/client/api/service_accounts/update_workspace_service_account.py +11 -7
- blaxel/core/client/api/templates/list_templates.py +5 -5
- blaxel/core/client/api/volume_templates/create_volume_template.py +4 -4
- blaxel/core/client/api/volume_templates/delete_volume_template.py +5 -5
- blaxel/core/client/api/volume_templates/delete_volume_template_version.py +4 -4
- blaxel/core/client/api/volume_templates/get_volume_template.py +5 -5
- blaxel/core/client/api/volume_templates/list_volume_templates.py +8 -6
- blaxel/core/client/api/volume_templates/update_volume_template.py +4 -4
- blaxel/core/client/api/volumes/create_volume.py +5 -5
- blaxel/core/client/api/volumes/delete_volume.py +5 -5
- blaxel/core/client/api/volumes/get_volume.py +5 -5
- blaxel/core/client/api/volumes/list_volumes.py +5 -5
- blaxel/core/client/api/workspaces/accept_workspace_invitation.py +10 -6
- blaxel/core/client/api/workspaces/check_workspace_availability.py +5 -5
- blaxel/core/client/api/workspaces/create_workspace.py +5 -5
- blaxel/core/client/api/workspaces/decline_workspace_invitation.py +5 -5
- blaxel/core/client/api/workspaces/delete_workspace.py +5 -5
- blaxel/core/client/api/workspaces/get_workspace.py +5 -5
- blaxel/core/client/api/workspaces/invite_workspace_user.py +10 -6
- blaxel/core/client/api/workspaces/leave_workspace.py +4 -4
- blaxel/core/client/api/workspaces/list_workspace_users.py +5 -5
- blaxel/core/client/api/workspaces/list_workspaces.py +5 -5
- blaxel/core/client/api/workspaces/remove_workspace_user.py +3 -3
- blaxel/core/client/api/workspaces/update_workspace.py +5 -5
- blaxel/core/client/api/workspaces/update_workspace_user_role.py +10 -6
- blaxel/core/client/client.py +5 -19
- blaxel/core/client/models/acl.py +3 -3
- blaxel/core/client/models/agent.py +12 -5
- blaxel/core/client/models/agent_spec.py +22 -7
- blaxel/core/client/models/api_key.py +6 -6
- blaxel/core/client/models/billable_time_metric.py +3 -4
- blaxel/core/client/models/check_workspace_availability_body.py +1 -1
- blaxel/core/client/models/cleanup_images_response_200.py +1 -1
- blaxel/core/client/models/configuration.py +2 -3
- blaxel/core/client/models/continent.py +2 -2
- blaxel/core/client/models/core_event.py +3 -3
- blaxel/core/client/models/core_spec.py +14 -5
- blaxel/core/client/models/core_spec_configurations.py +1 -2
- blaxel/core/client/models/country.py +2 -2
- blaxel/core/client/models/create_api_key_for_service_account_body.py +1 -1
- blaxel/core/client/models/create_job_execution_request.py +4 -5
- blaxel/core/client/models/create_job_execution_request_tasks_item.py +1 -1
- blaxel/core/client/models/create_job_execution_response.py +4 -5
- blaxel/core/client/models/create_job_execution_response_tasks_item.py +1 -1
- blaxel/core/client/models/create_workspace_service_account_body.py +1 -1
- blaxel/core/client/models/create_workspace_service_account_response_200.py +1 -1
- blaxel/core/client/models/custom_domain.py +6 -3
- blaxel/core/client/models/custom_domain_metadata.py +6 -7
- blaxel/core/client/models/custom_domain_spec.py +10 -7
- blaxel/core/client/models/custom_domain_spec_txt_records.py +1 -1
- blaxel/core/client/models/delete_sandbox_preview_token_response_200.py +1 -1
- blaxel/core/client/models/delete_volume_template_version_response_200.py +6 -3
- blaxel/core/client/models/delete_workspace_service_account_response_200.py +1 -1
- blaxel/core/client/models/entrypoint.py +4 -3
- blaxel/core/client/models/entrypoint_env.py +1 -1
- blaxel/core/client/models/expiration_policy.py +2 -2
- blaxel/core/client/models/flavor.py +2 -2
- blaxel/core/client/models/form.py +6 -3
- blaxel/core/client/models/form_config.py +1 -1
- blaxel/core/client/models/form_oauth.py +1 -1
- blaxel/core/client/models/form_secrets.py +1 -1
- blaxel/core/client/models/function.py +12 -5
- blaxel/core/client/models/function_spec.py +17 -6
- blaxel/core/client/models/get_workspace_service_accounts_response_200_item.py +1 -1
- blaxel/core/client/models/histogram_bucket.py +1 -1
- blaxel/core/client/models/histogram_stats.py +1 -1
- blaxel/core/client/models/image.py +6 -3
- blaxel/core/client/models/image_metadata.py +6 -6
- blaxel/core/client/models/image_spec.py +1 -2
- blaxel/core/client/models/image_tag.py +3 -3
- blaxel/core/client/models/integration.py +12 -5
- blaxel/core/client/models/integration_additional_infos.py +1 -1
- blaxel/core/client/models/integration_connection.py +6 -3
- blaxel/core/client/models/integration_connection_spec.py +1 -2
- blaxel/core/client/models/integration_connection_spec_config.py +1 -1
- blaxel/core/client/models/integration_connection_spec_secret.py +1 -1
- blaxel/core/client/models/integration_endpoint.py +9 -6
- blaxel/core/client/models/integration_endpoint_token.py +1 -1
- blaxel/core/client/models/integration_endpoints.py +1 -3
- blaxel/core/client/models/integration_headers.py +1 -1
- blaxel/core/client/models/integration_model.py +1 -1
- blaxel/core/client/models/integration_organization.py +2 -2
- blaxel/core/client/models/integration_query_params.py +1 -1
- blaxel/core/client/models/integration_repository.py +2 -2
- blaxel/core/client/models/invite_workspace_user_body.py +1 -1
- blaxel/core/client/models/job.py +12 -5
- blaxel/core/client/models/job_execution.py +6 -3
- blaxel/core/client/models/job_execution_config.py +3 -3
- blaxel/core/client/models/job_execution_metadata.py +7 -7
- blaxel/core/client/models/job_execution_spec.py +1 -2
- blaxel/core/client/models/job_execution_stats.py +1 -1
- blaxel/core/client/models/job_execution_task.py +6 -3
- blaxel/core/client/models/job_execution_task_condition.py +3 -3
- blaxel/core/client/models/job_execution_task_metadata.py +6 -6
- blaxel/core/client/models/job_execution_task_spec.py +2 -2
- blaxel/core/client/models/job_metrics.py +15 -12
- blaxel/core/client/models/job_metrics_executions_total.py +1 -1
- blaxel/core/client/models/job_metrics_tasks_total.py +1 -1
- blaxel/core/client/models/job_spec.py +17 -6
- blaxel/core/client/models/jobs_chart_value.py +1 -1
- blaxel/core/client/models/jobs_network_chart.py +1 -2
- blaxel/core/client/models/jobs_success_failed_chart.py +11 -4
- blaxel/core/client/models/jobs_total.py +1 -1
- blaxel/core/client/models/last_n_requests_metric.py +4 -4
- blaxel/core/client/models/latency_metric.py +10 -7
- blaxel/core/client/models/location_response.py +1 -2
- blaxel/core/client/models/logs_response.py +1 -1
- blaxel/core/client/models/logs_response_data.py +4 -4
- blaxel/core/client/models/mcp_definition.py +11 -8
- blaxel/core/client/models/mcp_definition_entrypoint.py +1 -1
- blaxel/core/client/models/mcp_definition_form.py +1 -1
- blaxel/core/client/models/memory_allocation_by_name.py +1 -1
- blaxel/core/client/models/memory_allocation_metric.py +2 -2
- blaxel/core/client/models/metadata.py +6 -7
- blaxel/core/client/models/metadata_labels.py +1 -1
- blaxel/core/client/models/metric.py +2 -2
- blaxel/core/client/models/metrics.py +24 -11
- blaxel/core/client/models/metrics_models.py +1 -1
- blaxel/core/client/models/metrics_request_total_per_code.py +1 -1
- blaxel/core/client/models/metrics_rps_per_code.py +1 -1
- blaxel/core/client/models/model.py +12 -5
- blaxel/core/client/models/model_spec.py +14 -5
- blaxel/core/client/models/o_auth.py +2 -2
- blaxel/core/client/models/owner_fields.py +3 -3
- blaxel/core/client/models/pending_invitation.py +6 -6
- blaxel/core/client/models/pending_invitation_accept.py +6 -3
- blaxel/core/client/models/pending_invitation_render.py +14 -7
- blaxel/core/client/models/pending_invitation_render_invited_by.py +1 -1
- blaxel/core/client/models/pending_invitation_render_workspace.py +2 -2
- blaxel/core/client/models/pending_invitation_workspace_details.py +1 -1
- blaxel/core/client/models/pod_template_spec.py +1 -1
- blaxel/core/client/models/policy.py +6 -3
- blaxel/core/client/models/policy_location.py +2 -2
- blaxel/core/client/models/policy_max_tokens.py +5 -3
- blaxel/core/client/models/policy_spec.py +15 -8
- blaxel/core/client/models/port.py +1 -1
- blaxel/core/client/models/preview.py +6 -3
- blaxel/core/client/models/preview_metadata.py +8 -8
- blaxel/core/client/models/preview_spec.py +5 -6
- blaxel/core/client/models/preview_spec_request_headers.py +1 -1
- blaxel/core/client/models/preview_spec_response_headers.py +1 -1
- blaxel/core/client/models/preview_token.py +6 -3
- blaxel/core/client/models/preview_token_metadata.py +4 -4
- blaxel/core/client/models/preview_token_spec.py +2 -2
- blaxel/core/client/models/private_location.py +1 -1
- blaxel/core/client/models/public_ip.py +3 -3
- blaxel/core/client/models/public_ips.py +1 -2
- blaxel/core/client/models/region.py +2 -2
- blaxel/core/client/models/repository.py +2 -2
- blaxel/core/client/models/request_duration_over_time_metric.py +1 -1
- blaxel/core/client/models/request_duration_over_time_metrics.py +4 -3
- blaxel/core/client/models/request_total_by_origin_metric.py +23 -10
- blaxel/core/client/models/request_total_by_origin_metric_request_total_by_origin.py +1 -1
- blaxel/core/client/models/request_total_by_origin_metric_request_total_by_origin_and_code.py +1 -1
- blaxel/core/client/models/request_total_metric.py +14 -7
- blaxel/core/client/models/request_total_metric_request_total_per_code.py +1 -1
- blaxel/core/client/models/request_total_metric_rps_per_code.py +1 -1
- blaxel/core/client/models/request_total_response_data.py +5 -5
- blaxel/core/client/models/resource.py +6 -4
- blaxel/core/client/models/resource_log.py +1 -1
- blaxel/core/client/models/resource_log_chart.py +1 -1
- blaxel/core/client/models/resource_log_response.py +2 -2
- blaxel/core/client/models/resource_metrics.py +95 -40
- blaxel/core/client/models/resource_metrics_request_total_per_code.py +1 -1
- blaxel/core/client/models/resource_metrics_request_total_per_code_previous.py +1 -1
- blaxel/core/client/models/resource_metrics_rps_per_code.py +1 -1
- blaxel/core/client/models/resource_metrics_rps_per_code_previous.py +1 -1
- blaxel/core/client/models/resource_trace.py +5 -5
- blaxel/core/client/models/revision_configuration.py +3 -3
- blaxel/core/client/models/revision_metadata.py +5 -5
- blaxel/core/client/models/runtime.py +9 -10
- blaxel/core/client/models/runtime_configuration.py +1 -1
- blaxel/core/client/models/runtime_startup_probe.py +1 -1
- blaxel/core/client/models/sandbox.py +13 -6
- blaxel/core/client/models/sandbox_definition.py +3 -4
- blaxel/core/client/models/sandbox_lifecycle.py +2 -3
- blaxel/core/client/models/sandbox_metrics.py +1 -1
- blaxel/core/client/models/sandbox_spec.py +25 -8
- blaxel/core/client/models/serverless_config.py +4 -5
- blaxel/core/client/models/serverless_config_configuration.py +1 -1
- blaxel/core/client/models/spec_configuration.py +1 -1
- blaxel/core/client/models/start_sandbox.py +6 -3
- blaxel/core/client/models/stop_sandbox.py +6 -3
- blaxel/core/client/models/store_agent.py +6 -7
- blaxel/core/client/models/store_agent_labels.py +1 -1
- blaxel/core/client/models/store_configuration.py +7 -6
- blaxel/core/client/models/store_configuration_option.py +2 -2
- blaxel/core/client/models/template.py +6 -7
- blaxel/core/client/models/template_variable.py +1 -1
- blaxel/core/client/models/time_fields.py +3 -3
- blaxel/core/client/models/time_to_first_token_over_time_metrics.py +7 -4
- blaxel/core/client/models/token_rate_metric.py +3 -3
- blaxel/core/client/models/token_rate_metrics.py +4 -5
- blaxel/core/client/models/token_total_metric.py +13 -7
- blaxel/core/client/models/trace_ids_response.py +1 -1
- blaxel/core/client/models/trigger.py +2 -3
- blaxel/core/client/models/trigger_configuration.py +4 -5
- blaxel/core/client/models/trigger_configuration_task.py +1 -1
- blaxel/core/client/models/update_workspace_service_account_body.py +1 -1
- blaxel/core/client/models/update_workspace_service_account_response_200.py +1 -1
- blaxel/core/client/models/update_workspace_user_role_body.py +1 -1
- blaxel/core/client/models/volume.py +13 -6
- blaxel/core/client/models/volume_attachment.py +3 -3
- blaxel/core/client/models/volume_spec.py +2 -2
- blaxel/core/client/models/volume_state.py +2 -2
- blaxel/core/client/models/volume_template.py +6 -3
- blaxel/core/client/models/volume_template_spec.py +2 -2
- blaxel/core/client/models/volume_template_state.py +6 -4
- blaxel/core/client/models/volume_template_version.py +4 -4
- blaxel/core/client/models/websocket_channel.py +4 -4
- blaxel/core/client/models/websocket_message.py +3 -3
- blaxel/core/client/models/workspace.py +13 -10
- blaxel/core/client/models/workspace_labels.py +1 -1
- blaxel/core/client/models/workspace_runtime.py +1 -1
- blaxel/core/client/models/workspace_user.py +1 -1
- blaxel/core/client/response_interceptor.py +3 -1
- blaxel/core/common/autoload.py +9 -11
- blaxel/core/common/env.py +10 -8
- blaxel/core/common/settings.py +7 -5
- blaxel/core/common/webhook.py +0 -1
- blaxel/core/jobs/__init__.py +13 -3
- blaxel/core/mcp/client.py +8 -2
- blaxel/core/mcp/server.py +8 -2
- blaxel/core/models/__init__.py +6 -5
- blaxel/core/sandbox/__init__.py +1 -1
- blaxel/core/sandbox/client/api/codegen/get_codegen_reranking_path.py +10 -6
- blaxel/core/sandbox/client/api/fastapply/put_codegen_fastapply_path.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/delete_filesystem_multipart_upload_id_abort.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/delete_filesystem_path.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/delete_filesystem_tree_path.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_content_search_path.py +7 -5
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_find_path.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_multipart.py +4 -4
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_multipart_upload_id_parts.py +4 -4
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_path.py +4 -4
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_search_path.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_tree_path.py +4 -4
- blaxel/core/sandbox/client/api/filesystem/get_watch_filesystem_path.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/post_filesystem_multipart_initiate_path.py +4 -4
- blaxel/core/sandbox/client/api/filesystem/post_filesystem_multipart_upload_id_complete.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/put_filesystem_multipart_upload_id_part.py +4 -4
- blaxel/core/sandbox/client/api/filesystem/put_filesystem_path.py +10 -6
- blaxel/core/sandbox/client/api/filesystem/put_filesystem_tree_path.py +4 -4
- blaxel/core/sandbox/client/api/network/delete_network_process_pid_monitor.py +4 -4
- blaxel/core/sandbox/client/api/network/get_network_process_pid_ports.py +4 -4
- blaxel/core/sandbox/client/api/network/post_network_process_pid_monitor.py +4 -4
- blaxel/core/sandbox/client/api/process/delete_process_identifier.py +10 -6
- blaxel/core/sandbox/client/api/process/delete_process_identifier_kill.py +10 -6
- blaxel/core/sandbox/client/api/process/get_process.py +8 -6
- blaxel/core/sandbox/client/api/process/get_process_identifier.py +10 -6
- blaxel/core/sandbox/client/api/process/get_process_identifier_logs.py +10 -6
- blaxel/core/sandbox/client/api/process/get_process_identifier_logs_stream.py +10 -6
- blaxel/core/sandbox/client/api/process/post_process.py +10 -6
- blaxel/core/sandbox/client/api/root/delete.py +5 -5
- blaxel/core/sandbox/client/api/root/get.py +5 -5
- blaxel/core/sandbox/client/api/root/options.py +5 -5
- blaxel/core/sandbox/client/api/root/patch.py +5 -5
- blaxel/core/sandbox/client/api/root/post.py +5 -5
- blaxel/core/sandbox/client/api/root/put.py +5 -5
- blaxel/core/sandbox/client/client.py +3 -1
- blaxel/core/sandbox/client/models/apply_edit_request.py +2 -2
- blaxel/core/sandbox/client/models/apply_edit_response.py +3 -3
- blaxel/core/sandbox/client/models/content_search_match.py +1 -1
- blaxel/core/sandbox/client/models/content_search_response.py +1 -1
- blaxel/core/sandbox/client/models/delete_network_process_pid_monitor_response_200.py +1 -1
- blaxel/core/sandbox/client/models/directory.py +1 -1
- blaxel/core/sandbox/client/models/error_response.py +1 -1
- blaxel/core/sandbox/client/models/file.py +2 -2
- blaxel/core/sandbox/client/models/file_request.py +2 -2
- blaxel/core/sandbox/client/models/file_with_content.py +2 -2
- blaxel/core/sandbox/client/models/filesystem_multipart_upload.py +3 -3
- blaxel/core/sandbox/client/models/filesystem_multipart_upload_parts.py +4 -2
- blaxel/core/sandbox/client/models/filesystem_uploaded_part.py +3 -3
- blaxel/core/sandbox/client/models/find_match.py +2 -2
- blaxel/core/sandbox/client/models/find_response.py +1 -1
- blaxel/core/sandbox/client/models/fuzzy_search_match.py +2 -2
- blaxel/core/sandbox/client/models/fuzzy_search_response.py +1 -1
- blaxel/core/sandbox/client/models/get_network_process_pid_ports_response_200.py +1 -1
- blaxel/core/sandbox/client/models/multipart_complete_request.py +1 -1
- blaxel/core/sandbox/client/models/multipart_initiate_request.py +1 -1
- blaxel/core/sandbox/client/models/multipart_initiate_response.py +2 -2
- blaxel/core/sandbox/client/models/multipart_list_parts_response.py +2 -2
- blaxel/core/sandbox/client/models/multipart_list_uploads_response.py +1 -1
- blaxel/core/sandbox/client/models/multipart_part_info.py +2 -2
- blaxel/core/sandbox/client/models/multipart_upload_part_response.py +2 -2
- blaxel/core/sandbox/client/models/port_monitor_request.py +1 -1
- blaxel/core/sandbox/client/models/post_network_process_pid_monitor_response_200.py +1 -1
- blaxel/core/sandbox/client/models/process_logs.py +1 -1
- blaxel/core/sandbox/client/models/process_request.py +6 -6
- blaxel/core/sandbox/client/models/process_request_env.py +1 -1
- blaxel/core/sandbox/client/models/process_response.py +8 -8
- blaxel/core/sandbox/client/models/put_filesystem_multipart_upload_id_part_body.py +1 -1
- blaxel/core/sandbox/client/models/ranked_file.py +1 -1
- blaxel/core/sandbox/client/models/reranking_response.py +1 -1
- blaxel/core/sandbox/client/models/subdirectory.py +1 -1
- blaxel/core/sandbox/client/models/success_response.py +1 -1
- blaxel/core/sandbox/client/models/tree_request.py +1 -1
- blaxel/core/sandbox/client/models/tree_request_files.py +1 -1
- blaxel/core/sandbox/client/models/welcome_response.py +1 -1
- blaxel/core/sandbox/default/__init__.py +0 -1
- blaxel/core/sandbox/default/action.py +3 -3
- blaxel/core/sandbox/default/codegen.py +2 -4
- blaxel/core/sandbox/default/filesystem.py +38 -82
- blaxel/core/sandbox/default/interpreter.py +17 -10
- blaxel/core/sandbox/default/preview.py +6 -2
- blaxel/core/sandbox/default/process.py +20 -11
- blaxel/core/sandbox/default/sandbox.py +24 -14
- blaxel/core/sandbox/sync/__init__.py +0 -2
- blaxel/core/sandbox/sync/action.py +2 -3
- blaxel/core/sandbox/sync/codegen.py +1 -5
- blaxel/core/sandbox/sync/filesystem.py +17 -6
- blaxel/core/sandbox/sync/interpreter.py +10 -6
- blaxel/core/sandbox/sync/network.py +0 -2
- blaxel/core/sandbox/sync/preview.py +76 -33
- blaxel/core/sandbox/sync/process.py +27 -12
- blaxel/core/sandbox/sync/sandbox.py +30 -18
- blaxel/core/sandbox/sync/session.py +6 -4
- blaxel/core/sandbox/types.py +2 -1
- blaxel/core/tools/__init__.py +30 -6
- blaxel/core/tools/common.py +1 -1
- blaxel/core/tools/types.py +2 -1
- blaxel/crewai/model.py +20 -5
- blaxel/googleadk/__init__.py +1 -1
- blaxel/googleadk/tools.py +3 -5
- blaxel/langgraph/custom/gemini.py +126 -133
- blaxel/langgraph/model.py +54 -50
- blaxel/langgraph/tools.py +9 -3
- blaxel/llamaindex/custom/cohere.py +25 -16
- blaxel/llamaindex/model.py +44 -57
- blaxel/llamaindex/tools.py +2 -3
- blaxel/pydantic/custom/gemini.py +3 -3
- blaxel/pydantic/tools.py +2 -4
- blaxel/telemetry/exporters.py +10 -3
- blaxel/telemetry/instrumentation/blaxel_langgraph.py +4 -2
- blaxel/telemetry/instrumentation/blaxel_langgraph_gemini.py +22 -5
- blaxel/telemetry/instrumentation/utils.py +3 -3
- blaxel/telemetry/log/log.py +2 -3
- blaxel/telemetry/log/logger.py +21 -15
- blaxel/telemetry/span.py +10 -6
- {blaxel-0.2.31rc120.dist-info → blaxel-0.2.32.dist-info}/METADATA +2 -2
- blaxel-0.2.32.dist-info/RECORD +506 -0
- blaxel/core/client/api/compute/start_sandbox.py +0 -157
- blaxel/core/client/api/compute/stop_sandbox.py +0 -157
- blaxel-0.2.31rc120.dist-info/RECORD +0 -508
- {blaxel-0.2.31rc120.dist-info → blaxel-0.2.32.dist-info}/WHEEL +0 -0
- {blaxel-0.2.31rc120.dist-info → blaxel-0.2.32.dist-info}/licenses/LICENSE +0 -0
|
@@ -23,9 +23,15 @@ from typing import (
|
|
|
23
23
|
|
|
24
24
|
import httpx
|
|
25
25
|
import requests
|
|
26
|
-
from langchain_core.callbacks.manager import
|
|
26
|
+
from langchain_core.callbacks.manager import (
|
|
27
|
+
AsyncCallbackManagerForLLMRun,
|
|
28
|
+
CallbackManagerForLLMRun,
|
|
29
|
+
)
|
|
27
30
|
from langchain_core.language_models import LanguageModelInput
|
|
28
|
-
from langchain_core.language_models.chat_models import
|
|
31
|
+
from langchain_core.language_models.chat_models import (
|
|
32
|
+
BaseChatModel,
|
|
33
|
+
LangSmithParams,
|
|
34
|
+
)
|
|
29
35
|
from langchain_core.messages import (
|
|
30
36
|
AIMessage,
|
|
31
37
|
AIMessageChunk,
|
|
@@ -36,13 +42,21 @@ from langchain_core.messages import (
|
|
|
36
42
|
ToolMessage,
|
|
37
43
|
)
|
|
38
44
|
from langchain_core.messages.ai import UsageMetadata
|
|
39
|
-
from langchain_core.messages.tool import
|
|
45
|
+
from langchain_core.messages.tool import (
|
|
46
|
+
invalid_tool_call,
|
|
47
|
+
tool_call,
|
|
48
|
+
tool_call_chunk,
|
|
49
|
+
)
|
|
40
50
|
from langchain_core.output_parsers.openai_tools import (
|
|
41
51
|
JsonOutputKeyToolsParser,
|
|
42
52
|
PydanticToolsParser,
|
|
43
53
|
parse_tool_calls,
|
|
44
54
|
)
|
|
45
|
-
from langchain_core.outputs import
|
|
55
|
+
from langchain_core.outputs import (
|
|
56
|
+
ChatGeneration,
|
|
57
|
+
ChatGenerationChunk,
|
|
58
|
+
ChatResult,
|
|
59
|
+
)
|
|
46
60
|
from langchain_core.runnables import Runnable, RunnablePassthrough
|
|
47
61
|
from langchain_core.tools import BaseTool
|
|
48
62
|
from langchain_core.utils.function_calling import convert_to_openai_tool
|
|
@@ -73,6 +87,7 @@ _ToolDict = Dict[str, Any]
|
|
|
73
87
|
SafetySettingDict = Dict[str, str]
|
|
74
88
|
OutputParserLike = Union[PydanticToolsParser, JsonOutputKeyToolsParser]
|
|
75
89
|
|
|
90
|
+
|
|
76
91
|
# Data classes
|
|
77
92
|
class Part(BaseModel):
|
|
78
93
|
text: str | None = None
|
|
@@ -81,38 +96,47 @@ class Part(BaseModel):
|
|
|
81
96
|
function_call: Dict[str, Any] | None = None
|
|
82
97
|
function_response: Dict[str, Any] | None = None
|
|
83
98
|
|
|
99
|
+
|
|
84
100
|
class Content(BaseModel):
|
|
85
101
|
role: str | None = None
|
|
86
102
|
parts: List[Part]
|
|
87
103
|
|
|
104
|
+
|
|
88
105
|
class Blob(BaseModel):
|
|
89
106
|
data: str
|
|
90
107
|
mime_type: str
|
|
91
108
|
|
|
109
|
+
|
|
92
110
|
class FileData(BaseModel):
|
|
93
111
|
file_uri: str
|
|
94
112
|
mime_type: str
|
|
95
113
|
|
|
114
|
+
|
|
96
115
|
class VideoMetadata(BaseModel):
|
|
97
116
|
duration: str | None = None
|
|
98
117
|
start_offset: str | None = None
|
|
99
118
|
end_offset: str | None = None
|
|
100
119
|
|
|
120
|
+
|
|
101
121
|
class FunctionCall(BaseModel):
|
|
102
122
|
name: str
|
|
103
123
|
args: Dict[str, Any]
|
|
104
124
|
|
|
125
|
+
|
|
105
126
|
class FunctionResponse(BaseModel):
|
|
106
127
|
name: str
|
|
107
128
|
response: Dict[str, Any]
|
|
108
129
|
|
|
130
|
+
|
|
109
131
|
class SafetySetting(BaseModel):
|
|
110
132
|
category: str
|
|
111
133
|
threshold: str
|
|
112
134
|
|
|
135
|
+
|
|
113
136
|
class ToolConfig(BaseModel):
|
|
114
137
|
function_calling_config: Dict[str, Any]
|
|
115
138
|
|
|
139
|
+
|
|
116
140
|
class GenerationConfig(BaseModel):
|
|
117
141
|
candidate_count: int | None = None
|
|
118
142
|
temperature: float | None = None
|
|
@@ -122,11 +146,13 @@ class GenerationConfig(BaseModel):
|
|
|
122
146
|
top_p: float | None = None
|
|
123
147
|
response_modalities: List[str] | None = None
|
|
124
148
|
|
|
149
|
+
|
|
125
150
|
class GoogleTool(BaseModel):
|
|
126
151
|
name: str
|
|
127
152
|
description: str
|
|
128
153
|
parameters: Dict[str, Any]
|
|
129
154
|
|
|
155
|
+
|
|
130
156
|
class ImageBytesLoader:
|
|
131
157
|
def load_part(self, image_url: str) -> Part:
|
|
132
158
|
"""Load an image from a URL and convert it to a Part."""
|
|
@@ -138,16 +164,17 @@ class ImageBytesLoader:
|
|
|
138
164
|
# Convert to JPEG format
|
|
139
165
|
img = Image.open(io.BytesIO(response.content))
|
|
140
166
|
img_byte_arr = io.BytesIO()
|
|
141
|
-
img.save(img_byte_arr, format=
|
|
167
|
+
img.save(img_byte_arr, format="JPEG")
|
|
142
168
|
img_byte_arr = img_byte_arr.getvalue()
|
|
143
169
|
|
|
144
170
|
return Part(
|
|
145
171
|
inline_data={
|
|
146
172
|
"mime_type": "image/jpeg",
|
|
147
|
-
"data": img_byte_arr.decode(
|
|
173
|
+
"data": img_byte_arr.decode("utf-8"),
|
|
148
174
|
}
|
|
149
175
|
)
|
|
150
176
|
|
|
177
|
+
|
|
151
178
|
class ChatGoogleGenerativeAIError(Exception):
|
|
152
179
|
"""
|
|
153
180
|
Custom exception class for errors associated with the `Google GenAI` API.
|
|
@@ -156,6 +183,7 @@ class ChatGoogleGenerativeAIError(Exception):
|
|
|
156
183
|
Google genai API usage in the ChatGoogleGenerativeAI class, such as unsupported
|
|
157
184
|
message types or roles.
|
|
158
185
|
"""
|
|
186
|
+
|
|
159
187
|
pass
|
|
160
188
|
|
|
161
189
|
|
|
@@ -210,8 +238,8 @@ def _chat_with_retry(generation_method: Callable, **kwargs: Any) -> Any:
|
|
|
210
238
|
def _chat_with_retry(**kwargs: Any) -> Any:
|
|
211
239
|
try:
|
|
212
240
|
# Extract request parameters and other kwargs
|
|
213
|
-
request = kwargs.pop(
|
|
214
|
-
kwargs.pop(
|
|
241
|
+
request = kwargs.pop("request", {})
|
|
242
|
+
kwargs.pop("metadata", None)
|
|
215
243
|
|
|
216
244
|
# Unpack request parameters into kwargs
|
|
217
245
|
kwargs.update(request)
|
|
@@ -224,14 +252,10 @@ def _chat_with_retry(generation_method: Callable, **kwargs: Any) -> Any:
|
|
|
224
252
|
)
|
|
225
253
|
raise ValueError(error_msg)
|
|
226
254
|
elif e.response.status_code == 403: # Forbidden
|
|
227
|
-
error_msg =
|
|
228
|
-
"Access forbidden. Please check your API key and permissions."
|
|
229
|
-
)
|
|
255
|
+
error_msg = "Access forbidden. Please check your API key and permissions."
|
|
230
256
|
raise ValueError(error_msg)
|
|
231
257
|
else:
|
|
232
|
-
raise ChatGoogleGenerativeAIError(
|
|
233
|
-
f"HTTP error occurred: {e.response.text}"
|
|
234
|
-
) from e
|
|
258
|
+
raise ChatGoogleGenerativeAIError(f"HTTP error occurred: {e.response.text}") from e
|
|
235
259
|
except Exception as e:
|
|
236
260
|
raise e
|
|
237
261
|
|
|
@@ -259,8 +283,8 @@ async def _achat_with_retry(generation_method: Callable, **kwargs: Any) -> Any:
|
|
|
259
283
|
async def _achat_with_retry(**kwargs: Any) -> Any:
|
|
260
284
|
try:
|
|
261
285
|
# Extract request parameters and other kwargs
|
|
262
|
-
request = kwargs.pop(
|
|
263
|
-
kwargs.pop(
|
|
286
|
+
request = kwargs.pop("request", {})
|
|
287
|
+
kwargs.pop("metadata", None)
|
|
264
288
|
|
|
265
289
|
# Unpack request parameters into kwargs
|
|
266
290
|
kwargs.update(request)
|
|
@@ -273,14 +297,10 @@ async def _achat_with_retry(generation_method: Callable, **kwargs: Any) -> Any:
|
|
|
273
297
|
)
|
|
274
298
|
raise ValueError(error_msg)
|
|
275
299
|
elif e.response.status_code == 403: # Forbidden
|
|
276
|
-
error_msg =
|
|
277
|
-
"Access forbidden. Please check your API key and permissions."
|
|
278
|
-
)
|
|
300
|
+
error_msg = "Access forbidden. Please check your API key and permissions."
|
|
279
301
|
raise ValueError(error_msg)
|
|
280
302
|
else:
|
|
281
|
-
raise ChatGoogleGenerativeAIError(
|
|
282
|
-
f"HTTP error occurred: {e.response.text}"
|
|
283
|
-
) from e
|
|
303
|
+
raise ChatGoogleGenerativeAIError(f"HTTP error occurred: {e.response.text}") from e
|
|
284
304
|
except Exception as e:
|
|
285
305
|
raise e
|
|
286
306
|
|
|
@@ -310,9 +330,7 @@ def _convert_to_parts(
|
|
|
310
330
|
img_url = part["image_url"]
|
|
311
331
|
if isinstance(img_url, dict):
|
|
312
332
|
if "url" not in img_url:
|
|
313
|
-
raise ValueError(
|
|
314
|
-
f"Unrecognized message image format: {img_url}"
|
|
315
|
-
)
|
|
333
|
+
raise ValueError(f"Unrecognized message image format: {img_url}")
|
|
316
334
|
img_url = img_url["url"]
|
|
317
335
|
parts.append(image_loader.load_part(img_url))
|
|
318
336
|
# Handle media type like LangChain.js
|
|
@@ -324,17 +342,13 @@ def _convert_to_parts(
|
|
|
324
342
|
media_part = Part()
|
|
325
343
|
|
|
326
344
|
if "data" in part:
|
|
327
|
-
media_part.inline_data = Blob(
|
|
328
|
-
data=part["data"], mime_type=mime_type
|
|
329
|
-
)
|
|
345
|
+
media_part.inline_data = Blob(data=part["data"], mime_type=mime_type)
|
|
330
346
|
elif "file_uri" in part:
|
|
331
347
|
media_part.file_data = FileData(
|
|
332
348
|
file_uri=part["file_uri"], mime_type=mime_type
|
|
333
349
|
)
|
|
334
350
|
else:
|
|
335
|
-
raise ValueError(
|
|
336
|
-
f"Media part must have either data or file_uri: {part}"
|
|
337
|
-
)
|
|
351
|
+
raise ValueError(f"Media part must have either data or file_uri: {part}")
|
|
338
352
|
parts.append(media_part)
|
|
339
353
|
else:
|
|
340
354
|
raise ValueError(
|
|
@@ -343,16 +357,12 @@ def _convert_to_parts(
|
|
|
343
357
|
)
|
|
344
358
|
else:
|
|
345
359
|
# Yolo
|
|
346
|
-
logger.warning(
|
|
347
|
-
"Unrecognized message part format. Assuming it's a text part."
|
|
348
|
-
)
|
|
360
|
+
logger.warning("Unrecognized message part format. Assuming it's a text part.")
|
|
349
361
|
parts.append(Part(text=str(part)))
|
|
350
362
|
else:
|
|
351
363
|
# TODO: Maybe some of Google's native stuff
|
|
352
364
|
# would hit this branch.
|
|
353
|
-
raise ChatGoogleGenerativeAIError(
|
|
354
|
-
"Gemini only supports text and inline_data parts."
|
|
355
|
-
)
|
|
365
|
+
raise ChatGoogleGenerativeAIError("Gemini only supports text and inline_data parts.")
|
|
356
366
|
return parts
|
|
357
367
|
|
|
358
368
|
|
|
@@ -404,7 +414,8 @@ def _get_ai_message_tool_messages_parts(
|
|
|
404
414
|
|
|
405
415
|
|
|
406
416
|
def _parse_chat_history(
|
|
407
|
-
input_messages: Sequence[BaseMessage],
|
|
417
|
+
input_messages: Sequence[BaseMessage],
|
|
418
|
+
convert_system_message_to_human: bool = False,
|
|
408
419
|
) -> Tuple[Content | None, List[Content]]:
|
|
409
420
|
messages: List[Content] = []
|
|
410
421
|
|
|
@@ -415,9 +426,7 @@ def _parse_chat_history(
|
|
|
415
426
|
messages_without_tool_messages = [
|
|
416
427
|
message for message in input_messages if not isinstance(message, ToolMessage)
|
|
417
428
|
]
|
|
418
|
-
tool_messages = [
|
|
419
|
-
message for message in input_messages if isinstance(message, ToolMessage)
|
|
420
|
-
]
|
|
429
|
+
tool_messages = [message for message in input_messages if isinstance(message, ToolMessage)]
|
|
421
430
|
for i, message in enumerate(messages_without_tool_messages):
|
|
422
431
|
if isinstance(message, SystemMessage):
|
|
423
432
|
system_parts = _convert_to_parts(message.content)
|
|
@@ -462,9 +471,7 @@ def _parse_chat_history(
|
|
|
462
471
|
role = "user"
|
|
463
472
|
parts = [_convert_tool_message_to_part(message)]
|
|
464
473
|
else:
|
|
465
|
-
raise ValueError(
|
|
466
|
-
f"Unexpected message with type {type(message)} at the position {i}."
|
|
467
|
-
)
|
|
474
|
+
raise ValueError(f"Unexpected message with type {type(message)} at the position {i}.")
|
|
468
475
|
|
|
469
476
|
messages.append(Content(role=role, parts=parts))
|
|
470
477
|
return system_instruction, messages
|
|
@@ -623,9 +630,7 @@ def _response_to_result(
|
|
|
623
630
|
)
|
|
624
631
|
)
|
|
625
632
|
else:
|
|
626
|
-
generations.append(
|
|
627
|
-
ChatGeneration(message=message, generation_info=generation_info)
|
|
628
|
-
)
|
|
633
|
+
generations.append(ChatGeneration(message=message, generation_info=generation_info))
|
|
629
634
|
if not response.get("candidates"):
|
|
630
635
|
# Likely a "prompt feedback" violation (e.g., toxic input)
|
|
631
636
|
# Raising an error would be different than how OpenAI handles it,
|
|
@@ -636,9 +641,7 @@ def _response_to_result(
|
|
|
636
641
|
)
|
|
637
642
|
if stream:
|
|
638
643
|
generations = [
|
|
639
|
-
ChatGenerationChunk(
|
|
640
|
-
message=AIMessageChunk(content=""), generation_info={}
|
|
641
|
-
)
|
|
644
|
+
ChatGenerationChunk(message=AIMessageChunk(content=""), generation_info={})
|
|
642
645
|
]
|
|
643
646
|
else:
|
|
644
647
|
generations = [ChatGeneration(message=AIMessage(""), generation_info={})]
|
|
@@ -696,7 +699,7 @@ class GeminiRestClient:
|
|
|
696
699
|
|
|
697
700
|
def _convert_to_dict(self, obj: Any) -> Any:
|
|
698
701
|
"""Convert Pydantic models and other objects to dictionaries."""
|
|
699
|
-
if hasattr(obj,
|
|
702
|
+
if hasattr(obj, "model_dump"):
|
|
700
703
|
return obj.model_dump()
|
|
701
704
|
elif isinstance(obj, list):
|
|
702
705
|
return [self._convert_to_dict(item) for item in obj]
|
|
@@ -810,7 +813,6 @@ class GeminiRestClient:
|
|
|
810
813
|
cached_content=cached_content,
|
|
811
814
|
)
|
|
812
815
|
|
|
813
|
-
|
|
814
816
|
with self._get_client().stream(
|
|
815
817
|
"POST",
|
|
816
818
|
f"v1beta/{model}:streamGenerateContent",
|
|
@@ -927,7 +929,9 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
927
929
|
else:
|
|
928
930
|
google_api_key = self.google_api_key
|
|
929
931
|
|
|
930
|
-
base_url = self.client_options.get(
|
|
932
|
+
base_url = self.client_options.get(
|
|
933
|
+
"api_endpoint", "https://generativelanguage.googleapis.com"
|
|
934
|
+
)
|
|
931
935
|
self.client = GeminiRestClient(
|
|
932
936
|
api_key=google_api_key,
|
|
933
937
|
base_url=base_url,
|
|
@@ -940,9 +944,7 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
940
944
|
)
|
|
941
945
|
return self
|
|
942
946
|
|
|
943
|
-
def _get_ls_params(
|
|
944
|
-
self, stop: List[str] | None = None, **kwargs: Any
|
|
945
|
-
) -> LangSmithParams:
|
|
947
|
+
def _get_ls_params(self, stop: List[str] | None = None, **kwargs: Any) -> LangSmithParams:
|
|
946
948
|
"""Get standard params for tracing."""
|
|
947
949
|
params = self._get_invocation_params(stop=stop, **kwargs)
|
|
948
950
|
ls_params = LangSmithParams(
|
|
@@ -1082,15 +1084,11 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1082
1084
|
|
|
1083
1085
|
prev_usage_metadata: UsageMetadata | None = None
|
|
1084
1086
|
for chunk in response:
|
|
1085
|
-
_chat_result = _response_to_result(
|
|
1086
|
-
chunk, stream=True, prev_usage=prev_usage_metadata
|
|
1087
|
-
)
|
|
1087
|
+
_chat_result = _response_to_result(chunk, stream=True, prev_usage=prev_usage_metadata)
|
|
1088
1088
|
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
|
|
1089
1089
|
message = cast(AIMessageChunk, gen.message)
|
|
1090
1090
|
|
|
1091
|
-
curr_usage_metadata: UsageMetadata | dict[str, int] =
|
|
1092
|
-
message.usage_metadata or {}
|
|
1093
|
-
)
|
|
1091
|
+
curr_usage_metadata: UsageMetadata | dict[str, int] = message.usage_metadata or {}
|
|
1094
1092
|
|
|
1095
1093
|
prev_usage_metadata = (
|
|
1096
1094
|
message.usage_metadata
|
|
@@ -1142,15 +1140,11 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1142
1140
|
**kwargs,
|
|
1143
1141
|
metadata=self.default_metadata,
|
|
1144
1142
|
):
|
|
1145
|
-
_chat_result = _response_to_result(
|
|
1146
|
-
chunk, stream=True, prev_usage=prev_usage_metadata
|
|
1147
|
-
)
|
|
1143
|
+
_chat_result = _response_to_result(chunk, stream=True, prev_usage=prev_usage_metadata)
|
|
1148
1144
|
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
|
|
1149
1145
|
message = cast(AIMessageChunk, gen.message)
|
|
1150
1146
|
|
|
1151
|
-
curr_usage_metadata: UsageMetadata | dict[str, int] =
|
|
1152
|
-
message.usage_metadata or {}
|
|
1153
|
-
)
|
|
1147
|
+
curr_usage_metadata: UsageMetadata | dict[str, int] = message.usage_metadata or {}
|
|
1154
1148
|
|
|
1155
1149
|
prev_usage_metadata = (
|
|
1156
1150
|
message.usage_metadata
|
|
@@ -1196,9 +1190,7 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1196
1190
|
filtered_messages = []
|
|
1197
1191
|
for message in messages:
|
|
1198
1192
|
if isinstance(message, HumanMessage) and not message.content:
|
|
1199
|
-
warnings.warn(
|
|
1200
|
-
"HumanMessage with empty content was removed to prevent API error"
|
|
1201
|
-
)
|
|
1193
|
+
warnings.warn("HumanMessage with empty content was removed to prevent API error")
|
|
1202
1194
|
else:
|
|
1203
1195
|
filtered_messages.append(message)
|
|
1204
1196
|
messages = filtered_messages
|
|
@@ -1214,9 +1206,7 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1214
1206
|
f"be specified if 'tools' is specified."
|
|
1215
1207
|
)
|
|
1216
1208
|
raise ValueError(msg)
|
|
1217
|
-
all_names = [
|
|
1218
|
-
f.name for t in formatted_tools for f in t.function_declarations
|
|
1219
|
-
]
|
|
1209
|
+
all_names = [f.name for t in formatted_tools for f in t.function_declarations]
|
|
1220
1210
|
tool_config = _tool_choice_to_tool_config(tool_choice, all_names)
|
|
1221
1211
|
|
|
1222
1212
|
formatted_tool_config = None
|
|
@@ -1227,8 +1217,7 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1227
1217
|
formatted_safety_settings = []
|
|
1228
1218
|
if safety_settings:
|
|
1229
1219
|
formatted_safety_settings = [
|
|
1230
|
-
SafetySetting(category=c, threshold=t)
|
|
1231
|
-
for c, t in safety_settings.items()
|
|
1220
|
+
SafetySetting(category=c, threshold=t) for c, t in safety_settings.items()
|
|
1232
1221
|
]
|
|
1233
1222
|
|
|
1234
1223
|
# Construct the full model path
|
|
@@ -1240,9 +1229,7 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1240
1229
|
"tools": formatted_tools,
|
|
1241
1230
|
"tool_config": formatted_tool_config,
|
|
1242
1231
|
"safety_settings": formatted_safety_settings,
|
|
1243
|
-
"generation_config": self._prepare_params(
|
|
1244
|
-
stop, generation_config=generation_config
|
|
1245
|
-
),
|
|
1232
|
+
"generation_config": self._prepare_params(stop, generation_config=generation_config),
|
|
1246
1233
|
"cached_content": cached_content,
|
|
1247
1234
|
}
|
|
1248
1235
|
if system_instruction:
|
|
@@ -1280,9 +1267,7 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1280
1267
|
raise ValueError(f"Received unsupported arguments {kwargs}")
|
|
1281
1268
|
tool_name = _get_tool_name(schema) # type: ignore[arg-type]
|
|
1282
1269
|
if isinstance(schema, type) and is_basemodel_subclass_safe(schema):
|
|
1283
|
-
parser: OutputParserLike = PydanticToolsParser(
|
|
1284
|
-
tools=[schema], first_tool_only=True
|
|
1285
|
-
)
|
|
1270
|
+
parser: OutputParserLike = PydanticToolsParser(tools=[schema], first_tool_only=True)
|
|
1286
1271
|
else:
|
|
1287
1272
|
global WARNED_STRUCTURED_OUTPUT_JSON_MODE
|
|
1288
1273
|
warnings.warn(
|
|
@@ -1318,9 +1303,7 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1318
1303
|
|
|
1319
1304
|
def bind_tools(
|
|
1320
1305
|
self,
|
|
1321
|
-
tools: Sequence[
|
|
1322
|
-
dict[str, Any] | type | Callable[..., Any] | BaseTool | GoogleTool
|
|
1323
|
-
],
|
|
1306
|
+
tools: Sequence[dict[str, Any] | type | Callable[..., Any] | BaseTool | GoogleTool],
|
|
1324
1307
|
tool_config: Union[Dict, _ToolConfigDict] | None = None,
|
|
1325
1308
|
*,
|
|
1326
1309
|
tool_choice: Union[_ToolChoiceType, bool] | None = None,
|
|
@@ -1346,9 +1329,7 @@ class ChatGoogleGenerativeAI(BaseChatModel):
|
|
|
1346
1329
|
try:
|
|
1347
1330
|
formatted_tools: list = [convert_to_openai_tool(tool) for tool in tools] # type: ignore[arg-type]
|
|
1348
1331
|
except Exception:
|
|
1349
|
-
formatted_tools = [
|
|
1350
|
-
tool_to_dict(convert_to_genai_function_declarations(tools))
|
|
1351
|
-
]
|
|
1332
|
+
formatted_tools = [tool_to_dict(convert_to_genai_function_declarations(tools))]
|
|
1352
1333
|
if tool_choice:
|
|
1353
1334
|
kwargs["tool_choice"] = tool_choice
|
|
1354
1335
|
elif tool_config:
|
|
@@ -1378,6 +1359,7 @@ def _get_tool_name(
|
|
|
1378
1359
|
else:
|
|
1379
1360
|
raise e
|
|
1380
1361
|
|
|
1362
|
+
|
|
1381
1363
|
def _tool_choice_to_tool_config(
|
|
1382
1364
|
tool_choice: Union[str, bool, Dict[str, Any]], all_names: List[str]
|
|
1383
1365
|
) -> Dict[str, Any]:
|
|
@@ -1390,9 +1372,7 @@ def _tool_choice_to_tool_config(
|
|
|
1390
1372
|
}
|
|
1391
1373
|
elif isinstance(tool_choice, str):
|
|
1392
1374
|
if tool_choice not in all_names:
|
|
1393
|
-
raise ValueError(
|
|
1394
|
-
f"Tool choice {tool_choice} not found in available tools: {all_names}"
|
|
1395
|
-
)
|
|
1375
|
+
raise ValueError(f"Tool choice {tool_choice} not found in available tools: {all_names}")
|
|
1396
1376
|
return {
|
|
1397
1377
|
"function_calling_config": {
|
|
1398
1378
|
"mode": "ANY",
|
|
@@ -1402,8 +1382,9 @@ def _tool_choice_to_tool_config(
|
|
|
1402
1382
|
else:
|
|
1403
1383
|
return tool_choice
|
|
1404
1384
|
|
|
1385
|
+
|
|
1405
1386
|
def convert_to_genai_function_declarations(
|
|
1406
|
-
tools: Sequence[Union[Dict[str, Any], Type[BaseModel], Callable[..., Any], BaseTool]]
|
|
1387
|
+
tools: Sequence[Union[Dict[str, Any], Type[BaseModel], Callable[..., Any], BaseTool]],
|
|
1407
1388
|
) -> Dict[str, Any]:
|
|
1408
1389
|
"""Convert tools to Gemini function declarations format."""
|
|
1409
1390
|
function_declarations = []
|
|
@@ -1411,55 +1392,64 @@ def convert_to_genai_function_declarations(
|
|
|
1411
1392
|
if isinstance(tool, dict):
|
|
1412
1393
|
fn = tool.get("function", {})
|
|
1413
1394
|
fn_parameters = fn.get("parameters", {})
|
|
1414
|
-
function_declarations.append(
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
"
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1395
|
+
function_declarations.append(
|
|
1396
|
+
{
|
|
1397
|
+
"name": fn.get("name", ""),
|
|
1398
|
+
"description": fn.get("description", ""),
|
|
1399
|
+
"parameters": {
|
|
1400
|
+
"type": "object",
|
|
1401
|
+
"properties": fn_parameters.get("properties", {}),
|
|
1402
|
+
"required": fn_parameters.get("required", []),
|
|
1403
|
+
},
|
|
1404
|
+
}
|
|
1405
|
+
)
|
|
1423
1406
|
elif isinstance(tool, type) and issubclass(tool, BaseModel):
|
|
1424
1407
|
schema = tool.model_json_schema()
|
|
1425
|
-
function_declarations.append(
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
"
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1408
|
+
function_declarations.append(
|
|
1409
|
+
{
|
|
1410
|
+
"name": schema.get("title", ""),
|
|
1411
|
+
"description": schema.get("description", ""),
|
|
1412
|
+
"parameters": {
|
|
1413
|
+
"type": "object",
|
|
1414
|
+
"properties": {
|
|
1415
|
+
name: {
|
|
1416
|
+
"type": prop.get("type", "string"),
|
|
1417
|
+
"description": prop.get("description", ""),
|
|
1418
|
+
}
|
|
1419
|
+
for name, prop in schema.get("properties", {}).items()
|
|
1420
|
+
},
|
|
1421
|
+
"required": schema.get("required", []),
|
|
1436
1422
|
},
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
})
|
|
1423
|
+
}
|
|
1424
|
+
)
|
|
1440
1425
|
elif callable(tool):
|
|
1441
1426
|
# For callables, we'll create a basic function declaration
|
|
1442
|
-
function_declarations.append(
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
"
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1427
|
+
function_declarations.append(
|
|
1428
|
+
{
|
|
1429
|
+
"name": tool.__name__,
|
|
1430
|
+
"description": tool.__doc__ or "",
|
|
1431
|
+
"parameters": {
|
|
1432
|
+
"type": "object",
|
|
1433
|
+
"properties": {},
|
|
1434
|
+
"required": [],
|
|
1435
|
+
},
|
|
1436
|
+
}
|
|
1437
|
+
)
|
|
1451
1438
|
elif isinstance(tool, BaseTool):
|
|
1452
|
-
function_declarations.append(
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
"
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1439
|
+
function_declarations.append(
|
|
1440
|
+
{
|
|
1441
|
+
"name": tool.name,
|
|
1442
|
+
"description": tool.description,
|
|
1443
|
+
"parameters": {
|
|
1444
|
+
"type": "object",
|
|
1445
|
+
"properties": {},
|
|
1446
|
+
"required": [],
|
|
1447
|
+
},
|
|
1448
|
+
}
|
|
1449
|
+
)
|
|
1461
1450
|
return {"functionDeclarations": function_declarations}
|
|
1462
1451
|
|
|
1452
|
+
|
|
1463
1453
|
def is_basemodel_subclass_safe(cls: Type[Any]) -> bool:
|
|
1464
1454
|
"""Check if a class is a safe subclass of BaseModel."""
|
|
1465
1455
|
try:
|
|
@@ -1467,11 +1457,14 @@ def is_basemodel_subclass_safe(cls: Type[Any]) -> bool:
|
|
|
1467
1457
|
except TypeError:
|
|
1468
1458
|
return False
|
|
1469
1459
|
|
|
1460
|
+
|
|
1470
1461
|
def tool_to_dict(tool: Dict[str, Any]) -> Dict[str, Any]:
|
|
1471
1462
|
"""Convert a tool to a dictionary format."""
|
|
1472
1463
|
return tool
|
|
1473
1464
|
|
|
1465
|
+
|
|
1474
1466
|
def image_bytes_to_b64_string(image_bytes: bytes, image_format: str = "jpeg") -> str:
|
|
1475
1467
|
"""Convert image bytes to base64 string."""
|
|
1476
1468
|
import base64
|
|
1469
|
+
|
|
1477
1470
|
return f"data:image/{image_format};base64,{base64.b64encode(image_bytes).decode('utf-8')}"
|