gen_ai_hub.proxy.native.openai.clients module¶
- gen_ai_hub.proxy.native.openai.clients.set_deployment(value)¶
Context manager to set the current deployment.
- Parameters:
value (Deployment) – The deployment to set as current.
- gen_ai_hub.proxy.native.openai.clients.get_current_deployment()¶
Get the current deployment from the context variable.
- Returns:
The current deployment.
- Return type:
- class gen_ai_hub.proxy.native.openai.clients.Embeddings(client: OpenAI)¶
Bases:
EmbeddingsA class that represents the Embeddings. It extends the Embeddings_ class and provides functionality to create embeddings based on the provided input.
- create(*, input: str | List[str] | List[int] | List[List[int]] | None, model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) Embedding¶
Creates embeddings based on the provided input and model information.
- For NVIDIA models, use extra_body to specify additional parameters:
extra_body={‘input_type’: ‘query’|’passage’}
- Parameters:
input (Union[str, List[str], List[int], List[List[int]], None]) – the input data for which embeddings are to be created.
:param model:the model to use for creating embeddings, defaults to NOT_GIVEN :type model: str | None | NotGiven, optional :param deployment_id: the ID of the deployment to use, defaults to NOT_GIVEN :type deployment_id: str | None | NotGiven, optional :param model_name: the name of the model to use, defaults to NOT_GIVEN :type model_name: str | None | NotGiven, optional :param model_version: the model version, defaults to NOT_GIVEN :type model_version: str | None | NotGiven, optional :param config_id: the ID of the config to use, defaults to NOT_GIVEN :type config_id: str | None | NotGiven, optional :param config_name: the name of the config to use, defaults to NOT_GIVEN :type config_name: str | None | NotGiven, optional :param kwargs: additional keyword arguments. :type kwargs: dict :raises ValueError: if the deployment cannot be selected or the model name is not provided. :return: the created embeddings. :rtype: Embedding
- class gen_ai_hub.proxy.native.openai.clients.AsyncEmbeddings(client: AsyncOpenAI)¶
Bases:
AsyncEmbeddingsThe AsyncEmbeddings class is a subclass of AsyncEmbeddings_. This class is used for creating embeddings asynchronously. It provides an interface for fetching embeddings of a given input from a selected deployment on a proxy client.
- async create(*, input: str | List[str] | List[int] | List[List[int]] | None, model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) Embedding¶
Asynchronously creates embeddings for the given input using a specific model.
- Parameters:
input (Union[str, List[str], List[int], List[List[int]], None]) – the input data for which embeddings are to be created.
model (str | None | NotGiven, optional) – the model to use for creating embeddings, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the ID of the deployment to use, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the name of the model to use, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the ID of the config to use, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the name of the config to use, defaults to NOT_GIVEN
- Returns:
the created embeddings.
- Return type:
Embedding
- class gen_ai_hub.proxy.native.openai.clients.Completions(client: OpenAI)¶
Bases:
Completions- The Completions class is a subclass of Completions_. It provides a way to create a completion given a prompt and
certain other configurations. It extends from the base class Completions_ and overrides the create method to cater to the specific requirements.
- create(*, prompt: str | List[str] | List[int] | List[List[int]] | None, model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) Completion | Stream[Completion]¶
This method creates a completion based on the provided parameters. It uses a proxy client to select a deployment and then calls the create method of the parent class to generate a completion.
- Parameters:
prompt (Union[str, List[str], List[int], List[List[int]], None]) – the input prompt(s) for the completion.
model (str | None | NotGiven, optional) – the model to be used for the completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment id, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration id, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name, defaults to NOT_GIVEN
- Returns:
the completion or stream of completions created based on the provided prompt.
- Return type:
Completion | Stream[Completion]
- class gen_ai_hub.proxy.native.openai.clients.AsyncCompletions(client: AsyncOpenAI)¶
Bases:
AsyncCompletions- AsyncCompletions is a subclass of AsyncCompletions_. It provides a way to create a completion given a prompt and
certain other configurations in asynchronous way. It extends from the base class Completions_ and overrides the create method to cater to the specific requirements.
- async create(*, prompt: str | List[str] | List[int] | List[List[int]] | None, model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) Completion | Stream[Completion]¶
Asynchronously creates a completion or a stream of completions based on the given prompt and other parameters.
- Parameters:
prompt (Union[str, List[str], List[int], List[List[int]], None]) – the input prompt(s) for the completion.
model (str | None | NotGiven, optional) – the model to be used for the completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment id, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration id, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name, defaults to NOT_GIVEN
- Returns:
the completion or stream of completions created based on the provided prompt.
- Return type:
Completion | Stream[Completion]
- class gen_ai_hub.proxy.native.openai.clients.Chat(client: OpenAI)¶
Bases:
ChatA class that handles chat completions, extending from the class ‘Chat_’.
- class gen_ai_hub.proxy.native.openai.clients.ChatCompletions(client: OpenAI)¶
Bases:
CompletionsA class that handles chat completions, extending from the class ‘ChatCompletions_’.
- create(*, messages: List[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam], model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) ChatCompletion¶
Creates a chat completion using the provided parameters.
- Parameters:
messages (List[ChatCompletionMessageParam]) – the list of chat completion message parameters.
model (str | None | NotGiven, optional) – the model to use for chat completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment ID to use for chat completion, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name to use for chat completion, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version to use for chat completion, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration ID to use for chat completion, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name to use for chat completion, defaults to NOT_GIVEN
- Returns:
the chat completion created with the provided parameters.
- Return type:
ChatCompletion
- parse(*, messages: Iterable[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam], model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, response_format: type[ResponseFormatT] | NotGiven = NOT_GIVEN, **kwargs) ParsedChatCompletion[TypeVar]¶
Parses chat completions using the provided parameters and returns a ParsedChatCompletion object. This method provides richer integrations with Python specific types by converting pydantic models into JSON schemas and parsing the response content back into the given model.
- Parameters:
messages (Iterable[ChatCompletionMessageParam]) – the list of chat completion message parameters.
model (str | None | NotGiven, optional) – the model to use for chat completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment ID to use for chat completion, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name to use for chat completion, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version to use for chat completion, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration ID to use for chat completion, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name to use for chat completion, defaults to NOT_GIVEN
response_format (type[ResponseFormatT] | NotGiven, optional) – the response format type for structured output, defaults to NOT_GIVEN
- Returns:
the parsed chat completion with the structured response.
- Return type:
ParsedChatCompletion[ResponseFormatT]
- static supports_temperature(model_name: str) bool¶
Checks if the given model supports the temperature parameter. Reasoning models do not support temperature e.g., o1[-mini], o3[-mini], 5[-mini, -nano], cohere–command-a-reasoning
- Parameters:
model_name (str) – the name of the model to check.
- Returns:
True if the model supports temperature, False otherwise
- Return type:
bool
- class gen_ai_hub.proxy.native.openai.clients.Responses(client: OpenAI)¶
Bases:
Responses- The Responses class is a subclass of Responses_. It provides a way to create a response for the given input and
certain other configurations. It extends from the base class Responses_ and overrides the create method to cater to the specific requirements.
- create(*, input: str | List[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | ComputerCallOutput | ResponseFunctionWebSearchParam | ResponseFunctionToolCallParam | FunctionCallOutput | ToolSearchCall | ResponseToolSearchOutputItemParamParam | AdditionalTools | ResponseReasoningItemParam | ResponseCompactionItemParamParam | ImageGenerationCall | ResponseCodeInterpreterToolCallParam | LocalShellCall | LocalShellCallOutput | ShellCall | ShellCallOutput | ApplyPatchCall | ApplyPatchCallOutput | McpListTools | McpApprovalRequest | McpApprovalResponse | McpCall | ResponseCustomToolCallOutputParam | ResponseCustomToolCallParam | CompactionTrigger | ItemReference | Program | ProgramOutput] | Omit = None, instructions: str | Omit = None, model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) Response | Stream[Annotated[ResponseAudioDeltaEvent | ResponseAudioDoneEvent | ResponseAudioTranscriptDeltaEvent | ResponseAudioTranscriptDoneEvent | ResponseCodeInterpreterCallCodeDeltaEvent | ResponseCodeInterpreterCallCodeDoneEvent | ResponseCodeInterpreterCallCompletedEvent | ResponseCodeInterpreterCallInProgressEvent | ResponseCodeInterpreterCallInterpretingEvent | ResponseCompletedEvent | ResponseContentPartAddedEvent | ResponseContentPartDoneEvent | ResponseCreatedEvent | ResponseErrorEvent | ResponseFileSearchCallCompletedEvent | ResponseFileSearchCallInProgressEvent | ResponseFileSearchCallSearchingEvent | ResponseFunctionCallArgumentsDeltaEvent | ResponseFunctionCallArgumentsDoneEvent | ResponseInProgressEvent | ResponseFailedEvent | ResponseIncompleteEvent | ResponseOutputItemAddedEvent | ResponseOutputItemDoneEvent | ResponseReasoningSummaryPartAddedEvent | ResponseReasoningSummaryPartDoneEvent | ResponseReasoningSummaryTextDeltaEvent | ResponseReasoningSummaryTextDoneEvent | ResponseReasoningTextDeltaEvent | ResponseReasoningTextDoneEvent | ResponseRefusalDeltaEvent | ResponseRefusalDoneEvent | ResponseTextDeltaEvent | ResponseTextDoneEvent | ResponseWebSearchCallCompletedEvent | ResponseWebSearchCallInProgressEvent | ResponseWebSearchCallSearchingEvent | ResponseImageGenCallCompletedEvent | ResponseImageGenCallGeneratingEvent | ResponseImageGenCallInProgressEvent | ResponseImageGenCallPartialImageEvent | ResponseMcpCallArgumentsDeltaEvent | ResponseMcpCallArgumentsDoneEvent | ResponseMcpCallCompletedEvent | ResponseMcpCallFailedEvent | ResponseMcpCallInProgressEvent | ResponseMcpListToolsCompletedEvent | ResponseMcpListToolsFailedEvent | ResponseMcpListToolsInProgressEvent | ResponseOutputTextAnnotationAddedEvent | ResponseQueuedEvent | ResponseCustomToolCallInputDeltaEvent | ResponseCustomToolCallInputDoneEvent, PropertyInfo(alias='None', format=None, format_template='None', discriminator='type')]]¶
This method creates a response based on the provided parameters. It uses a proxy client to select a deployment and then calls the create method of the parent class to generate a response.
- Parameters:
input (str | ResponseInputParam | None | NotGiven, optional) – Text, image, or file inputs to the model, used to generate a response, defaults to NOT_GIVEN
instructions (str | None | NotGiven, optional) – A system (or developer) message inserted into the model’s context, defaults to NOT_GIVEN
model (str | None | NotGiven, optional) – the model to be used for the completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment id, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration id, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name, defaults to NOT_GIVEN
- Returns:
the response or stream of responsess created based on the provided input.
- Return type:
Response | Stream[ResponseStreamEvent]:
- parse(*, input: str | List[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | ComputerCallOutput | ResponseFunctionWebSearchParam | ResponseFunctionToolCallParam | FunctionCallOutput | ToolSearchCall | ResponseToolSearchOutputItemParamParam | AdditionalTools | ResponseReasoningItemParam | ResponseCompactionItemParamParam | ImageGenerationCall | ResponseCodeInterpreterToolCallParam | LocalShellCall | LocalShellCallOutput | ShellCall | ShellCallOutput | ApplyPatchCall | ApplyPatchCallOutput | McpListTools | McpApprovalRequest | McpApprovalResponse | McpCall | ResponseCustomToolCallOutputParam | ResponseCustomToolCallParam | CompactionTrigger | ItemReference | Program | ProgramOutput] | Omit = None, instructions: str | Omit = None, model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) ParsedResponse[TypeVar]¶
Parses responses using the provided parameters and returns a ParsedResponse object. This method provides richer integrations with Python specific types by converting pydantic models into JSON schemas and parsing the response content back into the given model
- Parameters:
input (str | ResponseInputParam | None | NotGiven, optional) – Text, image, or file inputs to the model, used to generate a response, defaults to NOT_GIVEN
instructions (str | None | NotGiven, optional) – A system (or developer) message inserted into the model’s context, defaults to NOT_GIVEN
model (str | None | NotGiven, optional) – the model to be used for the completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment id, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration id, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name, defaults to NOT_GIVEN
- Returns:
ParsedResponse object
- Return type:
ParsedResponse
- static supports_temperature(model_name: str) bool¶
Checks if the given model supports the temperature parameter. Reasoning models do not support temperature e.g., o1[-mini], o3[-mini], 5[-mini, -nano], cohere–command-a-reasoning
- Parameters:
model_name (str) – the name of the model to check.
- Returns:
True if the model supports temperature, False otherwise
- Return type:
bool
- class gen_ai_hub.proxy.native.openai.clients.AsyncChat(client: OpenAI)¶
Bases:
AsyncChatA class that handles asynchronous chat completions, extending from the class ‘AsyncChat_’.
- class gen_ai_hub.proxy.native.openai.clients.AsyncChatCompletions(client: AsyncOpenAI)¶
Bases:
AsyncCompletionsThe AsyncChatCompletions class is a derived class which extends AsyncChatCompletions_. This class is used to handle asynchronous chat completion requests. It provides methods to create and manage chat completions in an asynchronous manner.
- async create(*, messages: List[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam], model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) ChatCompletion¶
Asynchronously creates a new chat completion.
- Parameters:
messages (List[ChatCompletionMessageParam]) – the list of chat completion message parameters.
model (str | None | NotGiven, optional) – the model to be used, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment id, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration id, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name, defaults to NOT_GIVEN
- Returns:
the created chat completion.
- Return type:
ChatCompletion
- async parse(*, messages: Iterable[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam], model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, response_format: type[ResponseFormatT] | NotGiven = NOT_GIVEN, **kwargs) ParsedChatCompletion[TypeVar]¶
Asynchronously parses chat completions using the provided parameters and returns a ParsedChatCompletion object. This method provides richer integrations with Python specific types by converting pydantic models into JSON schemas and parsing the response content back into the given model.
- Parameters:
messages (Iterable[ChatCompletionMessageParam]) – the list of chat completion message parameters.
model (str | None | NotGiven, optional) – the model to use for chat completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment ID to use for chat completion, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name to use for chat completion, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version to use for chat completion, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration ID to use for chat completion, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name to use for chat completion, defaults to NOT_GIVEN
response_format (type[ResponseFormatT] | NotGiven, optional) – the response format type for structured output, defaults to NOT_GIVEN
- Returns:
the parsed chat completion with the structured response.
- Return type:
ParsedChatCompletion[ResponseFormatT]
- static supports_temperature(model_name: str) bool¶
Checks if the given model supports the temperature parameter. Reasoning models do not support temperature e.g., o1[-mini], o3[-mini], cohere–command-a-reasoning
- Parameters:
model_name (str) – the name of the model to check.
- Returns:
True if the model supports temperature, False otherwise
- Return type:
bool
- class gen_ai_hub.proxy.native.openai.clients.AsyncResponses(client: AsyncOpenAI)¶
Bases:
AsyncResponsesThe asynch Responses class is a subclass of AsyncResponses_. It provides a way to create a response for the given input and certain other configurations. It extends from the base class AsyncResponses_ and overrides the create method to cater to the specific requirements.
- async create(*, input: str | List[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | ComputerCallOutput | ResponseFunctionWebSearchParam | ResponseFunctionToolCallParam | FunctionCallOutput | ToolSearchCall | ResponseToolSearchOutputItemParamParam | AdditionalTools | ResponseReasoningItemParam | ResponseCompactionItemParamParam | ImageGenerationCall | ResponseCodeInterpreterToolCallParam | LocalShellCall | LocalShellCallOutput | ShellCall | ShellCallOutput | ApplyPatchCall | ApplyPatchCallOutput | McpListTools | McpApprovalRequest | McpApprovalResponse | McpCall | ResponseCustomToolCallOutputParam | ResponseCustomToolCallParam | CompactionTrigger | ItemReference | Program | ProgramOutput] | Omit = None, instructions: str | Omit = None, model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) Response | AsyncStream[Annotated[ResponseAudioDeltaEvent | ResponseAudioDoneEvent | ResponseAudioTranscriptDeltaEvent | ResponseAudioTranscriptDoneEvent | ResponseCodeInterpreterCallCodeDeltaEvent | ResponseCodeInterpreterCallCodeDoneEvent | ResponseCodeInterpreterCallCompletedEvent | ResponseCodeInterpreterCallInProgressEvent | ResponseCodeInterpreterCallInterpretingEvent | ResponseCompletedEvent | ResponseContentPartAddedEvent | ResponseContentPartDoneEvent | ResponseCreatedEvent | ResponseErrorEvent | ResponseFileSearchCallCompletedEvent | ResponseFileSearchCallInProgressEvent | ResponseFileSearchCallSearchingEvent | ResponseFunctionCallArgumentsDeltaEvent | ResponseFunctionCallArgumentsDoneEvent | ResponseInProgressEvent | ResponseFailedEvent | ResponseIncompleteEvent | ResponseOutputItemAddedEvent | ResponseOutputItemDoneEvent | ResponseReasoningSummaryPartAddedEvent | ResponseReasoningSummaryPartDoneEvent | ResponseReasoningSummaryTextDeltaEvent | ResponseReasoningSummaryTextDoneEvent | ResponseReasoningTextDeltaEvent | ResponseReasoningTextDoneEvent | ResponseRefusalDeltaEvent | ResponseRefusalDoneEvent | ResponseTextDeltaEvent | ResponseTextDoneEvent | ResponseWebSearchCallCompletedEvent | ResponseWebSearchCallInProgressEvent | ResponseWebSearchCallSearchingEvent | ResponseImageGenCallCompletedEvent | ResponseImageGenCallGeneratingEvent | ResponseImageGenCallInProgressEvent | ResponseImageGenCallPartialImageEvent | ResponseMcpCallArgumentsDeltaEvent | ResponseMcpCallArgumentsDoneEvent | ResponseMcpCallCompletedEvent | ResponseMcpCallFailedEvent | ResponseMcpCallInProgressEvent | ResponseMcpListToolsCompletedEvent | ResponseMcpListToolsFailedEvent | ResponseMcpListToolsInProgressEvent | ResponseOutputTextAnnotationAddedEvent | ResponseQueuedEvent | ResponseCustomToolCallInputDeltaEvent | ResponseCustomToolCallInputDoneEvent, PropertyInfo(alias='None', format=None, format_template='None', discriminator='type')]]¶
Async method that creates a response based on the provided parameters. It uses a proxy client to select a deployment and then calls the create method of the parent class to generate a response.
- Parameters:
input (str | ResponseInputParam | None | NotGiven, optional) – Text, image, or file inputs to the model, used to generate a response, defaults to NOT_GIVEN
instructions (str | None | NotGiven, optional) – A system (or developer) message inserted into the model’s context, defaults to NOT_GIVEN
model (str | None | NotGiven, optional) – the model to be used for the completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment id, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration id, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name, defaults to NOT_GIVEN
- Returns:
the response or stream of responsess created based on the provided input.
- Return type:
Response | AsyncStream[ResponseStreamEvent]:
- async parse(*, input: str | List[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | ComputerCallOutput | ResponseFunctionWebSearchParam | ResponseFunctionToolCallParam | FunctionCallOutput | ToolSearchCall | ResponseToolSearchOutputItemParamParam | AdditionalTools | ResponseReasoningItemParam | ResponseCompactionItemParamParam | ImageGenerationCall | ResponseCodeInterpreterToolCallParam | LocalShellCall | LocalShellCallOutput | ShellCall | ShellCallOutput | ApplyPatchCall | ApplyPatchCallOutput | McpListTools | McpApprovalRequest | McpApprovalResponse | McpCall | ResponseCustomToolCallOutputParam | ResponseCustomToolCallParam | CompactionTrigger | ItemReference | Program | ProgramOutput] | Omit = None, instructions: str | Omit = None, model: str | None | NotGiven = NOT_GIVEN, deployment_id: str | None | NotGiven = NOT_GIVEN, model_name: str | None | NotGiven = NOT_GIVEN, model_version: str | None | NotGiven = NOT_GIVEN, config_id: str | None | NotGiven = NOT_GIVEN, config_name: str | None | NotGiven = NOT_GIVEN, **kwargs) ParsedResponse[TypeVar]¶
Async parses responses using the provided parameters and returns a ParsedResponse object. This method provides richer integrations with Python specific types by converting pydantic models into JSON schemas and parsing the response content back into the given model
- Parameters:
input (str | ResponseInputParam | None | NotGiven, optional) – Text, image, or file inputs to the model, used to generate a response, defaults to NOT_GIVEN
instructions (str | None | NotGiven, optional) – A system (or developer) message inserted into the model’s context, defaults to NOT_GIVEN
model (str | None | NotGiven, optional) – the model to be used for the completion, defaults to NOT_GIVEN
deployment_id (str | None | NotGiven, optional) – the deployment id, defaults to NOT_GIVEN
model_name (str | None | NotGiven, optional) – the model name, defaults to NOT_GIVEN
model_version (str | None | NotGiven, optional) – the model version, defaults to NOT_GIVEN
config_id (str | None | NotGiven, optional) – the configuration id, defaults to NOT_GIVEN
config_name (str | None | NotGiven, optional) – the configuration name, defaults to NOT_GIVEN
- Returns:
ParsedResponse object
- Return type:
ParsedResponse
- static supports_temperature(model_name: str) bool¶
Checks if the given model supports the temperature parameter. Reasoning models do not support temperature e.g., o1[-mini], o3[-mini], 5[-mini, -nano], cohere–command-a-reasoning
- Parameters:
model_name (str) – the name of the model to check.
- Returns:
True if the model supports temperature, False otherwise
- Return type:
bool
- class gen_ai_hub.proxy.native.openai.clients.OpenAIWithRawResponse(client: OpenAI)¶
Bases:
objectThis class is a wrapper for the OpenAI API client that provides raw responses. Note: The properties ‘edits’, ‘files’, ‘images’, ‘audio’, ‘moderations’, ‘models’, ‘fine_tuning’, ‘fine_tunes’ and ‘beta’ are placeholders and currently do not provide any functionality.
- completions¶
An instance of CompletionsWithRawResponse class.
- chat¶
An instance of ChatWithRawResponse class.
- edits¶
Not currently used.
- embeddings¶
An instance of EmbeddingsWithRawResponse class if client.embeddings is not None.
- files¶
Not currently used.
- images¶
Not currently used.
- audio¶
Not currently used.
- moderations¶
Not currently used.
- models¶
Not currently used.
- fine_tuning¶
Not currently used.
- fine_tunes¶
Not currently used.
- beta¶
Not currently used.
The class is designed to provide the raw responses from OpenAI’s API endpoints. It currently supports completions, chat, and embeddings endpoints.
- class gen_ai_hub.proxy.native.openai.clients.AsyncOpenAIWithRawResponse(client: AsyncOpenAI)¶
Bases:
objectA class that provides an asynchronous interface to the OpenAI API, returning raw responses.
This class wraps the core functionality of OpenAI’s API, offering access to completions, chat capabilities, and embeddings. It is designed to work with OpenAI’s asynchronous client, allowing for concurrent requests to the API.
Note: The properties ‘edits’, ‘files’, ‘images’, ‘audio’, ‘moderations’, ‘models’, ‘fine_tuning’, ‘fine_tunes’ and ‘beta’ are placeholders and currently do not provide any functionality.
- completions¶
An instance of resources.AsyncCompletionsWithRawResponse for managing completions with the API.
- chat¶
An instance of resources.AsyncChatWithRawResponse for managing chat with the API.
- embeddings¶
An instance of resources.AsyncEmbeddingsWithRawResponse for managing embeddings with the API.
- edits¶
Currently a placeholder with no functionality.
- files¶
Currently a placeholder with no functionality.
- images¶
Currently a placeholder with no functionality.
- audio¶
Currently a placeholder with no functionality.
- moderations¶
Currently a placeholder with no functionality.
- models¶
Currently a placeholder with no functionality.
- fine_tuning¶
Currently a placeholder with no functionality.
- fine_tunes¶
Currently a placeholder with no functionality.
- beta¶
Currently a placeholder with no functionality.
- __init__(client: AsyncOpenAI) None¶
Initializes the AsyncOpenAIWithRawResponse class with the provided AsyncOpenAI client.
- Parameters:
client (AsyncOpenAI) – An instance of AsyncOpenAI client.
- class gen_ai_hub.proxy.native.openai.clients.OpenAI(*, proxy_client: BaseProxyClient | None = None, api_version: str | None = '2025-03-01-preview', **kwargs)¶
Bases:
OpenAI- This is a class for the OpenAI API client. It is designed to handle various services provided by OpenAI such as text
completions, chat, embeddings etc.
- proxy_client¶
An instance of a Proxy Client. Defaults to None.
- Type:
BaseProxyClient, optional
- api_version¶
API version used for OpenAI API calls. Defaults to DEFAULT_API_VERSION.
- Type:
str, optional
- completions¶
An instance of the Completions class for text generation.
- Type:
- edits¶
Placeholder for future use. Currently set to None.
- embeddings¶
An instance of the Embeddings class for getting text embeddings.
- Type:
- files¶
Placeholder for future use. Currently set to None.
- images¶
Placeholder for future use. Currently set to None.
- audio¶
Placeholder for future use. Currently set to None.
- moderations¶
Placeholder for future use. Currently set to None.
- models¶
Placeholder for future use. Currently set to None.
- fine_tuning¶
Placeholder for future use. Currently set to None.
- fine_tunes¶
Placeholder for future use. Currently set to None.
- beta¶
Placeholder for future use. Currently set to None.
- with_raw_response¶
An instance of the OpenAIWithRawResponse class for returning raw
- Type:
- responses from the API.
- __init__(*, proxy_client: BaseProxyClient | None = None, api_version: str | None = '2025-03-01-preview', **kwargs) None¶
Initializes the OpenAI API client with the provided parameters.
- Parameters:
proxy_client (Optional[BaseProxyClient], optional) – An instance of a Proxy Client. Defaults to None.
api_version (Optional[str], optional) – API version used for OpenAI API calls. Defaults to DEFAULT_API_VERSION.
- property default_headers: dict[str, str | Omit]¶
- request(cast_to, options, *args, **kwargs)¶
- class gen_ai_hub.proxy.native.openai.clients.AsyncOpenAI(*, proxy_client: BaseProxyClient | None = None, api_version: str | None = '2025-03-01-preview', **kwargs)¶
Bases:
AsyncOpenAIAn async version of the OpenAI API client.
This class is used to interact with the OpenAI API asynchronously. It supports various operations like creating completions, generating chat messages, and getting embeddings.
- proxy_client¶
A proxy client to make API requests. If not provided, a default one will be
- Type:
- created.
- api_version¶
The version of the OpenAI API to use. Default is defined by DEFAULT_API_VERSION.
- Type:
str, optional
- completions¶
A client for interacting with the OpenAI API’s completions.
- Type:
- edits¶
Placeholder for future support of “edits” operations.
- Type:
None
- embeddings¶
A client for interacting with the OpenAI API’s embeddings.
- Type:
- files¶
Placeholder for future support of “files” operations.
- Type:
None
- images¶
Placeholder for future support of “images” operations.
- Type:
None
- audio¶
Placeholder for future support of “audio” operations.
- Type:
None
- moderations¶
Placeholder for future support of “moderations” operations.
- Type:
None
- models¶
Placeholder for future support of “models” operations.
- Type:
None
- fine_tuning¶
Placeholder for future support of “fine_tuning” operations.
- Type:
None
- fine_tunes¶
Placeholder for future support of “fine_tunes” operations.
- Type:
None
- beta¶
Placeholder for future support of “beta” operations.
- Type:
None
- with_raw_response¶
A client that returns raw API responses.
- __init__(*, proxy_client: BaseProxyClient | None = None, api_version: str | None = '2025-03-01-preview', **kwargs) None¶
Initializes the AsyncOpenAI client with the provided parameters.
- Parameters:
proxy_client (Optional[BaseProxyClient], optional) – An instance of a Proxy Client. Defaults to None.
api_version (Optional[str], optional) – API version used for OpenAI API calls. Defaults to DEFAULT_API_VERSION.
- property default_headers: dict[str, str | Omit]¶
- request(cast_to, options, *args, **kwargs)¶
Overrides the request method to include additional request body kwargs from the current deployment.
- Parameters:
cast_to (any) – the type to cast the response to.
options (any) – the request options.
- Returns:
the response from the request.
- Return type:
CoroutineType[Any, Any, ResponseT@request]