mirascope.core.gemini.call_response¶
This module contains the GeminiCallResponse
class.
Usage Documentation
GeminiCallResponse
¶
Bases: BaseCallResponse[GenerateContentResponse | AsyncGenerateContentResponse, GeminiTool, Tool, GeminiDynamicConfig, ContentsType, GeminiCallParams, ContentDict]
A convenience wrapper around the Gemini API response.
When calling the Gemini API using a function decorated with gemini_call
, the
response will be a GeminiCallResponse
instance with properties that allow for
more convenient access to commonly used attributes.
Example:
from mirascope.core import prompt_template
from mirascope.core.gemini import gemini_call
@gemini_call("gemini-1.5-flash")
def recommend_book(genre: str) -> str:
return f"Recommend a {genre} book"
response = recommend_book("fantasy") # response is an `GeminiCallResponse` instance
print(response.content)
model
property
¶
model: str
Returns the model name.
google.generativeai does not return model, so we return the model provided by the user.
id
property
¶
id: str | None
Returns the id of the response.
google.generativeai does not return an id
usage
property
¶
Returns the usage of the chat completion.
google.generativeai does not have Usage, so we return None
message_param
property
¶
Returns the models's response as a message parameter.
tools
property
¶
tools: list[GeminiTool] | None
Returns the list of tools for the 0th candidate's 0th content part.
tool
property
¶
tool: GeminiTool | None
Returns the 0th tool for the 0th candidate's 0th content part.
Raises:
Type | Description |
---|---|
ValidationError
|
if the tool call doesn't match the tool's schema. |
tool_message_params
classmethod
¶
tool_message_params(
tools_and_outputs: list[tuple[GeminiTool, object]]
) -> list[ContentDict]
Returns the tool message parameters for tool call results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tools_and_outputs |
list[tuple[GeminiTool, object]]
|
The list of tools and their outputs from which the tool message parameters should be constructed. |
required |
Returns:
Type | Description |
---|---|
list[ContentDict]
|
The list of constructed |