Skip to content

Commit f41c97d

Browse files
NeonDanielkirgrim
andauthored
Multi-Round Discussion (#10)
* Fixed deployment issues * Fixed deployment issues * Added missing dependency * fix typo * commented-out build reference until troubleshooted * Added rendering of the multi-round discussions in the prompts table * Updated fetching of discussion rounds * Fixed multiround discussions rendering * Fixed handling of multi-round prompt discussions and minor UI fixes * ran pre-commit fix * Manually re-apply pre-commit linting * Update license_tests --------- Co-authored-by: Kyrylo Hrymailo <kirill.grim@gmail.com>
1 parent c48c416 commit f41c97d

10 files changed

Lines changed: 248 additions & 116 deletions

File tree

.github/workflows/license_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ jobs:
1010
license_tests:
1111
uses: neongeckocom/.github/.github/workflows/license_tests.yml@master
1212
with:
13-
packages-exclude: '^(pyklatchat|neon|tqdm|RapidFuzz|typing_extensions|typing-inspection|click|setuptools|urllib3).*'
13+
packages-exclude: '^(pyklatchat|neon|tqdm|RapidFuzz|typing_extensions|typing-inspection|click|setuptools|urllib3|marisa-trie).*'

chat_client/static/css/klatchatNano.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,4 +437,4 @@ background-color: darkblue;
437437

438438
.modal, .modal-backdrop {
439439
position: absolute !important;
440-
}
440+
}

chat_client/static/js/builder_utils.js

Lines changed: 193 additions & 93 deletions
Large diffs are not rendered by default.

