response
¶
CompletionResponse
¶
Bases: BaseModel
A class wrapping the response from the LLM model.
For a streaming response, it tracks the chunks of the response and builds the complete response when the streaming is finished.
chunks
class-attribute
instance-attribute
¶
chunks: List[Union[ModelResponse, ChatCompletionChunk]] = (
Field(
[],
description="The chunks of the response when streaming",
)
)
The chunks of the response when streaming.
complete_response
property
¶
complete_response: Union[ModelResponse, ChatCompletion]
The complete response from the model. This will block until the response is finished.
cost
class-attribute
instance-attribute
¶
The cost of the completion.
finish_reason
class-attribute
instance-attribute
¶
finish_reason: Optional[str] = Field(
None,
description="The reason why the completion is finished for the top-choice",
)
The reason why the completion is finished for the top-choice.
is_finished
class-attribute
instance-attribute
¶
is_finished: bool = Field(
False,
description="Whether the response stream is finished",
)
Whether the response stream is finished.
is_stream
class-attribute
instance-attribute
¶
is_stream: bool = Field(
False, description="Whether the response is a stream"
)
Whether the response is a stream.
message
class-attribute
instance-attribute
¶
The top-choice message from the completion.
num_raw_completions
class-attribute
instance-attribute
¶
num_raw_completions: int = Field(
1, description="The number of raw completions"
)
The number of raw completions.
post_finish_callbacks
class-attribute
instance-attribute
¶
The post finish callbacks.
raw_response
class-attribute
instance-attribute
¶
raw_response: Any = Field(
None, description="The raw response from the model"
)
The raw response from the model.
response_model
class-attribute
instance-attribute
¶
response_model: Any = Field(
None,
description="The BaseModel's subclass specifying the response format.",
)
The BaseModel's subclass specifying the response format.
response_obj
class-attribute
instance-attribute
¶
response_obj: Any = Field(
None,
description="The response object of response model, could be a stream",
)
The response object of response model, could be a stream.
tool_calls
class-attribute
instance-attribute
¶
The tool calls.
usage
class-attribute
instance-attribute
¶
usage: Optional[CompletionUsage] = Field(
None, description="The usage of the completion"
)
The usage of the completion.
format_stream
¶
Format the stream response as a text generator.
Source code in src/appl/core/response.py
register_post_finish_callback
¶
register_post_finish_callback(
callback: Callable,
order: Literal["first", "last"] = "last",
) -> None
Register a post finish callback.
The callback will be called after the response is finished.
Source code in src/appl/core/response.py
streaming
¶
streaming(
display: Optional[str] = None,
title: str = "APPL Streaming",
display_prefix_content: str = "",
live: Optional[Live] = None,
) -> CompletionResponse
Stream the response object and finish the response.
Source code in src/appl/core/response.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
update
¶
update(
other: CompletionResponse, split_marker: str = "\n"
) -> CompletionResponse
Update the response with the information contained in the other response.