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.
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.
finished_raw_response
property
¶
finished_raw_response: Union[ModelResponse, ChatCompletion]
The completed raw response from the model. This will block until the response is finished.
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.
reasoning_content
class-attribute
instance-attribute
¶
reasoning_content: Optional[str] = Field(
None,
description="The reasoning content from the completion if exists",
)
The reasoning content from the completion if exists.
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_stream() -> (
Generator[Union[str, ReasoningContent], None, None]
)
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
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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
|
update
¶
update(
other: CompletionResponse, split_marker: str = "\n"
) -> CompletionResponse
Update the response with the information contained in the other response.
Source code in src/appl/core/response.py
ReasoningContent
¶
Bases: BaseModel
The content of the reasoning.