mirascope.core.openai.call_response¶
This module contains the OpenAICallResponse
class.
Usage Documentation
OpenAICallResponse
¶
Bases: BaseCallResponse[ChatCompletion, OpenAITool, ChatCompletionToolParam, OpenAIDynamicConfig, ChatCompletionMessageParam, OpenAICallParams, ChatCompletionUserMessageParam]
A convenience wrapper around the OpenAI ChatCompletion
response.
When calling the OpenAI API using a function decorated with openai_call
, the
response will be an OpenAICallResponse
instance with properties that allow for
more convenience access to commonly used attributes.
Example:
from mirascope.core import prompt_template
from mirascope.core.openai import openai_call
@openai_call("gpt-4o")
def recommend_book(genre: str) -> str:
return f"Recommend a {genre} book"
response = recommend_book("fantasy") # response is an `OpenAICallResponse` instance
print(response.content)
message_param
property
¶
Returns the assistants's response as a message parameter.
tools
property
¶
tools: list[OpenAITool] | None
Returns any available tool calls as their OpenAITool
definition.
Raises:
Type | Description |
---|---|
ValidationError
|
if a tool call doesn't match the tool's schema. |
ValueError
|
if the model refused to response, in which case the error message will be the refusal. |
tool
property
¶
tool: OpenAITool | None
Returns the 0th tool for the 0th choice message.
Raises:
Type | Description |
---|---|
ValidationError
|
if the tool call doesn't match the tool's schema. |
ValueError
|
if the model refused to response, in which case the error message will be the refusal. |
audio_transcript
property
¶
audio_transcript: str | None
Returns the transcript of the audio content.
tool_message_params
classmethod
¶
tool_message_params(
tools_and_outputs: list[tuple[OpenAITool, str]]
) -> list[ChatCompletionToolMessageParam]
Returns the tool message parameters for tool call results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tools_and_outputs |
list[tuple[OpenAITool, str]]
|
The list of tools and their outputs from which the tool message parameters should be constructed. |
required |
Returns:
Type | Description |
---|---|
list[ChatCompletionToolMessageParam]
|
The list of constructed |