Skip to content

Commit

Permalink
add chat tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Jicheng Lu committed Oct 18, 2024
1 parent 1650875 commit 74864b7
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 58 deletions.
32 changes: 21 additions & 11 deletions src/lib/common/MultiSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
/** @type {string} */
export let searchPlaceholder = '';
/** @type {string} */
export let placeholder = '';
/** @type {string} */
export let containerClasses = "";
Expand All @@ -26,9 +29,13 @@
/** @type {boolean} */
export let disableDefaultStyles = false;
/** @type {boolean} */
export let searchMode = false;
/** @type {null | undefined | (() => Promise<any>)} */
export let onScrollMoreOptions = null;
/** @type {string} */
let searchValue = '';
Expand Down Expand Up @@ -179,7 +186,7 @@
function sendEvent() {
svelteDispatch("select", {
selecteds: refOptions.filter(x => !!x.checked)
selecteds: refOptions.filter(x => !!x.checked).map(x => ({ key: x.key, value: x.value }))
});
}
Expand Down Expand Up @@ -261,6 +268,7 @@
type="text"
class='clickable'
value={displayText}
placeholder={placeholder}
readonly
/>
<div class={`display-suffix ${showOptionList ? 'show-list' : ''}`}>
Expand All @@ -269,17 +277,19 @@
</ul>
{#if showOptionList}
<ul class="option-list" id={`multiselect-list-${tag}`} on:scroll={() => innerScroll()}>
<div class="search-box">
<div class="search-prefix">
<i class="bx bx-search-alt" />
{#if searchMode}
<div class="search-box">
<div class="search-prefix">
<i class="bx bx-search-alt" />
</div>
<Input
type="text"
value={searchValue}
placeholder={searchPlaceholder}
on:input={e => changeSearchValue(e)}
/>
</div>
<Input
type="text"
value={searchValue}
placeholder={searchPlaceholder}
on:input={e => changeSearchValue(e)}
/>
</div>
{/if}
{#if innerOptions.length > 0}
{#if selectAll}
<!-- svelte-ignore a11y-click-events-have-key-events -->
Expand Down
8 changes: 7 additions & 1 deletion src/lib/helpers/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ const chatAction = {
NewChat: 'new-chat',
ReceiveNotification: 'receive-notification'
};
export const ChatAction = Object.freeze(chatAction);
export const ChatAction = Object.freeze(chatAction);

const conversationTag = {
Evaluation: "evaluation-set",
Test: "test-set"
};
export const ConversationTag = Object.freeze(conversationTag);
1 change: 1 addition & 0 deletions src/lib/helpers/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function skipLoader(config) {
const putRegexes = [
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/update', 'g'),
new RegExp('http(s*)://(.*?)/conversation/(.*?)/update-message', 'g'),
new RegExp('http(s*)://(.*?)/conversation/(.*?)/update-tags', 'g'),
];

const deleteRegexes = [
Expand Down
1 change: 0 additions & 1 deletion src/lib/helpers/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ export const knowledgeBaseDocumentStore = createKnowledgeBaseDocumentStore();

export function resetLocalStorage(resetUser = false) {
conversationUserStateStore.resetAll();
conversationSearchOptionStore.reset();
conversationUserMessageStore.reset();
conversationUserAttachmentStore.reset();
localStorage.removeItem('conversation');
Expand Down
18 changes: 17 additions & 1 deletion src/lib/helpers/types/conversationTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @property {string?} [status] - The conversation status.
* @property {string?} [taskId] - The task id.
* @property {import('$commonTypes').KeyValuePair[]} [states] - The conversation status.
* @property {string[]} [tags] - The tags.
*/

/**
Expand All @@ -29,7 +30,8 @@
* @property {string} channel - The conversation status.
* @property {string} [task_id] - Optional task id.
* @property {string} status - The conversation status.
* @property {Object[]} states - The conversation states.
* @property {Object[]} states - The conversation states.
* @property {string[]} tags - The conversation tags.
* @property {Date} updated_time - The conversation updated time.
* @property {Date} created_time - The conversation created time.
*/
Expand Down Expand Up @@ -259,7 +261,21 @@ IRichContent.prototype.quick_replies;
* @property {number} innerIndex
*/

/**
* @typedef {Object} UpdateTagsRequest
* @property {string[]} tags
*/


/**
* @typedef {Object} ConversationSearchOption
* @property {string?} [agentId]
* @property {string?} [channel]
* @property {string?} [taskId]
* @property {string?} [status]
* @property {UserStateDetailModel[]} states
* @property {string[]} tags
*/

/**
* Invoked when a new conersation is created.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/scss/custom/components/_multiselect.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

.option-list {
padding: 5px 2px;
border: 2px solid var(--bs-border-color-translucent);
border: 1px solid var(--bs-border-color-translucent);
border-radius: 5px;

overflow-x: auto;
Expand Down
40 changes: 40 additions & 0 deletions src/lib/scss/custom/pages/_chat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@

.chat-row {
height: 100%;
flex-wrap: nowrap;
justify-content: space-between;

.chat-head-info {
display: flex;
flex: 0 0 fit-content;
flex-direction: column;
height: 100%;

Expand Down Expand Up @@ -152,6 +155,25 @@
border: 1px solid var(--#{$prefix}border-color);
}
}

.large-btn {
width: 40px;
height: 40px;
}

.btn-pair {
display: flex;

.btn-left {
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
}

.btn-right {
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
}
}
}

.chat-conversation {
Expand Down Expand Up @@ -765,4 +787,22 @@
}
}
}
}

.conv-tags-container {
display: flex;
flex-wrap: wrap;
overflow-y: auto;
scrollbar-width: none;
min-height: 100px;
max-height: 180px;

.conv-tag-unit {
flex: 0 0 50%;

label {
font-size: 14px;
font-weight: 400;
}
}
}
1 change: 1 addition & 0 deletions src/lib/services/api-endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const endpoints = {
dialogsUrl: `${host}/conversation/{conversationId}/dialogs`,
conversationMessageDeletionUrl: `${host}/conversation/{conversationId}/message/{messageId}`,
conversationMessageUpdateUrl: `${host}/conversation/{conversationId}/update-message`,
conversationTagsUpdateUrl: `${host}/conversation/{conversationId}/update-tags`,
fileUploadUrl: `${host}/agent/{agentId}/conversation/{conversationId}/upload`,

// LLM provider
Expand Down
26 changes: 25 additions & 1 deletion src/lib/services/conversation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function deleteConversation(conversationId) {
* @param {string} conversationId
* @returns {Promise<import('$conversationTypes').ChatResponseModel[]>}
*/
export async function GetDialogs(conversationId) {
export async function getDialogs(conversationId) {
let url = replaceUrl(endpoints.dialogsUrl, {conversationId: conversationId});
const response = await axios.get(url);
return response.data;
Expand Down Expand Up @@ -170,6 +170,30 @@ export async function deleteConversationMessage(conversationId, messageId, isNew
});
}

/**
* delete a message in conversation
* @param {string} conversationId The conversation id
* @param {import('$conversationTypes').UpdateTagsRequest} request
* @returns {Promise<boolean>}
*/
export async function updateConversationTags(conversationId, request) {
let url = replaceUrl(endpoints.conversationTagsUpdateUrl, {
conversationId: conversationId
});

const data = {
tags: request.tags || []
};

return new Promise((resolve, reject) => {
axios.put(url, {...data}).then(response => {
resolve(response.data);
}).catch(err => {
reject(err)
});
});
}

/**
* delete a message in conversation
* @param {string} conversationId The conversation id
Expand Down
Loading

0 comments on commit 74864b7

Please sign in to comment.