Msg types
labridge.agent.chat_msg.msg_types
¶
labridge.agent.chat_msg.msg_types.AgentResponse
¶
Bases: BaseModel
The response of chat agent.
response (str): The response string. references (Optional[List[str]]): The paths of reference files.
Source code in labridge\agent\chat_msg\msg_types.py
164 165 166 167 168 169 170 171 172 |
|
labridge.agent.chat_msg.msg_types.BaseClientMessage
¶
Bases: BaseModel
This is the base class for client's messages.
user_id (str): The user id of a Lab member. reply_in_speech (bool): If True, the agent will reply in speech. enable_instruct (bool): If True, enable the user to intervene into the agent's reasoning phase. enable_comment (bool): If True: enable the user to intervene into the agent's acting phase.
Source code in labridge\agent\chat_msg\msg_types.py
32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer
¶
Bases: object
This class includes buffers that manager the messages from users and the agent's corresponding reply.
Before a chat, the user's messages will put into the user_msg_buffer
.
When the agent get a user's messages, these messages will be packed and used as input to Call Chat()
.
Additionally, During the execution of Chat()
, the agent is able to get new messages from the buffer, such as
when collecting information from the user in some tools.
The response of the agent will be put into the agent_reply_buffer
, similarly, the user may receive an 'inner'
response from the buffer.
Depending on the user's choice reply_in_speech
, the agent's response will be sent back to the user directly or
transformed to speech before that.
Source code in labridge\agent\chat_msg\msg_types.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.clear_user_msg(user_id)
¶
Clear a user's messages in the buffer.
PARAMETER | DESCRIPTION |
---|---|
user_id |
The user id of a Lab member.
TYPE:
|
Source code in labridge\agent\chat_msg\msg_types.py
370 371 372 373 374 375 376 377 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.default_agent_speech_path(user_id)
¶
Default save path of agent's speech.
Source code in labridge\agent\chat_msg\msg_types.py
462 463 464 465 466 467 468 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.default_tmp_file_path(user_id, file_name)
¶
Default save path of the user's uploaded file.
Source code in labridge\agent\chat_msg\msg_types.py
470 471 472 473 474 475 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.default_user_speech_path(user_id, speech_suffix)
¶
Default save path of a user's speech.
Source code in labridge\agent\chat_msg\msg_types.py
449 450 451 452 453 454 455 456 457 458 459 460 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.get_agent_reply(user_id)
¶
Get the agent reply to a user from the buffer.
PARAMETER | DESCRIPTION |
---|---|
user_id |
The user id of a Lab member.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[ServerReply, ServerSpeechReply]
|
Union[ServerReply, ServerSpeechReply]: If an agent's reply exists, return a valid reply, otherwise, return an invalid reply. |
Source code in labridge\agent\chat_msg\msg_types.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.get_user_msg(user_id, timeout=240)
async
¶
Wait until a user's messages are put into the buffer, and get them.
PARAMETER | DESCRIPTION |
---|---|
user_id |
The user id of a Lab member.
TYPE:
|
timeout |
If timeout, return None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[PackedUserMessage]
|
Optional[PackedUserMessage]: The obtained packed user messages. If no user messages if put in until time is out, return None. |
Source code in labridge\agent\chat_msg\msg_types.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.put_agent_reply(user_id, reply_str, references=None, inner_chat=False, extra_info=None)
¶
Put an agent's reply into the buffer.
PARAMETER | DESCRIPTION |
---|---|
user_id |
The user id of a Lab member.
TYPE:
|
reply_str |
The agent's reply string.
TYPE:
|
references |
The dumped string of reference info dict. Defaults to None.
The
TYPE:
|
inner_chat |
Whether the reply happens inside a chat.
TYPE:
|
extra_info |
extra information generally with long texts.
TYPE:
|
Source code in labridge\agent\chat_msg\msg_types.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.put_user_msg(user_msg)
¶
Put a new user message into the buffer.
PARAMETER | DESCRIPTION |
---|---|
user_msg |
A new message from a user.
TYPE:
|
Source code in labridge\agent\chat_msg\msg_types.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.reset_buffer()
¶
Reset the user_msg_buffer and agent_reply_buffer.
RETURNS | DESCRIPTION |
---|---|
None |
Source code in labridge\agent\chat_msg\msg_types.py
343 344 345 346 347 348 349 350 351 352 353 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.test_get_user_text(user_id, enable_instruct=False, enable_comment=False)
¶
For debug.
Source code in labridge\agent\chat_msg\msg_types.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|
labridge.agent.chat_msg.msg_types.ChatMsgBuffer.update_buffer_for_new_users()
¶
When new users are registered, update the buffer.
RETURNS | DESCRIPTION |
---|---|
None |
Source code in labridge\agent\chat_msg\msg_types.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
labridge.agent.chat_msg.msg_types.ChatSpeechMessage
¶
Bases: BaseClientMessage
This message includes:
- Basic: user_id.
- The save path of user's speech file data.
This message is used in the websocket_chat_speech
.
Source code in labridge\agent\chat_msg\msg_types.py
100 101 102 103 104 105 106 107 108 109 110 |
|
labridge.agent.chat_msg.msg_types.ChatTextMessage
¶
Bases: BaseClientMessage
This message includes:
- Basic: user_id.
- The user's query.
This message is used in the websocket_chat_text
.
Source code in labridge\agent\chat_msg\msg_types.py
87 88 89 90 91 92 93 94 95 96 97 |
|
labridge.agent.chat_msg.msg_types.FileWithTextMessage
¶
Bases: BaseClientMessage
This message includes:
- Basic: user_id
- The info of the file to be uploaded.
- The attached user's query.
- Whether to reply in speech or not.
This message is used in the websocket_chat_with_file
.
Source code in labridge\agent\chat_msg\msg_types.py
47 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 |
|
labridge.agent.chat_msg.msg_types.FileWithTextMessage.dumps()
¶
The formatted string that the client sends to the server for uploading request, including the file info and the attached text.
Source code in labridge\agent\chat_msg\msg_types.py
62 63 64 65 66 67 68 69 70 71 72 |
|
labridge.agent.chat_msg.msg_types.PackedUserMessage
¶
Pack the user messages.
user_id (str): The user id of a Lab member. system_msg (str): The corresponding system message. user_msg (str): The packed user messages. reply_in_speech (bool): Whether the agent should reply in speech or not chat_group_id (Optional[str]): The ID of a chat group (If the messages are from a chat group). Defaults to None.
Source code in labridge\agent\chat_msg\msg_types.py
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 |
|
labridge.agent.chat_msg.msg_types.PackedUserMessage.loads(dumped_str)
classmethod
¶
Load from a dumped JSON string.
PARAMETER | DESCRIPTION |
---|---|
dumped_str |
The dumped JSON string.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
PackedUserMessage |
Source code in labridge\agent\chat_msg\msg_types.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
labridge.agent.chat_msg.msg_types.ServerReply
¶
Bases: BaseModel
The server's text reply.
reply_text (str): The reply text.
valid (bool): Whether this reply contains valid information.
references (Optional[List[dict]]): The infos of reference files.
error (Optional[str]): The error information. If no error, it is None.
inner_chat (Optional[bool]): Whether the reply is produced inside the Chat Call.
- If this reply is the final response of the agent, it is False.
- If this reply is an internal response such as collecting information from the user or getting authorization,
it is True. When inner_chat
is True, the client should post the user's answer to corresponding URL with flag Inner
.
Source code in labridge\agent\chat_msg\msg_types.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
labridge.agent.chat_msg.msg_types.ServerSpeechReply
¶
Bases: BaseModel
The server's speech reply.
reply_speech (Dict[str, int]): The path of the agent's speech file.
valid (bool): Whether the reply contains valid information. When receiving an invalid reply,
the client should continue to get the server's reply until get a valid reply.
references (Optional[List[dict]]): The paths of reference files.
inner_chat (Optional[bool]): Whether the reply is produced inside the Chat Call.
- If this reply is the final response of the agent, it is False.
- If this reply is an internal response such as collecting information from the user or getting authorization,
it is True. When inner_chat
is True, the client should post the user's answer to corresponding URL with flag Inner
.
Source code in labridge\agent\chat_msg\msg_types.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
labridge.agent.chat_msg.msg_types.UserMsgFormatter
¶
Bases: object
This class transform the user's messages into specific formats and generate corresponding system messages.
Source code in labridge\agent\chat_msg\msg_types.py
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 |
|
labridge.agent.chat_msg.msg_types.UserMsgFormatter.formatted_msgs(msgs)
¶
Turn into formatted text message.
PARAMETER | DESCRIPTION |
---|---|
msgs |
The user's messages.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
PackedUserMessage
|
The packed user messages, and system message.
TYPE:
|
Source code in labridge\agent\chat_msg\msg_types.py
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 |
|