gemini.types¶
Types for interacting with Google's Gemini models using Mirascope.
GeminiCallParams
¶
Bases: BaseCallParams[GeminiTool]
The parameters to use when calling the Gemini API calls.
Example:
from mirascope.gemini import GeminiCall, GeminiCallParams
class BookRecommendation(GeminiPrompt):
prompt_template = "Please recommend a {genre} book"
genre: str
call_params = GeminiCallParams(
model="gemini-1.0-pro-001",
generation_config={"candidate_count": 2},
)
response = BookRecommender(genre="fantasy").call()
print(response.content)
#> The Name of the Wind
Source code in mirascope/gemini/types.py
GeminiCallResponse
¶
Bases: BaseCallResponse[Union[GenerateContentResponse, AsyncGenerateContentResponse], GeminiTool]
Convenience wrapper around Gemini's GenerateContentResponse
.
When using Mirascope's convenience wrappers to interact with Gemini models via
GeminiCall
, responses using GeminiCall.call()
will return a
GeminiCallResponse
, whereby the implemented properties allow for simpler syntax
and a convenient developer experience.
Example:
from mirascope.gemini import GeminiPrompt
class BookRecommender(GeminiPrompt):
prompt_template = "Please recommend a {genre} book"
genre: str
response = BookRecommender(genre="fantasy").call()
print(response.content)
#> The Lord of the Rings
Source code in mirascope/gemini/types.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
content: str
property
¶
Returns the contained string content for the 0th choice.
input_tokens: None
property
¶
Returns the number of input tokens.
output_tokens: None
property
¶
Returns the number of output tokens.
tool: Optional[GeminiTool]
property
¶
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. |
tools: Optional[list[GeminiTool]]
property
¶
Returns the list of tools for the 0th candidate's 0th content part.
usage: None
property
¶
Returns the usage of the chat completion.
google.generativeai does not have Usage, so we return None
dump()
¶
Dumps the response to a dictionary.
GeminiCallResponseChunk
¶
Bases: BaseCallResponseChunk[GenerateContentResponse, GeminiTool]
Convenience wrapper around chat completion streaming chunks.
When using Mirascope's convenience wrappers to interact with Gemini models via
GeminiCall
, responses using GeminiCall.stream()
will return a
GeminiCallResponseChunk
, whereby the implemented properties allow for simpler
syntax and a convenient developer experience.
Example:
from mirascope.gemini import GeminiCall
class Math(GeminiCall):
prompt_template = "What is 1 + 2?"
content = ""
for chunk in Math().stream():
content += chunk.content
print(content)
#> 1
# 1 +
# 1 + 2
# 1 + 2 equals
# 1 + 2 equals
# 1 + 2 equals 3
# 1 + 2 equals 3.
Source code in mirascope/gemini/types.py
content: str
property
¶
Returns the chunk content for the 0th choice.