chat_client/static/js/chat_utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ async function buildConversation(conversationData, skin, remember=true,conversat
387387
* @param maxResults - max number of messages to fetch
388388
* @returns {Promise<{}>} promise resolving conversation data returned
389389
*/
390-
async function getConversationDataByInput(input, skin, oldestMessageTS=null, maxResults=10){
390+
async function getConversationDataByInput(input, skin, oldestMessageTS=null, maxResults=30){
391391
let conversationData = {};
392392
if(input){
393393
let query_url = `chat_api/search/${input.toString()}?limit_chat_history=${maxResults}&skin=${skin}`;
@@ -696,7 +696,7 @@ async function displayConversation(searchStr, skin=CONVERSATION_SKINS.PROMPTS, a
696696
}
697697
else if (searchStr !== "") {
698698
const alertParent = document.getElementById(alertParentID || conversationParentID);
699-
await getConversationDataByInput(searchStr, skin, null, 10).then(async conversationData => {
699+
await getConversationDataByInput(searchStr, skin, null).then(async conversationData => {
700700
let responseOk = false;
701701
if (!conversationData || Object.keys(conversationData).length === 0){
702702
displayAlert(

chat_client/static/js/klatchatNano.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3980,4 +3980,4 @@ const initKlatChat = (options) => {
39803980
document.addEventListener('DOMContentLoaded', (e) => {
39813981
return new NanoBuilder(options);
39823982
})
3983-
};
3983+
};

chat_client/static/js/message_utils.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,29 @@ const getUserPromptTR = (promptID, userID) => {
106106

107107
/**
108108
* Adds prompt message of specified user id
109-
* @param cid: target conversation id
110-
* @param userID: target submind user id
111-
* @param messageText: message of submind
112-
* @param promptId: target prompt id
113-
* @param promptState: prompt state to consider
109+
* @param cid - target conversation id
110+
* @param userID - target submind user id
111+
* @param messageText - message of submind
112+
* @param promptId - target prompt id
113+
* @param promptState - prompt state to consider
114+
* @param promptContext - associated prompt's context
114115
*/
115-
async function addPromptMessage(cid, userID, messageText, promptId, promptState){
116+
async function addPromptMessage(cid, userID, messageText, promptId, promptState, promptContext){
116117
const tableBody = document.getElementById(`${promptId}_tbody`);
117118
if (await getCurrentSkin(cid) === CONVERSATION_SKINS.PROMPTS){
118119
try {
119120
const userData = await getUserData(userID);
120121
promptState = PROMPT_STATES[promptState].toLowerCase();
121122
if (!getUserPromptTR(promptId, userID)) {
122-
const newUserRow = await buildSubmindHTML(promptId, userID, userData, '', '', '');
123+
const newUserRow = await buildSubmindHTML(promptId, userID, userData, '', '', '', promptContext?.discussion_rounds);
123124
tableBody.insertAdjacentHTML('beforeend', newUserRow);
124125
}
125126
try {
126-
console.log("userData:", userData)
127-
const messageElem = document.getElementById(`${promptId}_${userData['nickname']}_${promptState}`);
127+
let messageElemId = `${promptId}_${userData['nickname']}_${promptState}`
128+
if (promptState === "disc" && promptContext?.discussion_rounds > 1 && promptContext?.discussion_counter){
129+
messageElemId += `_${promptContext?.discussion_counter}`
130+
}
131+
const messageElem = document.getElementById(messageElemId);
128132
messageElem.innerText = messageText;
129133
} catch (e) {
130134
console.warn(`Failed to add prompt message (${cid},${userID}, ${messageText}, ${promptId}, ${promptState}) - ${e}`)
@@ -182,7 +186,7 @@ async function addOldMessages(cid, skin=CONVERSATION_SKINS.BASE) {
182186
const firstMessageItem = messageContainer.children[i];
183187
const oldestMessageTS = await DBGateway.getInstance(DB_TABLES.CHAT_MESSAGES_PAGINATION).getItem(cid).then(res=> res?.oldest_created_on || null);
184188
if (oldestMessageTS) {
185-
const numMessages = await getCurrentSkin(cid) === CONVERSATION_SKINS.PROMPTS? 30: 10;
189+
const numMessages = await getCurrentSkin(cid) === CONVERSATION_SKINS.PROMPTS? 50: 10;
186190
await getConversationDataByInput( cid, skin, oldestMessageTS, numMessages ).then( async conversationData => {
187191
if (messageContainer) {
188192
const userMessageList = getUserMessages( conversationData, null );

chat_client/static/js/sio.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function initSIO(){
7272
});
7373

7474
socket.on('new_prompt_message', async (message) => {
75-
await addPromptMessage(message['cid'], message['userID'], message['messageText'], message['promptID'], message['promptState'])
75+
await addPromptMessage(message['cid'], message['userID'], message['messageText'], message['promptID'], message['promptState'], message?.context)
7676
.catch(err => console.error('Error occurred while adding new prompt data: ', err));
7777
});
7878

@@ -82,9 +82,17 @@ function initSIO(){
8282
console.info(`setting prompt_id=${promptID} as completed`);
8383
if (promptElem){
8484
const promptWinner = document.getElementById(`${promptID}_winner`);
85-
const winner_response = document.getElementById(`${promptID}_${data['winner']}_resp`).innerText;
86-
console.log("data:", data)
87-
promptWinner.innerHTML = await buildPromptWinnerHTML(data['winner'], winner_response);
85+
let winnerResponse;
86+
if (data?.winner){
87+
const winnerRespHTML = document.getElementById(`${promptID}_${data.winner}_resp`);
88+
if (winnerRespHTML) {
89+
winnerResponse = winnerRespHTML.innerText;
90+
}
91+
}
92+
if (!winnerResponse){
93+
winnerResponse = "Consensus not reached."
94+
}
95+
promptWinner.innerHTML = await buildPromptWinnerHTML(data['winner'], winnerResponse);
8896
}else {
8997
console.warn(`Failed to get HTML element from prompt_id=${promptID}`);
9098
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<tr id="{prompt_id}_{user_id}_prompt_row" data-submind-id="{user_id}">
2+
<td class="d-flex justify-content-center" style="border-width: 0; border-top-width: 1px">
3+
{participant_icon}
4+
</td>
5+
<td>
6+
<div style="overflow-y:auto; width:100%; max-height: 150px!important;" id="{prompt_id}_{user_nickname}_resp"
7+
data-message-id="{response_message_id}"
8+
data-created-on="{response_created_on}"
9+
data-toggle="tooltip"
10+
title="{response_created_on_tooltip}">{response}
11+
</div>
12+
</td>
13+
{submind_discussions}
14+
<td id="{prompt_id}_{user_nickname}_vote"
15+
data-created-on="{vote_created_on}"
16+
data-message-id="{vote_message_id}"
17+
data-toggle="tooltip"
18+
title="{vote_created_on_tooltip}">{vote}
19+
</td>
20+
</tr>

chat_client/templates/components/prompt_table.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
<table class="data table table-bordered prompt-table" data-rtc-resizable-table="table.one" id="{prompt_id}">
33
<thead>
44
<tr>
5-
<th colspan="4">Prompt: "{prompt_text}"</th>
5+
<th colspan="{tr_length}">Prompt: "{prompt_text}"</th>
66
</tr>
77
<tr>
88
<th data-rtc-resizable="subminds">Submind</th>
99
<th data-rtc-resizable="responses">Response</th>
10-
<th data-rtc-resizable="discussion">Discussion</th>
10+
{discussions_header}
1111
<th data-rtc-resizable="votes">Vote</th>
1212
</tr>
1313
</thead>
1414
<tbody id="{prompt_id}_tbody">
1515
{prompt_participants_data}
1616
</tbody>
1717
<tr>
18-
<th colspan="4" id="{prompt_id}_winner" style="font-weight: normal">{selected_winner}</th>
18+
<th colspan="{tr_length}" id="{prompt_id}_winner" style="font-weight: normal">{selected_winner}</th>
1919
</tr>
2020
</table>
2121
</li>

requirements/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cachetools==5.5.0
22
fastapi==0.115.6
33
httpx==0.28.1 # required by FastAPI
44
Jinja2==3.1.4
5-
klatchat-utils~=0.0,>=0.0.1a1
5+
klatchat-utils~=0.0,>=0.0.1a2
66
neon_utils[sentry]~=1.12
77
python-multipart==0.0.9
88
requests==2.32.3

0 commit comments

Comments
 (0)