openai.types¶
Types for interacting with OpenAI models using Mirascope.
OpenAICallParams
¶
Bases: BaseCallParams[OpenAITool]
The parameters to use when calling the OpenAI API.
Source code in mirascope/openai/types.py
kwargs(tool_type=OpenAITool, exclude=None)
¶
Returns the keyword argument call parameters.
OpenAICallResponse
¶
Bases: BaseCallResponse[ChatCompletion, OpenAITool]
A convenience wrapper around the OpenAI ChatCompletion
response.
When using Mirascope's convenience wrappers to interact with OpenAI models via
OpenAICall
, responses using OpenAICall.call()
will return a
OpenAICallResponse
, whereby the implemented properties allow for simpler syntax
and a convenient developer experience.
Example:
from mirascope.openai import OpenAICall
class BookRecommender(OpenAICall):
prompt_template = "Please recommend a {genre} book"
genre: str
response = Bookrecommender(genre="fantasy").call()
print(response.content)
#> The Name of the Wind
print(response.message)
#> ChatCompletionMessage(content='The Name of the Wind', role='assistant',
# function_call=None, tool_calls=None)
print(response.choices)
#> [Choice(finish_reason='stop', index=0, logprobs=None,
# message=ChatCompletionMessage(content='The Name of the Wind', role='assistant',
# function_call=None, tool_calls=None))]
Source code in mirascope/openai/types.py
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
choice: Choice
property
¶
Returns the 0th choice.
choices: list[Choice]
property
¶
Returns the array of chat completion choices.
content: str
property
¶
Returns the content of the chat completion for the 0th choice.
input_tokens: Optional[int]
property
¶
Returns the number of input tokens.
message: ChatCompletionMessage
property
¶
Returns the message of the chat completion for the 0th choice.
output_tokens: Optional[int]
property
¶
Returns the number of output tokens.
tool: Optional[OpenAITool]
property
¶
Returns the 0th tool for the 0th choice message.
Raises:
Type | Description |
---|---|
ValidationError
|
if the tool call doesn't match the tool's schema. |
tool_calls: Optional[list[ChatCompletionMessageToolCall]]
property
¶
Returns the tool calls for the 0th choice message.
tools: Optional[list[OpenAITool]]
property
¶
Returns the tools for the 0th choice message.
Raises:
Type | Description |
---|---|
ValidationError
|
if a tool call doesn't match the tool's schema. |
usage: Optional[CompletionUsage]
property
¶
Returns the usage of the chat completion.
dump()
¶
Dumps the response to a dictionary.
OpenAICallResponseChunk
¶
Bases: BaseCallResponseChunk[ChatCompletionChunk, OpenAITool]
Convenience wrapper around chat completion streaming chunks.
When using Mirascope's convenience wrappers to interact with OpenAI models via
OpenAICall.stream
, responses will return an OpenAICallResponseChunk
, whereby
the implemented properties allow for simpler syntax and a convenient developer
experience.
Example:
from mirascope.openai import OpenAICall
class Math(OpenAICall):
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/openai/types.py
choice: ChunkChoice
property
¶
Returns the 0th choice.
choices: list[ChunkChoice]
property
¶
Returns the array of chat completion choices.
content: str
property
¶
Returns the content for the 0th choice delta.
delta: Optional[ChoiceDelta]
property
¶
Returns the delta for the 0th choice.
tool_calls: Optional[list[ChoiceDeltaToolCall]]
property
¶
Returns the partial tool calls for the 0th choice message.
The first list[ChoiceDeltaToolCall]
will contain the name of the tool and
index, and subsequent list[ChoiceDeltaToolCall]
s will contain the arguments
which will be strings that need to be concatenated with future
list[ChoiceDeltaToolCall]
s to form a complete JSON tool calls. The last
list[ChoiceDeltaToolCall]
will be None indicating end of stream.
OpenAIEmbeddingResponse
¶
Bases: BaseEmbeddingResponse[CreateEmbeddingResponse]
A convenience wrapper around the OpenAI CreateEmbeddingResponse
response.
Source code in mirascope/openai/types.py
embeddings: list[list[float]]
property
¶
Returns the raw embeddings.