Conversations
Conversation
Bases: BaseModel
Pydantic model for returning a conversation as a response.
Attributes:
| Name | Type | Description |
|---|---|---|
conversation_id |
int
|
Unique identifier for the conversation. |
tenant_id |
int
|
The ID of the tenant or organization that owns the conversation. |
user_id |
int
|
The ID of the user who created the conversation. |
name |
Optional[str]
|
The name of the conversation. |
summary |
Optional[str]
|
A brief summary or description of the conversation. |
created_at |
Optional[datetime]
|
The timestamp when the conversation was created. |
modified_at |
Optional[datetime]
|
The timestamp when the conversation was last modified. |
created_by |
Optional[str]
|
The user who originally created the conversation. |
modified_by |
Optional[str]
|
The user who last modified the conversation. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
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 | |
ConversationCreate
Bases: BaseModel
Pydantic model for creating a new conversation.
Attributes:
| Name | Type | Description |
|---|---|---|
tenant_id |
int
|
The ID of the tenant or organization creating the conversation. Defaults to 1. |
user_id |
int
|
The ID of the user creating the conversation. |
name |
str
|
The name of the conversation. Defaults to 'New Conversation'. |
summary |
Optional[str]
|
A brief summary or description of the conversation. Defaults to 'No Summary'. |
created_by |
Optional[str]
|
The user who created the conversation. Defaults to 'anonymous'. |
modified_by |
Optional[str]
|
The user who last modified the conversation. Defaults to 'anonymous'. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
ConversationUpdate
Bases: BaseModel
Pydantic model for updating an existing conversation.
Attributes:
| Name | Type | Description |
|---|---|---|
tenant_id |
Optional[int]
|
The updated tenant ID, if provided. |
user_id |
Optional[int]
|
The updated user ID, if provided. |
name |
Optional[str]
|
The updated name of the conversation, if provided. |
summary |
Optional[str]
|
The updated summary of the conversation, if provided. |
created_by |
Optional[str]
|
The user who originally created the conversation. Defaults to 'anonymous'. |
modified_by |
Optional[str]
|
The user who last modified the conversation. Defaults to 'anonymous'. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
Message
Bases: BaseModel
Pydantic model representing an individual message within a conversation.
Attributes:
| Name | Type | Description |
|---|---|---|
message_id |
int
|
Unique identifier for the message. |
conversation_id |
int
|
The ID of the conversation the message belongs to. |
role |
RoleType
|
The role of the message sender, either 'user' or 'assistant'. |
content |
Optional[str]
|
The text content of the message. |
parent_message_id |
Optional[int]
|
The ID of the parent message, if this is a reply to another message. |
timestamp |
Optional[datetime]
|
The timestamp indicating when the message was created. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
MessageCreate
Bases: BaseModel
Pydantic model for creating a new message.
Attributes:
| Name | Type | Description |
|---|---|---|
role |
str
|
The role of the message sender, either 'user' or 'assistant'. |
content |
Optional[str]
|
The text content of the message. |
parent_message_id |
Optional[int]
|
The ID of the parent message, if this message is a reply. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
51 52 53 54 55 56 57 58 59 60 61 62 63 | |
MessageFlag
Bases: BaseModel
Pydantic model for returning an existing message flag.
Attributes:
| Name | Type | Description |
|---|---|---|
message_flag_id |
int
|
Unique identifier of the message flag. |
message_id |
int
|
The ID of the message that the flag is associated with. |
flag |
FlagType
|
The type of flag applied to the message (e.g., incorrect, praise, suggestion, other). |
comment |
Optional[str]
|
Optional comment providing additional details about the flag. |
created_at |
datetime
|
The timestamp indicating when the flag was created. |
created_by |
Optional[str]
|
The identifier (username or ID) of the user who created the flag. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
MessageFlagCreate
Bases: BaseModel
Pydantic model for creating a new message flag.
Attributes:
| Name | Type | Description |
|---|---|---|
flag |
FlagType
|
The type of flag to apply to the message. Must be one of ['incorrect', 'praise', 'suggestion', 'other']. |
comment |
Optional[str]
|
Optional comment providing additional details about why the flag is being applied. Max length: 1000 characters. |
created_by |
Optional[str]
|
The identifier (username or ID) of the user creating the flag. Defaults to 'anonymous' if not provided. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
validate_comment_length(v)
Ensures the comment, if provided, is not excessively long.
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
114 115 116 117 118 119 | |
MessageFlagUpdate
Bases: BaseModel
Pydantic model for updating an existing message flag.
Attributes:
| Name | Type | Description |
|---|---|---|
flag |
Optional[FlagType]
|
Updated flag type, if provided. |
comment |
Optional[str]
|
Updated comment associated with the flag. Max length: 1000 characters. |
created_by |
Optional[str]
|
The user who updated the flag, if this information is needed for audit purposes. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
validate_comment_length(v)
Ensures the comment, if provided, does not exceed the maximum length.
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
136 137 138 139 140 141 | |
MessageSQL
Bases: BaseModel
Pydantic model for returning a created MessageSQL entry.
Attributes:
| Name | Type | Description |
|---|---|---|
message_sql_id |
int
|
Unique identifier for the SQL entry. |
message_id |
int
|
The ID of the message associated with this SQL entry. |
query_generated |
str
|
The generated SQL query. |
query_results |
str
|
The results of the SQL query execution, stored as a JSON string or raw text. |
created_at |
datetime
|
Timestamp indicating when the SQL entry was created. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
MessageSQLCreate
Bases: BaseModel
Pydantic model for creating a new MessageSQL entry.
Attributes:
| Name | Type | Description |
|---|---|---|
sql_query |
str
|
The SQL query that was generated in response to a user message. |
sql_results |
Union[str, List[dict]]
|
The raw results of the executed SQL query. Can be either a string or a list of dictionaries. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
stringify_results(v)
Convert list of dictionaries to a JSON-formatted string for storage, if necessary. This ensures that SQL results can be stored in a text field.
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
244 245 246 247 248 249 250 251 252 | |
MessageSQLUpdate
Bases: BaseModel
Pydantic model for updating an existing MessageSQL entry.
Attributes:
| Name | Type | Description |
|---|---|---|
sql_query |
Optional[str]
|
The updated SQL query. |
sql_results |
Optional[Union[str, List[dict]]]
|
The updated raw results of the SQL query. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
stringify_results(v)
Convert list of dictionaries to a JSON-formatted string for storage, if necessary. This ensures that SQL results can be stored in a text field.
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
267 268 269 270 271 272 273 274 275 | |
MessageUpdate
Bases: BaseModel
Pydantic model for updating an existing message.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
Optional[str]
|
The updated content of the message, if provided. |
parent_message_id |
Optional[int]
|
The ID of the parent message, if this message is a reply. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
66 67 68 69 70 71 72 73 74 75 76 | |
conversation_model_to_pydantic(conversation_model)
Converts a ConversationModel instance into a Pydantic Conversation model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_model
|
ConversationModel
|
SQLAlchemy conversation model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Conversation |
Conversation
|
Pydantic representation of the conversation. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
create_conversation(conversation, session=Depends(my_cxo_db_conn.get_db_sess))
async
Creates a new conversation without handling any messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation
|
ConversationCreate
|
The conversation data to create. |
required |
session
|
AsyncSession
|
The database session. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
Conversation |
The created conversation. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
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 | |
create_message(conversation_id, message, session=Depends(my_cxo_db_conn.get_db_sess))
async
Creates a new message for a conversation. If the message role is 'assistant', the frontend should pass the parent_message_id, which is the user message that triggered it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation this message belongs to. |
required |
message
|
MessageCreate
|
The message data to create. |
required |
session
|
AsyncSession
|
The database session. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
The created message. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
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 | |
create_message_flag(conversation_id, message_id, message_flag, session=Depends(my_cxo_db_conn.get_db_sess))
async
Creates a new message flag for a specific message within a conversation.
This method allows users to create flags (e.g., incorrect, praise, suggestion, other) for individual messages. It first ensures that both the conversation and message exist, then creates the flag with the appropriate details provided by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation that contains the message to flag. |
required |
message_id
|
int
|
ID of the message to be flagged. |
required |
message_flag
|
MessageFlagCreate
|
The flag data to create, which includes the flag type and an optional comment. |
required |
session
|
AsyncSession
|
The SQLAlchemy async session for database interaction. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
MessageFlag |
The newly created message flag object. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the conversation or message cannot be found, or if a database error occurs. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
create_message_sql(conversation_id, message_id, message_sql_data, session=Depends(my_cxo_db_conn.get_db_sess))
async
Creates a new SQL query and results entry for a specific message within a conversation.
This method first ensures that the conversation and message exist. Then, it takes the SQL query and results provided in the request and stores them in the 'message_sql' table, associating them with the correct message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation that contains the message. |
required |
message_id
|
int
|
ID of the message for which the SQL query and results are to be created. |
required |
message_sql_data
|
MessageSQLCreate
|
Pydantic model containing the SQL query and results to store. |
required |
session
|
AsyncSession
|
The SQLAlchemy async session for database interaction. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
MessageSQL |
The newly created MessageSQL object containing the query and results. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the conversation or message cannot be found, or if a database error occurs. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 | |
get_conversations(conversation_ids=Query(None), session=Depends(my_cxo_db_conn.get_db_sess))
async
Retrieves conversations from the database.
If conversation_ids is provided, it will return only the specific conversations with the given IDs.
Otherwise, it will return all conversations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_ids
|
List[int]
|
List of conversation IDs to retrieve. |
Query(None)
|
session
|
AsyncSession
|
The database session. |
Depends(get_db_sess)
|
Returns:
| Type | Description |
|---|---|
|
List[Conversation]: List of conversations. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
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 337 338 339 340 341 342 343 | |
get_message_flags(conversation_id, message_id, message_flag_ids=Query(None), session=Depends(my_cxo_db_conn.get_db_sess))
async
Retrieves one, some, or all message flags for a specific message within a conversation.
This method first checks if the conversation and message exist, then fetches the flags associated
with the given message. If message_flag_ids are provided, it will retrieve only the specified flags.
Otherwise, it will return all flags associated with the message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation containing the message. |
required |
message_id
|
int
|
ID of the message for which the flags are to be retrieved. |
required |
message_flag_ids
|
List[int]
|
List of specific flag IDs to retrieve. Defaults to None (all flags). |
Query(None)
|
session
|
AsyncSession
|
The SQLAlchemy async session for database interaction. |
Depends(get_db_sess)
|
Returns:
| Type | Description |
|---|---|
|
List[MessageFlag]: A list of message flags, either specific ones or all flags associated with the message. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the conversation or message cannot be found, or if a database error occurs. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 | |
get_message_sql(conversation_id, message_id, session=Depends(my_cxo_db_conn.get_db_sess))
async
Retrieves the SQL query and results for a specific message within a conversation.
This method first ensures that the conversation and message exist. Then, it retrieves the associated SQL entry for the message, if it exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation that contains the message. |
required |
message_id
|
int
|
ID of the message for which the SQL query and results are to be retrieved. |
required |
session
|
AsyncSession
|
The SQLAlchemy async session for database interaction. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
MessageSQL |
The MessageSQL object containing the query and results, if found. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the conversation, message, or message SQL entry cannot be found. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
get_messages(conversation_id, message_ids=Query(None), session=Depends(my_cxo_db_conn.get_db_sess))
async
Retrieves messages from a conversation. If message_ids is provided, it will return
only those messages. Otherwise, it will return all messages for the conversation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation to fetch messages from. |
required |
message_ids
|
List[int]
|
List of message IDs to retrieve. |
Query(None)
|
session
|
AsyncSession
|
The database session. |
Depends(get_db_sess)
|
Returns:
| Type | Description |
|---|---|
|
List[Message]: List of messages. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
update_conversation(conversation_id, conversation=Body(...), session=Depends(my_cxo_db_conn.get_db_sess))
async
Updates a conversation's metadata, such as user_id, name, summary, created_by, modified_by, and modified_at fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation to update. |
required |
conversation
|
ConversationUpdate
|
Updated conversation data. |
Body(...)
|
session
|
AsyncSession
|
The database session. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
Conversation |
The updated conversation. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
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 | |
update_message(conversation_id, message_id, message=Body(...), session=Depends(my_cxo_db_conn.get_db_sess))
async
Updates an existing message within a conversation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation the message belongs to. |
required |
message_id
|
int
|
ID of the message to update. |
required |
message
|
MessageUpdate
|
Updated message data. |
Body(...)
|
session
|
AsyncSession
|
The database session. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
The updated message. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
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 | |
update_message_flag(conversation_id, message_id, message_flag_id, flag_update, session=Depends(my_cxo_db_conn.get_db_sess))
async
Updates an existing message flag for a specific message within a conversation.
This method allows users to update the flag type, comment, or both for an existing message flag. It first ensures that the conversation, message, and flag exist, then applies the updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation that contains the message. |
required |
message_id
|
int
|
ID of the message to which the flag is associated. |
required |
message_flag_id
|
int
|
ID of the message flag to update. |
required |
flag_update
|
MessageFlagUpdate
|
Pydantic model containing the new flag type, comment, or both. |
required |
session
|
AsyncSession
|
The SQLAlchemy async session for database interaction. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
MessageFlag |
The updated message flag object. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the conversation, message, or flag cannot be found, or if a database error occurs. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
update_message_sql(conversation_id, message_id, message_sql_id, message_sql_data, session=Depends(my_cxo_db_conn.get_db_sess))
async
Updates the SQL query and results for a specific message SQL entry within a conversation.
This method first ensures that the conversation, message, and message SQL entry exist. Then, it updates the provided fields (SQL query and results) for the message SQL entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int
|
ID of the conversation that contains the message. |
required |
message_id
|
int
|
ID of the message for which the SQL query and results are to be updated. |
required |
message_sql_id
|
int
|
ID of the message SQL entry to update. |
required |
message_sql_data
|
MessageSQLUpdate
|
Pydantic model containing the updated SQL query and/or results. |
required |
session
|
AsyncSession
|
The SQLAlchemy async session for database interaction. |
Depends(get_db_sess)
|
Returns:
| Name | Type | Description |
|---|---|---|
MessageSQL |
The updated MessageSQL object containing the updated query and results. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the conversation, message, or message SQL entry cannot be found, or if a database error occurs. |
Source code in mycxo/boxtalk/routes/api/conversations/conversation_route.py
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 | |