mirascope 1.25.7__py3-none-any.whl → 2.0.0a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mirascope/__init__.py +3 -59
- mirascope/graphs/__init__.py +22 -0
- mirascope/{experimental/graphs → graphs}/finite_state_machine.py +70 -159
- mirascope/llm/__init__.py +206 -16
- mirascope/llm/agents/__init__.py +15 -0
- mirascope/llm/agents/agent.py +97 -0
- mirascope/llm/agents/agent_template.py +45 -0
- mirascope/llm/agents/decorator.py +176 -0
- mirascope/llm/calls/__init__.py +16 -0
- mirascope/llm/calls/base_call.py +33 -0
- mirascope/llm/calls/calls.py +315 -0
- mirascope/llm/calls/decorator.py +255 -0
- mirascope/llm/clients/__init__.py +34 -0
- mirascope/llm/clients/anthropic/__init__.py +11 -0
- mirascope/llm/clients/anthropic/_utils/__init__.py +13 -0
- mirascope/llm/clients/anthropic/_utils/decode.py +244 -0
- mirascope/llm/clients/anthropic/_utils/encode.py +243 -0
- mirascope/llm/clients/anthropic/clients.py +819 -0
- mirascope/llm/clients/anthropic/model_ids.py +8 -0
- mirascope/llm/clients/base/__init__.py +15 -0
- mirascope/llm/clients/base/_utils.py +192 -0
- mirascope/llm/clients/base/client.py +1256 -0
- mirascope/llm/clients/base/kwargs.py +12 -0
- mirascope/llm/clients/base/params.py +93 -0
- mirascope/llm/clients/google/__init__.py +6 -0
- mirascope/llm/clients/google/_utils/__init__.py +13 -0
- mirascope/llm/clients/google/_utils/decode.py +231 -0
- mirascope/llm/clients/google/_utils/encode.py +279 -0
- mirascope/llm/clients/google/clients.py +853 -0
- mirascope/llm/clients/google/message.py +7 -0
- mirascope/llm/clients/google/model_ids.py +15 -0
- mirascope/llm/clients/openai/__init__.py +25 -0
- mirascope/llm/clients/openai/completions/__init__.py +9 -0
- mirascope/llm/clients/openai/completions/_utils/__init__.py +13 -0
- mirascope/llm/clients/openai/completions/_utils/decode.py +187 -0
- mirascope/llm/clients/openai/completions/_utils/encode.py +358 -0
- mirascope/llm/clients/openai/completions/_utils/model_features.py +81 -0
- mirascope/llm/clients/openai/completions/clients.py +833 -0
- mirascope/llm/clients/openai/completions/model_ids.py +8 -0
- mirascope/llm/clients/openai/responses/__init__.py +9 -0
- mirascope/llm/clients/openai/responses/_utils/__init__.py +13 -0
- mirascope/llm/clients/openai/responses/_utils/decode.py +194 -0
- mirascope/llm/clients/openai/responses/_utils/encode.py +333 -0
- mirascope/llm/clients/openai/responses/_utils/model_features.py +87 -0
- mirascope/llm/clients/openai/responses/clients.py +832 -0
- mirascope/llm/clients/openai/responses/model_ids.py +8 -0
- mirascope/llm/clients/openai/shared/__init__.py +7 -0
- mirascope/llm/clients/openai/shared/_utils.py +55 -0
- mirascope/llm/clients/providers.py +175 -0
- mirascope/llm/content/__init__.py +70 -0
- mirascope/llm/content/audio.py +173 -0
- mirascope/llm/content/document.py +94 -0
- mirascope/llm/content/image.py +206 -0
- mirascope/llm/content/text.py +47 -0
- mirascope/llm/content/thought.py +58 -0
- mirascope/llm/content/tool_call.py +63 -0
- mirascope/llm/content/tool_output.py +26 -0
- mirascope/llm/context/__init__.py +6 -0
- mirascope/llm/context/_utils.py +28 -0
- mirascope/llm/context/context.py +24 -0
- mirascope/llm/exceptions.py +105 -0
- mirascope/llm/formatting/__init__.py +22 -0
- mirascope/llm/formatting/_utils.py +74 -0
- mirascope/llm/formatting/format.py +104 -0
- mirascope/llm/formatting/from_call_args.py +30 -0
- mirascope/llm/formatting/partial.py +58 -0
- mirascope/llm/formatting/types.py +109 -0
- mirascope/llm/mcp/__init__.py +5 -0
- mirascope/llm/mcp/client.py +118 -0
- mirascope/llm/messages/__init__.py +32 -0
- mirascope/llm/messages/message.py +182 -0
- mirascope/llm/models/__init__.py +16 -0
- mirascope/llm/models/models.py +1243 -0
- mirascope/llm/prompts/__init__.py +33 -0
- mirascope/llm/prompts/_utils.py +60 -0
- mirascope/llm/prompts/decorator.py +286 -0
- mirascope/llm/prompts/protocols.py +99 -0
- mirascope/llm/responses/__init__.py +57 -0
- mirascope/llm/responses/_utils.py +56 -0
- mirascope/llm/responses/base_response.py +91 -0
- mirascope/llm/responses/base_stream_response.py +697 -0
- mirascope/llm/responses/finish_reason.py +27 -0
- mirascope/llm/responses/response.py +345 -0
- mirascope/llm/responses/root_response.py +177 -0
- mirascope/llm/responses/stream_response.py +572 -0
- mirascope/llm/responses/streams.py +363 -0
- mirascope/llm/tools/__init__.py +40 -0
- mirascope/llm/tools/_utils.py +25 -0
- mirascope/llm/tools/decorator.py +175 -0
- mirascope/llm/tools/protocols.py +96 -0
- mirascope/llm/tools/tool_schema.py +246 -0
- mirascope/llm/tools/toolkit.py +152 -0
- mirascope/llm/tools/tools.py +169 -0
- mirascope/llm/types/__init__.py +22 -0
- mirascope/llm/types/dataclass.py +9 -0
- mirascope/llm/types/jsonable.py +44 -0
- mirascope/llm/types/type_vars.py +19 -0
- mirascope-2.0.0a0.dist-info/METADATA +117 -0
- mirascope-2.0.0a0.dist-info/RECORD +101 -0
- mirascope/beta/__init__.py +0 -3
- mirascope/beta/openai/__init__.py +0 -17
- mirascope/beta/openai/realtime/__init__.py +0 -13
- mirascope/beta/openai/realtime/_utils/__init__.py +0 -3
- mirascope/beta/openai/realtime/_utils/_audio.py +0 -74
- mirascope/beta/openai/realtime/_utils/_protocols.py +0 -50
- mirascope/beta/openai/realtime/realtime.py +0 -500
- mirascope/beta/openai/realtime/recording.py +0 -98
- mirascope/beta/openai/realtime/tool.py +0 -113
- mirascope/beta/rag/__init__.py +0 -24
- mirascope/beta/rag/base/__init__.py +0 -22
- mirascope/beta/rag/base/chunkers/__init__.py +0 -2
- mirascope/beta/rag/base/chunkers/base_chunker.py +0 -37
- mirascope/beta/rag/base/chunkers/text_chunker.py +0 -33
- mirascope/beta/rag/base/config.py +0 -8
- mirascope/beta/rag/base/document.py +0 -11
- mirascope/beta/rag/base/embedders.py +0 -35
- mirascope/beta/rag/base/embedding_params.py +0 -18
- mirascope/beta/rag/base/embedding_response.py +0 -30
- mirascope/beta/rag/base/query_results.py +0 -7
- mirascope/beta/rag/base/vectorstore_params.py +0 -18
- mirascope/beta/rag/base/vectorstores.py +0 -37
- mirascope/beta/rag/chroma/__init__.py +0 -11
- mirascope/beta/rag/chroma/types.py +0 -62
- mirascope/beta/rag/chroma/vectorstores.py +0 -121
- mirascope/beta/rag/cohere/__init__.py +0 -11
- mirascope/beta/rag/cohere/embedders.py +0 -87
- mirascope/beta/rag/cohere/embedding_params.py +0 -29
- mirascope/beta/rag/cohere/embedding_response.py +0 -29
- mirascope/beta/rag/cohere/py.typed +0 -0
- mirascope/beta/rag/openai/__init__.py +0 -11
- mirascope/beta/rag/openai/embedders.py +0 -144
- mirascope/beta/rag/openai/embedding_params.py +0 -18
- mirascope/beta/rag/openai/embedding_response.py +0 -14
- mirascope/beta/rag/openai/py.typed +0 -0
- mirascope/beta/rag/pinecone/__init__.py +0 -19
- mirascope/beta/rag/pinecone/types.py +0 -143
- mirascope/beta/rag/pinecone/vectorstores.py +0 -148
- mirascope/beta/rag/weaviate/__init__.py +0 -6
- mirascope/beta/rag/weaviate/types.py +0 -92
- mirascope/beta/rag/weaviate/vectorstores.py +0 -103
- mirascope/core/__init__.py +0 -109
- mirascope/core/anthropic/__init__.py +0 -31
- mirascope/core/anthropic/_call.py +0 -67
- mirascope/core/anthropic/_call_kwargs.py +0 -13
- mirascope/core/anthropic/_thinking.py +0 -70
- mirascope/core/anthropic/_utils/__init__.py +0 -16
- mirascope/core/anthropic/_utils/_convert_common_call_params.py +0 -25
- mirascope/core/anthropic/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -21
- mirascope/core/anthropic/_utils/_convert_message_params.py +0 -102
- mirascope/core/anthropic/_utils/_get_json_output.py +0 -31
- mirascope/core/anthropic/_utils/_handle_stream.py +0 -113
- mirascope/core/anthropic/_utils/_message_param_converter.py +0 -154
- mirascope/core/anthropic/_utils/_setup_call.py +0 -146
- mirascope/core/anthropic/call_params.py +0 -44
- mirascope/core/anthropic/call_response.py +0 -226
- mirascope/core/anthropic/call_response_chunk.py +0 -152
- mirascope/core/anthropic/dynamic_config.py +0 -40
- mirascope/core/anthropic/py.typed +0 -0
- mirascope/core/anthropic/stream.py +0 -204
- mirascope/core/anthropic/tool.py +0 -101
- mirascope/core/azure/__init__.py +0 -31
- mirascope/core/azure/_call.py +0 -67
- mirascope/core/azure/_call_kwargs.py +0 -13
- mirascope/core/azure/_utils/__init__.py +0 -14
- mirascope/core/azure/_utils/_convert_common_call_params.py +0 -26
- mirascope/core/azure/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -21
- mirascope/core/azure/_utils/_convert_message_params.py +0 -121
- mirascope/core/azure/_utils/_get_credential.py +0 -33
- mirascope/core/azure/_utils/_get_json_output.py +0 -27
- mirascope/core/azure/_utils/_handle_stream.py +0 -130
- mirascope/core/azure/_utils/_message_param_converter.py +0 -117
- mirascope/core/azure/_utils/_setup_call.py +0 -183
- mirascope/core/azure/call_params.py +0 -59
- mirascope/core/azure/call_response.py +0 -215
- mirascope/core/azure/call_response_chunk.py +0 -105
- mirascope/core/azure/dynamic_config.py +0 -30
- mirascope/core/azure/py.typed +0 -0
- mirascope/core/azure/stream.py +0 -147
- mirascope/core/azure/tool.py +0 -93
- mirascope/core/base/__init__.py +0 -86
- mirascope/core/base/_call_factory.py +0 -256
- mirascope/core/base/_create.py +0 -253
- mirascope/core/base/_extract.py +0 -175
- mirascope/core/base/_extract_with_tools.py +0 -189
- mirascope/core/base/_partial.py +0 -95
- mirascope/core/base/_utils/__init__.py +0 -92
- mirascope/core/base/_utils/_base_message_param_converter.py +0 -22
- mirascope/core/base/_utils/_base_type.py +0 -26
- mirascope/core/base/_utils/_convert_base_model_to_base_tool.py +0 -48
- mirascope/core/base/_utils/_convert_base_type_to_base_tool.py +0 -24
- mirascope/core/base/_utils/_convert_function_to_base_tool.py +0 -139
- mirascope/core/base/_utils/_convert_messages_to_message_params.py +0 -178
- mirascope/core/base/_utils/_convert_provider_finish_reason_to_finish_reason.py +0 -20
- mirascope/core/base/_utils/_default_tool_docstring.py +0 -6
- mirascope/core/base/_utils/_extract_tool_return.py +0 -42
- mirascope/core/base/_utils/_fn_is_async.py +0 -24
- mirascope/core/base/_utils/_format_template.py +0 -32
- mirascope/core/base/_utils/_get_audio_type.py +0 -18
- mirascope/core/base/_utils/_get_common_usage.py +0 -20
- mirascope/core/base/_utils/_get_create_fn_or_async_create_fn.py +0 -137
- mirascope/core/base/_utils/_get_document_type.py +0 -7
- mirascope/core/base/_utils/_get_dynamic_configuration.py +0 -69
- mirascope/core/base/_utils/_get_fields_from_call_args.py +0 -34
- mirascope/core/base/_utils/_get_fn_args.py +0 -23
- mirascope/core/base/_utils/_get_image_dimensions.py +0 -39
- mirascope/core/base/_utils/_get_image_type.py +0 -26
- mirascope/core/base/_utils/_get_metadata.py +0 -17
- mirascope/core/base/_utils/_get_possible_user_message_param.py +0 -21
- mirascope/core/base/_utils/_get_prompt_template.py +0 -28
- mirascope/core/base/_utils/_get_template_values.py +0 -51
- mirascope/core/base/_utils/_get_template_variables.py +0 -38
- mirascope/core/base/_utils/_get_unsupported_tool_config_keys.py +0 -10
- mirascope/core/base/_utils/_is_prompt_template.py +0 -24
- mirascope/core/base/_utils/_json_mode_content.py +0 -17
- mirascope/core/base/_utils/_messages_decorator.py +0 -121
- mirascope/core/base/_utils/_parse_content_template.py +0 -323
- mirascope/core/base/_utils/_parse_prompt_messages.py +0 -63
- mirascope/core/base/_utils/_pil_image_to_bytes.py +0 -13
- mirascope/core/base/_utils/_protocols.py +0 -901
- mirascope/core/base/_utils/_setup_call.py +0 -79
- mirascope/core/base/_utils/_setup_extract_tool.py +0 -30
- mirascope/core/base/call_kwargs.py +0 -13
- mirascope/core/base/call_params.py +0 -36
- mirascope/core/base/call_response.py +0 -338
- mirascope/core/base/call_response_chunk.py +0 -130
- mirascope/core/base/dynamic_config.py +0 -82
- mirascope/core/base/from_call_args.py +0 -30
- mirascope/core/base/merge_decorators.py +0 -59
- mirascope/core/base/message_param.py +0 -175
- mirascope/core/base/messages.py +0 -116
- mirascope/core/base/metadata.py +0 -13
- mirascope/core/base/prompt.py +0 -497
- mirascope/core/base/response_model_config_dict.py +0 -9
- mirascope/core/base/stream.py +0 -479
- mirascope/core/base/stream_config.py +0 -11
- mirascope/core/base/structured_stream.py +0 -296
- mirascope/core/base/tool.py +0 -214
- mirascope/core/base/toolkit.py +0 -176
- mirascope/core/base/types.py +0 -344
- mirascope/core/bedrock/__init__.py +0 -34
- mirascope/core/bedrock/_call.py +0 -68
- mirascope/core/bedrock/_call_kwargs.py +0 -12
- mirascope/core/bedrock/_types.py +0 -104
- mirascope/core/bedrock/_utils/__init__.py +0 -14
- mirascope/core/bedrock/_utils/_convert_common_call_params.py +0 -39
- mirascope/core/bedrock/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -23
- mirascope/core/bedrock/_utils/_convert_message_params.py +0 -111
- mirascope/core/bedrock/_utils/_get_json_output.py +0 -30
- mirascope/core/bedrock/_utils/_handle_stream.py +0 -104
- mirascope/core/bedrock/_utils/_message_param_converter.py +0 -172
- mirascope/core/bedrock/_utils/_setup_call.py +0 -258
- mirascope/core/bedrock/call_params.py +0 -38
- mirascope/core/bedrock/call_response.py +0 -248
- mirascope/core/bedrock/call_response_chunk.py +0 -111
- mirascope/core/bedrock/dynamic_config.py +0 -37
- mirascope/core/bedrock/py.typed +0 -0
- mirascope/core/bedrock/stream.py +0 -154
- mirascope/core/bedrock/tool.py +0 -100
- mirascope/core/cohere/__init__.py +0 -30
- mirascope/core/cohere/_call.py +0 -67
- mirascope/core/cohere/_call_kwargs.py +0 -11
- mirascope/core/cohere/_types.py +0 -20
- mirascope/core/cohere/_utils/__init__.py +0 -14
- mirascope/core/cohere/_utils/_convert_common_call_params.py +0 -26
- mirascope/core/cohere/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -24
- mirascope/core/cohere/_utils/_convert_message_params.py +0 -32
- mirascope/core/cohere/_utils/_get_json_output.py +0 -30
- mirascope/core/cohere/_utils/_handle_stream.py +0 -35
- mirascope/core/cohere/_utils/_message_param_converter.py +0 -54
- mirascope/core/cohere/_utils/_setup_call.py +0 -150
- mirascope/core/cohere/call_params.py +0 -62
- mirascope/core/cohere/call_response.py +0 -205
- mirascope/core/cohere/call_response_chunk.py +0 -125
- mirascope/core/cohere/dynamic_config.py +0 -32
- mirascope/core/cohere/py.typed +0 -0
- mirascope/core/cohere/stream.py +0 -113
- mirascope/core/cohere/tool.py +0 -93
- mirascope/core/costs/__init__.py +0 -5
- mirascope/core/costs/_anthropic_calculate_cost.py +0 -219
- mirascope/core/costs/_azure_calculate_cost.py +0 -11
- mirascope/core/costs/_bedrock_calculate_cost.py +0 -15
- mirascope/core/costs/_cohere_calculate_cost.py +0 -44
- mirascope/core/costs/_gemini_calculate_cost.py +0 -67
- mirascope/core/costs/_google_calculate_cost.py +0 -427
- mirascope/core/costs/_groq_calculate_cost.py +0 -156
- mirascope/core/costs/_litellm_calculate_cost.py +0 -11
- mirascope/core/costs/_mistral_calculate_cost.py +0 -64
- mirascope/core/costs/_openai_calculate_cost.py +0 -416
- mirascope/core/costs/_vertex_calculate_cost.py +0 -67
- mirascope/core/costs/_xai_calculate_cost.py +0 -104
- mirascope/core/costs/calculate_cost.py +0 -86
- mirascope/core/gemini/__init__.py +0 -40
- mirascope/core/gemini/_call.py +0 -67
- mirascope/core/gemini/_call_kwargs.py +0 -12
- mirascope/core/gemini/_utils/__init__.py +0 -14
- mirascope/core/gemini/_utils/_convert_common_call_params.py +0 -39
- mirascope/core/gemini/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -23
- mirascope/core/gemini/_utils/_convert_message_params.py +0 -156
- mirascope/core/gemini/_utils/_get_json_output.py +0 -35
- mirascope/core/gemini/_utils/_handle_stream.py +0 -33
- mirascope/core/gemini/_utils/_message_param_converter.py +0 -209
- mirascope/core/gemini/_utils/_setup_call.py +0 -149
- mirascope/core/gemini/call_params.py +0 -52
- mirascope/core/gemini/call_response.py +0 -216
- mirascope/core/gemini/call_response_chunk.py +0 -100
- mirascope/core/gemini/dynamic_config.py +0 -26
- mirascope/core/gemini/stream.py +0 -120
- mirascope/core/gemini/tool.py +0 -104
- mirascope/core/google/__init__.py +0 -29
- mirascope/core/google/_call.py +0 -67
- mirascope/core/google/_call_kwargs.py +0 -13
- mirascope/core/google/_utils/__init__.py +0 -14
- mirascope/core/google/_utils/_convert_common_call_params.py +0 -38
- mirascope/core/google/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -27
- mirascope/core/google/_utils/_convert_message_params.py +0 -297
- mirascope/core/google/_utils/_get_json_output.py +0 -37
- mirascope/core/google/_utils/_handle_stream.py +0 -58
- mirascope/core/google/_utils/_message_param_converter.py +0 -200
- mirascope/core/google/_utils/_setup_call.py +0 -201
- mirascope/core/google/_utils/_validate_media_type.py +0 -58
- mirascope/core/google/call_params.py +0 -22
- mirascope/core/google/call_response.py +0 -255
- mirascope/core/google/call_response_chunk.py +0 -135
- mirascope/core/google/dynamic_config.py +0 -26
- mirascope/core/google/stream.py +0 -199
- mirascope/core/google/tool.py +0 -146
- mirascope/core/groq/__init__.py +0 -30
- mirascope/core/groq/_call.py +0 -67
- mirascope/core/groq/_call_kwargs.py +0 -13
- mirascope/core/groq/_utils/__init__.py +0 -14
- mirascope/core/groq/_utils/_convert_common_call_params.py +0 -26
- mirascope/core/groq/_utils/_convert_message_params.py +0 -112
- mirascope/core/groq/_utils/_get_json_output.py +0 -27
- mirascope/core/groq/_utils/_handle_stream.py +0 -123
- mirascope/core/groq/_utils/_message_param_converter.py +0 -89
- mirascope/core/groq/_utils/_setup_call.py +0 -132
- mirascope/core/groq/call_params.py +0 -52
- mirascope/core/groq/call_response.py +0 -213
- mirascope/core/groq/call_response_chunk.py +0 -104
- mirascope/core/groq/dynamic_config.py +0 -29
- mirascope/core/groq/py.typed +0 -0
- mirascope/core/groq/stream.py +0 -135
- mirascope/core/groq/tool.py +0 -80
- mirascope/core/litellm/__init__.py +0 -28
- mirascope/core/litellm/_call.py +0 -67
- mirascope/core/litellm/_utils/__init__.py +0 -5
- mirascope/core/litellm/_utils/_setup_call.py +0 -109
- mirascope/core/litellm/call_params.py +0 -10
- mirascope/core/litellm/call_response.py +0 -24
- mirascope/core/litellm/call_response_chunk.py +0 -14
- mirascope/core/litellm/dynamic_config.py +0 -8
- mirascope/core/litellm/py.typed +0 -0
- mirascope/core/litellm/stream.py +0 -86
- mirascope/core/litellm/tool.py +0 -13
- mirascope/core/mistral/__init__.py +0 -36
- mirascope/core/mistral/_call.py +0 -65
- mirascope/core/mistral/_call_kwargs.py +0 -19
- mirascope/core/mistral/_utils/__init__.py +0 -14
- mirascope/core/mistral/_utils/_convert_common_call_params.py +0 -24
- mirascope/core/mistral/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -22
- mirascope/core/mistral/_utils/_convert_message_params.py +0 -122
- mirascope/core/mistral/_utils/_get_json_output.py +0 -34
- mirascope/core/mistral/_utils/_handle_stream.py +0 -139
- mirascope/core/mistral/_utils/_message_param_converter.py +0 -176
- mirascope/core/mistral/_utils/_setup_call.py +0 -164
- mirascope/core/mistral/call_params.py +0 -36
- mirascope/core/mistral/call_response.py +0 -205
- mirascope/core/mistral/call_response_chunk.py +0 -105
- mirascope/core/mistral/dynamic_config.py +0 -33
- mirascope/core/mistral/py.typed +0 -0
- mirascope/core/mistral/stream.py +0 -120
- mirascope/core/mistral/tool.py +0 -81
- mirascope/core/openai/__init__.py +0 -31
- mirascope/core/openai/_call.py +0 -67
- mirascope/core/openai/_call_kwargs.py +0 -13
- mirascope/core/openai/_utils/__init__.py +0 -14
- mirascope/core/openai/_utils/_convert_common_call_params.py +0 -26
- mirascope/core/openai/_utils/_convert_message_params.py +0 -148
- mirascope/core/openai/_utils/_get_json_output.py +0 -31
- mirascope/core/openai/_utils/_handle_stream.py +0 -138
- mirascope/core/openai/_utils/_message_param_converter.py +0 -105
- mirascope/core/openai/_utils/_setup_call.py +0 -155
- mirascope/core/openai/call_params.py +0 -92
- mirascope/core/openai/call_response.py +0 -273
- mirascope/core/openai/call_response_chunk.py +0 -139
- mirascope/core/openai/dynamic_config.py +0 -34
- mirascope/core/openai/py.typed +0 -0
- mirascope/core/openai/stream.py +0 -185
- mirascope/core/openai/tool.py +0 -101
- mirascope/core/py.typed +0 -0
- mirascope/core/vertex/__init__.py +0 -45
- mirascope/core/vertex/_call.py +0 -62
- mirascope/core/vertex/_call_kwargs.py +0 -12
- mirascope/core/vertex/_utils/__init__.py +0 -14
- mirascope/core/vertex/_utils/_convert_common_call_params.py +0 -37
- mirascope/core/vertex/_utils/_convert_finish_reason_to_common_finish_reasons.py +0 -23
- mirascope/core/vertex/_utils/_convert_message_params.py +0 -171
- mirascope/core/vertex/_utils/_get_json_output.py +0 -36
- mirascope/core/vertex/_utils/_handle_stream.py +0 -33
- mirascope/core/vertex/_utils/_message_param_converter.py +0 -133
- mirascope/core/vertex/_utils/_setup_call.py +0 -160
- mirascope/core/vertex/call_params.py +0 -24
- mirascope/core/vertex/call_response.py +0 -206
- mirascope/core/vertex/call_response_chunk.py +0 -99
- mirascope/core/vertex/dynamic_config.py +0 -28
- mirascope/core/vertex/stream.py +0 -119
- mirascope/core/vertex/tool.py +0 -101
- mirascope/core/xai/__init__.py +0 -28
- mirascope/core/xai/_call.py +0 -67
- mirascope/core/xai/_utils/__init__.py +0 -5
- mirascope/core/xai/_utils/_setup_call.py +0 -113
- mirascope/core/xai/call_params.py +0 -10
- mirascope/core/xai/call_response.py +0 -16
- mirascope/core/xai/call_response_chunk.py +0 -14
- mirascope/core/xai/dynamic_config.py +0 -8
- mirascope/core/xai/py.typed +0 -0
- mirascope/core/xai/stream.py +0 -57
- mirascope/core/xai/tool.py +0 -13
- mirascope/experimental/graphs/__init__.py +0 -5
- mirascope/integrations/__init__.py +0 -16
- mirascope/integrations/_middleware_factory.py +0 -403
- mirascope/integrations/langfuse/__init__.py +0 -3
- mirascope/integrations/langfuse/_utils.py +0 -114
- mirascope/integrations/langfuse/_with_langfuse.py +0 -70
- mirascope/integrations/logfire/__init__.py +0 -3
- mirascope/integrations/logfire/_utils.py +0 -225
- mirascope/integrations/logfire/_with_logfire.py +0 -63
- mirascope/integrations/otel/__init__.py +0 -10
- mirascope/integrations/otel/_utils.py +0 -270
- mirascope/integrations/otel/_with_hyperdx.py +0 -60
- mirascope/integrations/otel/_with_otel.py +0 -59
- mirascope/integrations/tenacity.py +0 -14
- mirascope/llm/_call.py +0 -401
- mirascope/llm/_context.py +0 -384
- mirascope/llm/_override.py +0 -3639
- mirascope/llm/_protocols.py +0 -500
- mirascope/llm/_response_metaclass.py +0 -31
- mirascope/llm/call_response.py +0 -158
- mirascope/llm/call_response_chunk.py +0 -66
- mirascope/llm/stream.py +0 -162
- mirascope/llm/tool.py +0 -64
- mirascope/mcp/__init__.py +0 -7
- mirascope/mcp/_utils.py +0 -288
- mirascope/mcp/client.py +0 -167
- mirascope/mcp/server.py +0 -356
- mirascope/mcp/tools.py +0 -110
- mirascope/py.typed +0 -0
- mirascope/retries/__init__.py +0 -11
- mirascope/retries/fallback.py +0 -131
- mirascope/retries/tenacity.py +0 -50
- mirascope/tools/__init__.py +0 -37
- mirascope/tools/base.py +0 -98
- mirascope/tools/system/__init__.py +0 -0
- mirascope/tools/system/_docker_operation.py +0 -166
- mirascope/tools/system/_file_system.py +0 -267
- mirascope/tools/web/__init__.py +0 -0
- mirascope/tools/web/_duckduckgo.py +0 -111
- mirascope/tools/web/_httpx.py +0 -125
- mirascope/tools/web/_parse_url_content.py +0 -94
- mirascope/tools/web/_requests.py +0 -54
- mirascope/v0/__init__.py +0 -43
- mirascope/v0/anthropic.py +0 -54
- mirascope/v0/base/__init__.py +0 -12
- mirascope/v0/base/calls.py +0 -118
- mirascope/v0/base/extractors.py +0 -122
- mirascope/v0/base/ops_utils.py +0 -207
- mirascope/v0/base/prompts.py +0 -48
- mirascope/v0/base/types.py +0 -14
- mirascope/v0/base/utils.py +0 -21
- mirascope/v0/openai.py +0 -54
- mirascope-1.25.7.dist-info/METADATA +0 -169
- mirascope-1.25.7.dist-info/RECORD +0 -378
- {mirascope-1.25.7.dist-info → mirascope-2.0.0a0.dist-info}/WHEEL +0 -0
- {mirascope-1.25.7.dist-info → mirascope-2.0.0a0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,832 @@
|
|
|
1
|
+
"""OpenAI Responses API client implementation."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
from contextvars import ContextVar
|
|
6
|
+
from functools import lru_cache
|
|
7
|
+
from typing import overload
|
|
8
|
+
from typing_extensions import Unpack
|
|
9
|
+
|
|
10
|
+
from openai import AsyncOpenAI, OpenAI
|
|
11
|
+
|
|
12
|
+
from ....context import Context, DepsT
|
|
13
|
+
from ....formatting import Format, FormattableT
|
|
14
|
+
from ....messages import Message
|
|
15
|
+
from ....responses import (
|
|
16
|
+
AsyncContextResponse,
|
|
17
|
+
AsyncContextStreamResponse,
|
|
18
|
+
AsyncResponse,
|
|
19
|
+
AsyncStreamResponse,
|
|
20
|
+
ContextResponse,
|
|
21
|
+
ContextStreamResponse,
|
|
22
|
+
Response,
|
|
23
|
+
StreamResponse,
|
|
24
|
+
)
|
|
25
|
+
from ....tools import (
|
|
26
|
+
AsyncContextTool,
|
|
27
|
+
AsyncContextToolkit,
|
|
28
|
+
AsyncTool,
|
|
29
|
+
AsyncToolkit,
|
|
30
|
+
ContextTool,
|
|
31
|
+
ContextToolkit,
|
|
32
|
+
Tool,
|
|
33
|
+
Toolkit,
|
|
34
|
+
)
|
|
35
|
+
from ...base import BaseClient, Params
|
|
36
|
+
from . import _utils
|
|
37
|
+
from .model_ids import OpenAIResponsesModelId
|
|
38
|
+
|
|
39
|
+
OPENAI_RESPONSES_CLIENT_CONTEXT: ContextVar["OpenAIResponsesClient | None"] = (
|
|
40
|
+
ContextVar("OPENAI_RESPONSES_CLIENT_CONTEXT", default=None)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@lru_cache(maxsize=256)
|
|
45
|
+
def _openai_responses_singleton(
|
|
46
|
+
api_key: str | None, base_url: str | None
|
|
47
|
+
) -> "OpenAIResponsesClient":
|
|
48
|
+
"""Return a cached `OpenAIResponsesClient` instance for the given parameters."""
|
|
49
|
+
return OpenAIResponsesClient(api_key=api_key, base_url=base_url)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def client(
|
|
53
|
+
*, api_key: str | None = None, base_url: str | None = None
|
|
54
|
+
) -> "OpenAIResponsesClient":
|
|
55
|
+
"""Return an `OpenAIResponsesClient`."""
|
|
56
|
+
api_key = api_key or os.getenv("OPENAI_API_KEY")
|
|
57
|
+
base_url = base_url or os.getenv("OPENAI_BASE_URL")
|
|
58
|
+
return _openai_responses_singleton(api_key, base_url)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_client() -> "OpenAIResponsesClient":
|
|
62
|
+
"""Get the current `OpenAIResponsesClient` from context."""
|
|
63
|
+
current_client = OPENAI_RESPONSES_CLIENT_CONTEXT.get()
|
|
64
|
+
if current_client is None:
|
|
65
|
+
current_client = client()
|
|
66
|
+
OPENAI_RESPONSES_CLIENT_CONTEXT.set(current_client)
|
|
67
|
+
return current_client
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class OpenAIResponsesClient(BaseClient[OpenAIResponsesModelId, OpenAI]):
|
|
71
|
+
"""The client for the OpenAI Responses API."""
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def _context_var(self) -> ContextVar["OpenAIResponsesClient | None"]:
|
|
75
|
+
return OPENAI_RESPONSES_CLIENT_CONTEXT
|
|
76
|
+
|
|
77
|
+
def __init__(
|
|
78
|
+
self, *, api_key: str | None = None, base_url: str | None = None
|
|
79
|
+
) -> None:
|
|
80
|
+
"""Initialize the OpenAI Responses client."""
|
|
81
|
+
self.client = OpenAI(api_key=api_key, base_url=base_url)
|
|
82
|
+
self.async_client = AsyncOpenAI(api_key=api_key, base_url=base_url)
|
|
83
|
+
|
|
84
|
+
@overload
|
|
85
|
+
def call(
|
|
86
|
+
self,
|
|
87
|
+
*,
|
|
88
|
+
model_id: OpenAIResponsesModelId,
|
|
89
|
+
messages: Sequence[Message],
|
|
90
|
+
tools: Sequence[Tool] | Toolkit | None = None,
|
|
91
|
+
format: None = None,
|
|
92
|
+
**params: Unpack[Params],
|
|
93
|
+
) -> Response:
|
|
94
|
+
"""Generate an `llm.Response` without a response format."""
|
|
95
|
+
...
|
|
96
|
+
|
|
97
|
+
@overload
|
|
98
|
+
def call(
|
|
99
|
+
self,
|
|
100
|
+
*,
|
|
101
|
+
model_id: OpenAIResponsesModelId,
|
|
102
|
+
messages: Sequence[Message],
|
|
103
|
+
tools: Sequence[Tool] | Toolkit | None = None,
|
|
104
|
+
format: type[FormattableT] | Format[FormattableT],
|
|
105
|
+
**params: Unpack[Params],
|
|
106
|
+
) -> Response[FormattableT]:
|
|
107
|
+
"""Generate an `llm.Response` with a response format."""
|
|
108
|
+
...
|
|
109
|
+
|
|
110
|
+
@overload
|
|
111
|
+
def call(
|
|
112
|
+
self,
|
|
113
|
+
*,
|
|
114
|
+
model_id: OpenAIResponsesModelId,
|
|
115
|
+
messages: Sequence[Message],
|
|
116
|
+
tools: Sequence[Tool] | Toolkit | None = None,
|
|
117
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
118
|
+
**params: Unpack[Params],
|
|
119
|
+
) -> Response | Response[FormattableT]:
|
|
120
|
+
"""Generate an `llm.Response` with optional response format."""
|
|
121
|
+
...
|
|
122
|
+
|
|
123
|
+
def call(
|
|
124
|
+
self,
|
|
125
|
+
*,
|
|
126
|
+
model_id: OpenAIResponsesModelId,
|
|
127
|
+
messages: Sequence[Message],
|
|
128
|
+
tools: Sequence[Tool] | Toolkit | None = None,
|
|
129
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
130
|
+
**params: Unpack[Params],
|
|
131
|
+
) -> Response | Response[FormattableT]:
|
|
132
|
+
"""Generate an `llm.Response` by synchronously calling the OpenAI Responses API.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
model_id: Model identifier to use.
|
|
136
|
+
messages: Messages to send to the LLM.
|
|
137
|
+
tools: Optional tools that the model may invoke.
|
|
138
|
+
format: Optional response format specifier.
|
|
139
|
+
**params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
An `llm.Response` object containing the LLM-generated content.
|
|
143
|
+
"""
|
|
144
|
+
messages, format, kwargs = _utils.encode_request(
|
|
145
|
+
model_id=model_id,
|
|
146
|
+
messages=messages,
|
|
147
|
+
tools=tools,
|
|
148
|
+
format=format,
|
|
149
|
+
params=params,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
openai_response = self.client.responses.create(**kwargs)
|
|
153
|
+
|
|
154
|
+
assistant_message, finish_reason = _utils.decode_response(
|
|
155
|
+
openai_response, model_id
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return Response(
|
|
159
|
+
raw=openai_response,
|
|
160
|
+
provider="openai:responses",
|
|
161
|
+
model_id=model_id,
|
|
162
|
+
params=params,
|
|
163
|
+
tools=tools,
|
|
164
|
+
input_messages=messages,
|
|
165
|
+
assistant_message=assistant_message,
|
|
166
|
+
finish_reason=finish_reason,
|
|
167
|
+
format=format,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
@overload
|
|
171
|
+
async def call_async(
|
|
172
|
+
self,
|
|
173
|
+
*,
|
|
174
|
+
model_id: OpenAIResponsesModelId,
|
|
175
|
+
messages: Sequence[Message],
|
|
176
|
+
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
177
|
+
format: None = None,
|
|
178
|
+
**params: Unpack[Params],
|
|
179
|
+
) -> AsyncResponse:
|
|
180
|
+
"""Generate an `llm.AsyncResponse` without a response format."""
|
|
181
|
+
...
|
|
182
|
+
|
|
183
|
+
@overload
|
|
184
|
+
async def call_async(
|
|
185
|
+
self,
|
|
186
|
+
*,
|
|
187
|
+
model_id: OpenAIResponsesModelId,
|
|
188
|
+
messages: Sequence[Message],
|
|
189
|
+
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
190
|
+
format: type[FormattableT] | Format[FormattableT],
|
|
191
|
+
**params: Unpack[Params],
|
|
192
|
+
) -> AsyncResponse[FormattableT]:
|
|
193
|
+
"""Generate an `llm.AsyncResponse` with a response format."""
|
|
194
|
+
...
|
|
195
|
+
|
|
196
|
+
@overload
|
|
197
|
+
async def call_async(
|
|
198
|
+
self,
|
|
199
|
+
*,
|
|
200
|
+
model_id: OpenAIResponsesModelId,
|
|
201
|
+
messages: Sequence[Message],
|
|
202
|
+
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
203
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
204
|
+
**params: Unpack[Params],
|
|
205
|
+
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
206
|
+
"""Generate an `llm.AsyncResponse` with optional response format."""
|
|
207
|
+
...
|
|
208
|
+
|
|
209
|
+
async def call_async(
|
|
210
|
+
self,
|
|
211
|
+
*,
|
|
212
|
+
model_id: OpenAIResponsesModelId,
|
|
213
|
+
messages: Sequence[Message],
|
|
214
|
+
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
215
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
216
|
+
**params: Unpack[Params],
|
|
217
|
+
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
218
|
+
"""Generate an `llm.AsyncResponse` by asynchronously calling the OpenAI Responses API.
|
|
219
|
+
|
|
220
|
+
Args:
|
|
221
|
+
model_id: Model identifier to use.
|
|
222
|
+
messages: Messages to send to the LLM.
|
|
223
|
+
tools: Optional tools that the model may invoke.
|
|
224
|
+
format: Optional response format specifier.
|
|
225
|
+
**params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
|
|
226
|
+
|
|
227
|
+
Returns:
|
|
228
|
+
An `llm.AsyncResponse` object containing the LLM-generated content.
|
|
229
|
+
"""
|
|
230
|
+
messages, format, kwargs = _utils.encode_request(
|
|
231
|
+
model_id=model_id,
|
|
232
|
+
messages=messages,
|
|
233
|
+
tools=tools,
|
|
234
|
+
format=format,
|
|
235
|
+
params=params,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
openai_response = await self.async_client.responses.create(**kwargs)
|
|
239
|
+
|
|
240
|
+
assistant_message, finish_reason = _utils.decode_response(
|
|
241
|
+
openai_response, model_id
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
return AsyncResponse(
|
|
245
|
+
raw=openai_response,
|
|
246
|
+
provider="openai:responses",
|
|
247
|
+
model_id=model_id,
|
|
248
|
+
params=params,
|
|
249
|
+
tools=tools,
|
|
250
|
+
input_messages=messages,
|
|
251
|
+
assistant_message=assistant_message,
|
|
252
|
+
finish_reason=finish_reason,
|
|
253
|
+
format=format,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
@overload
|
|
257
|
+
def stream(
|
|
258
|
+
self,
|
|
259
|
+
*,
|
|
260
|
+
model_id: OpenAIResponsesModelId,
|
|
261
|
+
messages: Sequence[Message],
|
|
262
|
+
tools: Sequence[Tool] | Toolkit | None = None,
|
|
263
|
+
format: None = None,
|
|
264
|
+
**params: Unpack[Params],
|
|
265
|
+
) -> StreamResponse:
|
|
266
|
+
"""Generate a `llm.StreamResponse` without a response format."""
|
|
267
|
+
...
|
|
268
|
+
|
|
269
|
+
@overload
|
|
270
|
+
def stream(
|
|
271
|
+
self,
|
|
272
|
+
*,
|
|
273
|
+
model_id: OpenAIResponsesModelId,
|
|
274
|
+
messages: Sequence[Message],
|
|
275
|
+
tools: Sequence[Tool] | Toolkit | None = None,
|
|
276
|
+
format: type[FormattableT] | Format[FormattableT],
|
|
277
|
+
**params: Unpack[Params],
|
|
278
|
+
) -> StreamResponse[FormattableT]:
|
|
279
|
+
"""Generate a `llm.StreamResponse` with a response format."""
|
|
280
|
+
...
|
|
281
|
+
|
|
282
|
+
@overload
|
|
283
|
+
def stream(
|
|
284
|
+
self,
|
|
285
|
+
*,
|
|
286
|
+
model_id: OpenAIResponsesModelId,
|
|
287
|
+
messages: Sequence[Message],
|
|
288
|
+
tools: Sequence[Tool] | Toolkit | None = None,
|
|
289
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
290
|
+
**params: Unpack[Params],
|
|
291
|
+
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
292
|
+
"""Generate a `llm.StreamResponse` with optional response format."""
|
|
293
|
+
...
|
|
294
|
+
|
|
295
|
+
def stream(
|
|
296
|
+
self,
|
|
297
|
+
*,
|
|
298
|
+
model_id: OpenAIResponsesModelId,
|
|
299
|
+
messages: Sequence[Message],
|
|
300
|
+
tools: Sequence[Tool] | Toolkit | None = None,
|
|
301
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
302
|
+
**params: Unpack[Params],
|
|
303
|
+
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
304
|
+
"""Generate a `llm.StreamResponse` by synchronously streaming from the OpenAI Responses API.
|
|
305
|
+
|
|
306
|
+
Args:
|
|
307
|
+
model_id: Model identifier to use.
|
|
308
|
+
messages: Messages to send to the LLM.
|
|
309
|
+
tools: Optional tools that the model may invoke.
|
|
310
|
+
format: Optional response format specifier.
|
|
311
|
+
**params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
|
|
312
|
+
|
|
313
|
+
Returns:
|
|
314
|
+
A `llm.StreamResponse` object containing the LLM-generated content stream.
|
|
315
|
+
"""
|
|
316
|
+
messages, format, kwargs = _utils.encode_request(
|
|
317
|
+
model_id=model_id,
|
|
318
|
+
messages=messages,
|
|
319
|
+
tools=tools,
|
|
320
|
+
format=format,
|
|
321
|
+
params=params,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
openai_stream = self.client.responses.create(
|
|
325
|
+
**kwargs,
|
|
326
|
+
stream=True,
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
chunk_iterator = _utils.decode_stream(
|
|
330
|
+
openai_stream,
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
return StreamResponse(
|
|
334
|
+
provider="openai:responses",
|
|
335
|
+
model_id=model_id,
|
|
336
|
+
params=params,
|
|
337
|
+
tools=tools,
|
|
338
|
+
input_messages=messages,
|
|
339
|
+
chunk_iterator=chunk_iterator,
|
|
340
|
+
format=format,
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
@overload
|
|
344
|
+
async def stream_async(
|
|
345
|
+
self,
|
|
346
|
+
*,
|
|
347
|
+
model_id: OpenAIResponsesModelId,
|
|
348
|
+
messages: Sequence[Message],
|
|
349
|
+
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
350
|
+
format: None = None,
|
|
351
|
+
**params: Unpack[Params],
|
|
352
|
+
) -> AsyncStreamResponse:
|
|
353
|
+
"""Generate a `llm.AsyncStreamResponse` without a response format."""
|
|
354
|
+
...
|
|
355
|
+
|
|
356
|
+
@overload
|
|
357
|
+
async def stream_async(
|
|
358
|
+
self,
|
|
359
|
+
*,
|
|
360
|
+
model_id: OpenAIResponsesModelId,
|
|
361
|
+
messages: Sequence[Message],
|
|
362
|
+
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
363
|
+
format: type[FormattableT] | Format[FormattableT],
|
|
364
|
+
**params: Unpack[Params],
|
|
365
|
+
) -> AsyncStreamResponse[FormattableT]:
|
|
366
|
+
"""Generate a `llm.AsyncStreamResponse` with a response format."""
|
|
367
|
+
...
|
|
368
|
+
|
|
369
|
+
@overload
|
|
370
|
+
async def stream_async(
|
|
371
|
+
self,
|
|
372
|
+
*,
|
|
373
|
+
model_id: OpenAIResponsesModelId,
|
|
374
|
+
messages: Sequence[Message],
|
|
375
|
+
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
376
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
377
|
+
**params: Unpack[Params],
|
|
378
|
+
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
379
|
+
"""Generate a `llm.AsyncStreamResponse` with optional response format."""
|
|
380
|
+
...
|
|
381
|
+
|
|
382
|
+
async def stream_async(
|
|
383
|
+
self,
|
|
384
|
+
*,
|
|
385
|
+
model_id: OpenAIResponsesModelId,
|
|
386
|
+
messages: Sequence[Message],
|
|
387
|
+
tools: Sequence[AsyncTool] | AsyncToolkit | None = None,
|
|
388
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
389
|
+
**params: Unpack[Params],
|
|
390
|
+
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
391
|
+
"""Generate a `llm.AsyncStreamResponse` by asynchronously streaming from the OpenAI Responses API.
|
|
392
|
+
|
|
393
|
+
Args:
|
|
394
|
+
model_id: Model identifier to use.
|
|
395
|
+
messages: Messages to send to the LLM.
|
|
396
|
+
tools: Optional tools that the model may invoke.
|
|
397
|
+
format: Optional response format specifier.
|
|
398
|
+
**params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
|
|
399
|
+
|
|
400
|
+
Returns:
|
|
401
|
+
A `llm.AsyncStreamResponse` object containing the LLM-generated content stream.
|
|
402
|
+
"""
|
|
403
|
+
messages, format, kwargs = _utils.encode_request(
|
|
404
|
+
model_id=model_id,
|
|
405
|
+
messages=messages,
|
|
406
|
+
tools=tools,
|
|
407
|
+
format=format,
|
|
408
|
+
params=params,
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
openai_stream = await self.async_client.responses.create(
|
|
412
|
+
**kwargs,
|
|
413
|
+
stream=True,
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
chunk_iterator = _utils.decode_async_stream(
|
|
417
|
+
openai_stream,
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
return AsyncStreamResponse(
|
|
421
|
+
provider="openai:responses",
|
|
422
|
+
model_id=model_id,
|
|
423
|
+
params=params,
|
|
424
|
+
tools=tools,
|
|
425
|
+
input_messages=messages,
|
|
426
|
+
chunk_iterator=chunk_iterator,
|
|
427
|
+
format=format,
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
@overload
|
|
431
|
+
def context_call(
|
|
432
|
+
self,
|
|
433
|
+
*,
|
|
434
|
+
ctx: Context[DepsT],
|
|
435
|
+
model_id: OpenAIResponsesModelId,
|
|
436
|
+
messages: Sequence[Message],
|
|
437
|
+
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
438
|
+
| ContextToolkit[DepsT]
|
|
439
|
+
| None = None,
|
|
440
|
+
format: None = None,
|
|
441
|
+
**params: Unpack[Params],
|
|
442
|
+
) -> ContextResponse[DepsT]:
|
|
443
|
+
"""Generate a `llm.ContextResponse` without a response format."""
|
|
444
|
+
...
|
|
445
|
+
|
|
446
|
+
@overload
|
|
447
|
+
def context_call(
|
|
448
|
+
self,
|
|
449
|
+
*,
|
|
450
|
+
ctx: Context[DepsT],
|
|
451
|
+
model_id: OpenAIResponsesModelId,
|
|
452
|
+
messages: Sequence[Message],
|
|
453
|
+
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
454
|
+
| ContextToolkit[DepsT]
|
|
455
|
+
| None = None,
|
|
456
|
+
format: type[FormattableT] | Format[FormattableT],
|
|
457
|
+
**params: Unpack[Params],
|
|
458
|
+
) -> ContextResponse[DepsT, FormattableT]:
|
|
459
|
+
"""Generate a `llm.ContextResponse` with a response format."""
|
|
460
|
+
...
|
|
461
|
+
|
|
462
|
+
@overload
|
|
463
|
+
def context_call(
|
|
464
|
+
self,
|
|
465
|
+
*,
|
|
466
|
+
ctx: Context[DepsT],
|
|
467
|
+
model_id: OpenAIResponsesModelId,
|
|
468
|
+
messages: Sequence[Message],
|
|
469
|
+
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
470
|
+
| ContextToolkit[DepsT]
|
|
471
|
+
| None = None,
|
|
472
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
473
|
+
**params: Unpack[Params],
|
|
474
|
+
) -> ContextResponse[DepsT] | ContextResponse[DepsT, FormattableT]:
|
|
475
|
+
"""Generate a `llm.ContextResponse` with optional response format."""
|
|
476
|
+
...
|
|
477
|
+
|
|
478
|
+
def context_call(
|
|
479
|
+
self,
|
|
480
|
+
*,
|
|
481
|
+
ctx: Context[DepsT],
|
|
482
|
+
model_id: OpenAIResponsesModelId,
|
|
483
|
+
messages: Sequence[Message],
|
|
484
|
+
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
485
|
+
| ContextToolkit[DepsT]
|
|
486
|
+
| None = None,
|
|
487
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
488
|
+
**params: Unpack[Params],
|
|
489
|
+
) -> ContextResponse[DepsT] | ContextResponse[DepsT, FormattableT]:
|
|
490
|
+
"""Generate a `llm.ContextResponse` by synchronously calling the OpenAI Responses API with context.
|
|
491
|
+
|
|
492
|
+
Args:
|
|
493
|
+
ctx: The context object containing dependencies.
|
|
494
|
+
model_id: Model identifier to use.
|
|
495
|
+
messages: Messages to send to the LLM.
|
|
496
|
+
tools: Optional tools that the model may invoke.
|
|
497
|
+
format: Optional response format specifier.
|
|
498
|
+
**params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
|
|
499
|
+
|
|
500
|
+
Returns:
|
|
501
|
+
A `llm.ContextResponse` object containing the LLM-generated content and context.
|
|
502
|
+
"""
|
|
503
|
+
messages, format, kwargs = _utils.encode_request(
|
|
504
|
+
model_id=model_id,
|
|
505
|
+
messages=messages,
|
|
506
|
+
tools=tools,
|
|
507
|
+
format=format,
|
|
508
|
+
params=params,
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
openai_response = self.client.responses.create(**kwargs)
|
|
512
|
+
|
|
513
|
+
assistant_message, finish_reason = _utils.decode_response(
|
|
514
|
+
openai_response, model_id
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
return ContextResponse(
|
|
518
|
+
raw=openai_response,
|
|
519
|
+
provider="openai:responses",
|
|
520
|
+
model_id=model_id,
|
|
521
|
+
params=params,
|
|
522
|
+
tools=tools,
|
|
523
|
+
input_messages=messages,
|
|
524
|
+
assistant_message=assistant_message,
|
|
525
|
+
finish_reason=finish_reason,
|
|
526
|
+
format=format,
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
@overload
|
|
530
|
+
async def context_call_async(
|
|
531
|
+
self,
|
|
532
|
+
*,
|
|
533
|
+
ctx: Context[DepsT],
|
|
534
|
+
model_id: OpenAIResponsesModelId,
|
|
535
|
+
messages: Sequence[Message],
|
|
536
|
+
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
537
|
+
| AsyncContextToolkit[DepsT]
|
|
538
|
+
| None = None,
|
|
539
|
+
format: None = None,
|
|
540
|
+
**params: Unpack[Params],
|
|
541
|
+
) -> AsyncContextResponse[DepsT]:
|
|
542
|
+
"""Generate a `llm.AsyncContextResponse` without a response format."""
|
|
543
|
+
...
|
|
544
|
+
|
|
545
|
+
@overload
|
|
546
|
+
async def context_call_async(
|
|
547
|
+
self,
|
|
548
|
+
*,
|
|
549
|
+
ctx: Context[DepsT],
|
|
550
|
+
model_id: OpenAIResponsesModelId,
|
|
551
|
+
messages: Sequence[Message],
|
|
552
|
+
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
553
|
+
| AsyncContextToolkit[DepsT]
|
|
554
|
+
| None = None,
|
|
555
|
+
format: type[FormattableT] | Format[FormattableT],
|
|
556
|
+
**params: Unpack[Params],
|
|
557
|
+
) -> AsyncContextResponse[DepsT, FormattableT]:
|
|
558
|
+
"""Generate a `llm.AsyncContextResponse` with a response format."""
|
|
559
|
+
...
|
|
560
|
+
|
|
561
|
+
@overload
|
|
562
|
+
async def context_call_async(
|
|
563
|
+
self,
|
|
564
|
+
*,
|
|
565
|
+
ctx: Context[DepsT],
|
|
566
|
+
model_id: OpenAIResponsesModelId,
|
|
567
|
+
messages: Sequence[Message],
|
|
568
|
+
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
569
|
+
| AsyncContextToolkit[DepsT]
|
|
570
|
+
| None = None,
|
|
571
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
572
|
+
**params: Unpack[Params],
|
|
573
|
+
) -> AsyncContextResponse[DepsT] | AsyncContextResponse[DepsT, FormattableT]:
|
|
574
|
+
"""Generate a `llm.AsyncContextResponse` with optional response format."""
|
|
575
|
+
...
|
|
576
|
+
|
|
577
|
+
async def context_call_async(
|
|
578
|
+
self,
|
|
579
|
+
*,
|
|
580
|
+
ctx: Context[DepsT],
|
|
581
|
+
model_id: OpenAIResponsesModelId,
|
|
582
|
+
messages: Sequence[Message],
|
|
583
|
+
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
584
|
+
| AsyncContextToolkit[DepsT]
|
|
585
|
+
| None = None,
|
|
586
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
587
|
+
**params: Unpack[Params],
|
|
588
|
+
) -> AsyncContextResponse[DepsT] | AsyncContextResponse[DepsT, FormattableT]:
|
|
589
|
+
"""Generate a `llm.AsyncContextResponse` by asynchronously calling the OpenAI Responses API with context.
|
|
590
|
+
|
|
591
|
+
Args:
|
|
592
|
+
ctx: The context object containing dependencies.
|
|
593
|
+
model_id: Model identifier to use.
|
|
594
|
+
messages: Messages to send to the LLM.
|
|
595
|
+
tools: Optional tools that the model may invoke.
|
|
596
|
+
format: Optional response format specifier.
|
|
597
|
+
**params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
|
|
598
|
+
|
|
599
|
+
Returns:
|
|
600
|
+
A `llm.AsyncContextResponse` object containing the LLM-generated content and context.
|
|
601
|
+
"""
|
|
602
|
+
messages, format, kwargs = _utils.encode_request(
|
|
603
|
+
model_id=model_id,
|
|
604
|
+
messages=messages,
|
|
605
|
+
tools=tools,
|
|
606
|
+
format=format,
|
|
607
|
+
params=params,
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
openai_response = await self.async_client.responses.create(**kwargs)
|
|
611
|
+
|
|
612
|
+
assistant_message, finish_reason = _utils.decode_response(
|
|
613
|
+
openai_response, model_id
|
|
614
|
+
)
|
|
615
|
+
|
|
616
|
+
return AsyncContextResponse(
|
|
617
|
+
raw=openai_response,
|
|
618
|
+
provider="openai:responses",
|
|
619
|
+
model_id=model_id,
|
|
620
|
+
params=params,
|
|
621
|
+
tools=tools,
|
|
622
|
+
input_messages=messages,
|
|
623
|
+
assistant_message=assistant_message,
|
|
624
|
+
finish_reason=finish_reason,
|
|
625
|
+
format=format,
|
|
626
|
+
)
|
|
627
|
+
|
|
628
|
+
@overload
|
|
629
|
+
def context_stream(
|
|
630
|
+
self,
|
|
631
|
+
*,
|
|
632
|
+
ctx: Context[DepsT],
|
|
633
|
+
model_id: OpenAIResponsesModelId,
|
|
634
|
+
messages: Sequence[Message],
|
|
635
|
+
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
636
|
+
| ContextToolkit[DepsT]
|
|
637
|
+
| None = None,
|
|
638
|
+
format: None = None,
|
|
639
|
+
**params: Unpack[Params],
|
|
640
|
+
) -> ContextStreamResponse[DepsT]:
|
|
641
|
+
"""Generate a `llm.ContextStreamResponse` without a response format."""
|
|
642
|
+
...
|
|
643
|
+
|
|
644
|
+
@overload
|
|
645
|
+
def context_stream(
|
|
646
|
+
self,
|
|
647
|
+
*,
|
|
648
|
+
ctx: Context[DepsT],
|
|
649
|
+
model_id: OpenAIResponsesModelId,
|
|
650
|
+
messages: Sequence[Message],
|
|
651
|
+
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
652
|
+
| ContextToolkit[DepsT]
|
|
653
|
+
| None = None,
|
|
654
|
+
format: type[FormattableT] | Format[FormattableT],
|
|
655
|
+
**params: Unpack[Params],
|
|
656
|
+
) -> ContextStreamResponse[DepsT, FormattableT]:
|
|
657
|
+
"""Generate a `llm.ContextStreamResponse` with a response format."""
|
|
658
|
+
...
|
|
659
|
+
|
|
660
|
+
@overload
|
|
661
|
+
def context_stream(
|
|
662
|
+
self,
|
|
663
|
+
*,
|
|
664
|
+
ctx: Context[DepsT],
|
|
665
|
+
model_id: OpenAIResponsesModelId,
|
|
666
|
+
messages: Sequence[Message],
|
|
667
|
+
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
668
|
+
| ContextToolkit[DepsT]
|
|
669
|
+
| None = None,
|
|
670
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
671
|
+
**params: Unpack[Params],
|
|
672
|
+
) -> ContextStreamResponse[DepsT] | ContextStreamResponse[DepsT, FormattableT]:
|
|
673
|
+
"""Generate a `llm.ContextStreamResponse` with optional response format."""
|
|
674
|
+
...
|
|
675
|
+
|
|
676
|
+
def context_stream(
|
|
677
|
+
self,
|
|
678
|
+
*,
|
|
679
|
+
ctx: Context[DepsT],
|
|
680
|
+
model_id: OpenAIResponsesModelId,
|
|
681
|
+
messages: Sequence[Message],
|
|
682
|
+
tools: Sequence[Tool | ContextTool[DepsT]]
|
|
683
|
+
| ContextToolkit[DepsT]
|
|
684
|
+
| None = None,
|
|
685
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
686
|
+
**params: Unpack[Params],
|
|
687
|
+
) -> ContextStreamResponse[DepsT] | ContextStreamResponse[DepsT, FormattableT]:
|
|
688
|
+
"""Generate a `llm.ContextStreamResponse` by synchronously streaming from the OpenAI Responses API with context.
|
|
689
|
+
|
|
690
|
+
Args:
|
|
691
|
+
ctx: The context object containing dependencies.
|
|
692
|
+
model_id: Model identifier to use.
|
|
693
|
+
messages: Messages to send to the LLM.
|
|
694
|
+
tools: Optional tools that the model may invoke.
|
|
695
|
+
format: Optional response format specifier.
|
|
696
|
+
**params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
|
|
697
|
+
|
|
698
|
+
Returns:
|
|
699
|
+
A `llm.ContextStreamResponse` object containing the LLM-generated content stream and context.
|
|
700
|
+
"""
|
|
701
|
+
messages, format, kwargs = _utils.encode_request(
|
|
702
|
+
model_id=model_id,
|
|
703
|
+
messages=messages,
|
|
704
|
+
tools=tools,
|
|
705
|
+
format=format,
|
|
706
|
+
params=params,
|
|
707
|
+
)
|
|
708
|
+
|
|
709
|
+
openai_stream = self.client.responses.create(
|
|
710
|
+
**kwargs,
|
|
711
|
+
stream=True,
|
|
712
|
+
)
|
|
713
|
+
|
|
714
|
+
chunk_iterator = _utils.decode_stream(
|
|
715
|
+
openai_stream,
|
|
716
|
+
)
|
|
717
|
+
|
|
718
|
+
return ContextStreamResponse(
|
|
719
|
+
provider="openai:responses",
|
|
720
|
+
model_id=model_id,
|
|
721
|
+
params=params,
|
|
722
|
+
tools=tools,
|
|
723
|
+
input_messages=messages,
|
|
724
|
+
chunk_iterator=chunk_iterator,
|
|
725
|
+
format=format,
|
|
726
|
+
)
|
|
727
|
+
|
|
728
|
+
@overload
|
|
729
|
+
async def context_stream_async(
|
|
730
|
+
self,
|
|
731
|
+
*,
|
|
732
|
+
ctx: Context[DepsT],
|
|
733
|
+
model_id: OpenAIResponsesModelId,
|
|
734
|
+
messages: Sequence[Message],
|
|
735
|
+
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
736
|
+
| AsyncContextToolkit[DepsT]
|
|
737
|
+
| None = None,
|
|
738
|
+
format: None = None,
|
|
739
|
+
**params: Unpack[Params],
|
|
740
|
+
) -> AsyncContextStreamResponse[DepsT]:
|
|
741
|
+
"""Generate a `llm.AsyncContextStreamResponse` without a response format."""
|
|
742
|
+
...
|
|
743
|
+
|
|
744
|
+
@overload
|
|
745
|
+
async def context_stream_async(
|
|
746
|
+
self,
|
|
747
|
+
*,
|
|
748
|
+
ctx: Context[DepsT],
|
|
749
|
+
model_id: OpenAIResponsesModelId,
|
|
750
|
+
messages: Sequence[Message],
|
|
751
|
+
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
752
|
+
| AsyncContextToolkit[DepsT]
|
|
753
|
+
| None = None,
|
|
754
|
+
format: type[FormattableT] | Format[FormattableT],
|
|
755
|
+
**params: Unpack[Params],
|
|
756
|
+
) -> AsyncContextStreamResponse[DepsT, FormattableT]:
|
|
757
|
+
"""Generate a `llm.AsyncContextStreamResponse` with a response format."""
|
|
758
|
+
...
|
|
759
|
+
|
|
760
|
+
@overload
|
|
761
|
+
async def context_stream_async(
|
|
762
|
+
self,
|
|
763
|
+
*,
|
|
764
|
+
ctx: Context[DepsT],
|
|
765
|
+
model_id: OpenAIResponsesModelId,
|
|
766
|
+
messages: Sequence[Message],
|
|
767
|
+
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
768
|
+
| AsyncContextToolkit[DepsT]
|
|
769
|
+
| None = None,
|
|
770
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
771
|
+
**params: Unpack[Params],
|
|
772
|
+
) -> (
|
|
773
|
+
AsyncContextStreamResponse[DepsT]
|
|
774
|
+
| AsyncContextStreamResponse[DepsT, FormattableT]
|
|
775
|
+
):
|
|
776
|
+
"""Generate a `llm.AsyncContextStreamResponse` with optional response format."""
|
|
777
|
+
...
|
|
778
|
+
|
|
779
|
+
async def context_stream_async(
|
|
780
|
+
self,
|
|
781
|
+
*,
|
|
782
|
+
ctx: Context[DepsT],
|
|
783
|
+
model_id: OpenAIResponsesModelId,
|
|
784
|
+
messages: Sequence[Message],
|
|
785
|
+
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]]
|
|
786
|
+
| AsyncContextToolkit[DepsT]
|
|
787
|
+
| None = None,
|
|
788
|
+
format: type[FormattableT] | Format[FormattableT] | None = None,
|
|
789
|
+
**params: Unpack[Params],
|
|
790
|
+
) -> (
|
|
791
|
+
AsyncContextStreamResponse[DepsT]
|
|
792
|
+
| AsyncContextStreamResponse[DepsT, FormattableT]
|
|
793
|
+
):
|
|
794
|
+
"""Generate a `llm.AsyncContextStreamResponse` by asynchronously streaming from the OpenAI Responses API with context.
|
|
795
|
+
|
|
796
|
+
Args:
|
|
797
|
+
ctx: The context object containing dependencies.
|
|
798
|
+
model_id: Model identifier to use.
|
|
799
|
+
messages: Messages to send to the LLM.
|
|
800
|
+
tools: Optional tools that the model may invoke.
|
|
801
|
+
format: Optional response format specifier.
|
|
802
|
+
**params: Additional parameters to configure output (e.g. temperature). See `llm.Params`.
|
|
803
|
+
|
|
804
|
+
Returns:
|
|
805
|
+
A `llm.AsyncContextStreamResponse` object containing the LLM-generated content stream and context.
|
|
806
|
+
"""
|
|
807
|
+
messages, format, kwargs = _utils.encode_request(
|
|
808
|
+
model_id=model_id,
|
|
809
|
+
messages=messages,
|
|
810
|
+
tools=tools,
|
|
811
|
+
format=format,
|
|
812
|
+
params=params,
|
|
813
|
+
)
|
|
814
|
+
|
|
815
|
+
openai_stream = await self.async_client.responses.create(
|
|
816
|
+
**kwargs,
|
|
817
|
+
stream=True,
|
|
818
|
+
)
|
|
819
|
+
|
|
820
|
+
chunk_iterator = _utils.decode_async_stream(
|
|
821
|
+
openai_stream,
|
|
822
|
+
)
|
|
823
|
+
|
|
824
|
+
return AsyncContextStreamResponse(
|
|
825
|
+
provider="openai:responses",
|
|
826
|
+
model_id=model_id,
|
|
827
|
+
params=params,
|
|
828
|
+
tools=tools,
|
|
829
|
+
input_messages=messages,
|
|
830
|
+
chunk_iterator=chunk_iterator,
|
|
831
|
+
format=format,
|
|
832
|
+
)
|