mirascope.core.openai.call_response | Mirascope
MirascopeLilypad

mirascope.core.openai.call_response

Module call_response

This module contains the OpenAICallResponse class.

Usage

Class ChatCompletionAudio

Attributes

NameTypeDescription
datastr-
transcriptstr-

Class OpenAICallResponse

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)

Bases:

BaseCallResponse[ChatCompletion, OpenAITool, ChatCompletionToolParam, OpenAIDynamicConfig, ChatCompletionMessageParam, OpenAICallParams, ChatCompletionUserMessageParam, OpenAIMessageParamConverter]

Attributes

NameTypeDescription
responseSkipValidation[ChatCompletion]-
contentstrReturns the content of the chat completion for the 0th choice.
finish_reasonslist[str]Returns the finish reasons of the response.
modelstrReturns the name of the response model.
idstrReturns the id of the response.
usageCompletionUsage | NoneReturns the usage of the chat completion.
input_tokensint | NoneReturns the number of input tokens.
cached_tokensint | NoneReturns the number of cached tokens.
output_tokensint | NoneReturns the number of output tokens.
message_paramSerializeAsAny[ChatCompletionAssistantMessageParam]Returns the assistants's response as a message parameter.
toolslist[OpenAITool] | NoneReturns any available tool calls as their `OpenAITool` definition.
toolOpenAITool | NoneReturns the 0th tool for the 0th choice message.
audiobytes | NoneReturns the audio data of the response.
audio_transcriptstr | NoneReturns the transcript of the audio content.
common_finish_reasonslist[FinishReason] | NoneProvider-agnostic finish reasons.
common_message_paramBaseMessageParam-
common_user_message_paramBaseMessageParam | None-
cost_metadataCostMetadata-

Function tool_message_params

Returns the tool message parameters for tool call results.

Parameters

NameTypeDescription
clsAny-
tools_and_outputslist[tuple[OpenAITool, str]]The list of tools and their outputs from which the tool message parameters should be constructed.

Returns

TypeDescription
list[ChatCompletionToolMessageParam]The list of constructed `ChatCompletionToolMessageParam` parameters.