Skip to content

Commit e51d2b2

Browse files
authored
Fix discussion rendering (#12)
* Fix table rendering to support multi-round discussion with single round configured * Refactor Dockerfile to optimize layer caching * Add pre-commit formatting to resolve GHA failure
1 parent e51dd58 commit e51d2b2

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ ENV OVOS_CONFIG_FILENAME=klat.yaml
88
ENV XDG_CONFIG_HOME=/config
99
ENV KLAT_ENV=PROD
1010

11-
COPY . /app/
12-
13-
WORKDIR /app
14-
1511
RUN apt-get update \
1612
&& apt-get install -y \
17-
&& apt install build-essential -y \
13+
&& apt-get install build-essential -y \
1814
&& pip install --upgrade pip \
1915
&& pip install wheel
2016

21-
RUN pip install /app
17+
COPY . /app/
18+
19+
WORKDIR /app
2220

21+
RUN pip install /app
2322

2423
CMD ["pyklatchat-client"]

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: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function generateDarkColorFromUsername(username) {
158158
* @param submindID - user id of submind
159159
* @param submindUserData - user data of submind
160160
* @param submindResponse - Responding data of submind to incoming prompt
161-
* @param submindOpinions - Discussion data of submind to incoming prompt
161+
* @param submindOpinions - Discussion data of submind to incoming prompt, Dict or List[Dict]
162162
* @param submindVote - Vote data of submind in prompt
163163
* @param discussionRounds - number of discussion rounds (used for rendering)
164164
* @return {Promise<string|void>} - Submind Data HTML populated with provided data
@@ -183,8 +183,15 @@ async function buildSubmindHTML(promptID, submindID, submindUserData, submindRes
183183
let promptParticipantTemplate;
184184
// Fallback to the single-discussion rounds
185185
if (!discussionRounds || discussionRounds === 1) {
186-
phaseDataObjectMapping['opinion'] = submindOpinions;
187-
promptParticipantTemplate = 'prompt_participant'
186+
// Check if submindOpinions is an array and take the first element if it is.
187+
if (Array.isArray(submindOpinions)) {
188+
// Handles cases where multi-round discussion specifies 1 round
189+
phaseDataObjectMapping['opinion'] = submindOpinions[0];
190+
} else {
191+
// Handles backwards-compat. where only one discussion round was saved
192+
phaseDataObjectMapping['opinion'] = submindOpinions;
193+
}
194+
promptParticipantTemplate = 'prompt_participant';
188195
}else{
189196
templateData['submind_discussions'] = buildSubmindDiscussionHTML(promptID, userNickname, submindOpinions, discussionRounds);
190197
promptParticipantTemplate = 'prompt_participant_multi_discussions'
@@ -340,15 +347,20 @@ async function buildPromptHTML(prompt) {
340347
try {
341348
const messageIds = promptData[key]?.[submindID];
342349
if (Array.isArray(messageIds)) {
350+
// Handle `submind_discussion_history` which maps User UID to an array of message IDs
343351
data[key] = messageIds.map(id => {
344352
const raw = prompt['message_mapping']?.[id]?.[0];
353+
if (!raw) {
354+
console.warn(`Message ID ${id} not found in message_mapping for key ${key}`);
355+
}
345356
return raw ? { ...raw, message_id: id } : { message_text: emptyAnswer };
346357
});
347358
} else {
348359
const id = messageIds;
349360
const raw = prompt['message_mapping']?.[id]?.[0];
350361
data[key] = raw ? { ...raw, message_id: id } : { message_text: emptyAnswer };
351362
}
363+
console.debug(`Fetched data for key ${key} and submindID ${submindID}:`, data[key]);
352364
} catch (e) {
353365
data[key] = Array.isArray(promptData[key]?.[submindID])
354366
? promptData[key][submindID].map(() => ({message_text: emptyAnswer}))

chat_client/static/js/klatchatNano.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4103,4 +4103,4 @@ const initKlatChat = (options) => {
41034103
document.addEventListener('DOMContentLoaded', (e) => {
41044104
return new NanoBuilder(options);
41054105
})
4106-
};
4106+
};

0 commit comments

Comments
 (0)