Skip to content

Commit

Permalink
Merge pull request #164 from iceljc/features/refine-chat-window
Browse files Browse the repository at this point in the history
skip loader
  • Loading branch information
iceljc authored Jul 17, 2024
2 parents e8ff46f + b62fbe1 commit c5d251d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/lib/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export const TEXT_EDITORS = [

export const FILE_EDITORS = [
EditorType.File
];
];

export const LERNER_ID = "01acc3e5-0af7-49e6-ad7a-a760bd12dc40";
export const TRAINING_MODE = "training";
3 changes: 2 additions & 1 deletion src/lib/helpers/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function skipLoader(config) {

const getRegexes = [
new RegExp('http(s*)://(.*?)/address/options(.*?)', 'g'),
new RegExp('http(s*)://(.*?)/conversation/(.*?)/files/(.*?)', 'g')
new RegExp('http(s*)://(.*?)/conversation/(.*?)/files/(.*?)', 'g'),
new RegExp('http(s*)://(.*?)/llm-provider/(.*?)/models', 'g')
];

if (config.method === 'post' && !!config.data && postRegexes.some(regex => regex.test(config.url || ''))) {
Expand Down
14 changes: 13 additions & 1 deletion src/routes/chat/[agentId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { getToken, setToken } from '$lib/services/auth-service.js'
import { getUserStore } from '$lib/helpers/store.js';
import { conversationStore, getConversationStore } from '$lib/helpers/store.js';
import { LERNER_ID, TRAINING_MODE } from '$lib/helpers/constants';
const params = $page.params;
Expand Down Expand Up @@ -40,10 +41,21 @@
conversationId = conversation.id;
let chatUrl = `chat/${agentId}/${conversationId}`;
let query = "";
if (agentId === LERNER_ID) {
query += `mode=${TRAINING_MODE}`;
}
const isFrame = $page.url.searchParams.get('isFrame');
if (isFrame === 'true') {
chatUrl = `${chatUrl}?isFrame=true`
query += "isFrame=true";
}
if (!!query) {
chatUrl = `${chatUrl}?${query}`;
}
window.location.href = chatUrl;
});
</script>
Expand Down
20 changes: 15 additions & 5 deletions src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { onMount, setContext, tick } from 'svelte';
import Viewport from 'svelte-viewport-info';
import { PUBLIC_LIVECHAT_ENTRY_ICON } from '$env/static/public';
import { BOT_SENDERS, TEXT_EDITORS, USER_SENDERS } from '$lib/helpers/constants';
import { BOT_SENDERS, LERNER_ID, TEXT_EDITORS, TRAINING_MODE, USER_SENDERS } from '$lib/helpers/constants';
import { signalr } from '$lib/services/signalr-service.js';
import { webSpeech } from '$lib/services/web-speech.js';
import { newConversation } from '$lib/services/conversation-service';
Expand Down Expand Up @@ -130,6 +130,9 @@
let autoScrollLog = false;
let disableAction = false;
/** @type {string} */
let mode = '';
$: {
const editor = lastBotMsg?.rich_content?.editor || '';
loadTextEditor = TEXT_EDITORS.includes(editor) || !Object.values(EditorType).includes(editor);
Expand Down Expand Up @@ -184,6 +187,7 @@
function initChatView() {
isFrame = $page.url.searchParams.get('isFrame') === 'true';
mode = $page.url.searchParams.get('mode') || '';
// initial condition
isPersistLogClosed = false;
isInstantLogClosed = false;
Expand Down Expand Up @@ -394,6 +398,9 @@
window.location.href = url;
}
function handleSaveKnowledge() {
sendChatMessage("Save knowledge");
}
/**
* @param {string} msgText
Expand Down Expand Up @@ -952,14 +959,17 @@
</Dropdown>
</li>
{/if}
<DropdownItem on:click={handleNewConversation}>New Conversation</DropdownItem>
<DropdownItem on:click={() => handleNewConversation()}>New Conversation</DropdownItem>
{#if agent?.id === LERNER_ID && mode === TRAINING_MODE}
<DropdownItem on:click={() => handleSaveKnowledge()}>Save Knowledge</DropdownItem>
{/if}
</DropdownMenu>
</Dropdown>
</li>
<li class="list-inline-item d-md-inline-block">
<button
class="btn btn-primary btn-rounded btn-sm chat-send waves-effect waves-light"
class={`btn btn-rounded btn-sm chat-send waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`}
disabled={disableAction}
on:click={() => endChat()}
>
Expand Down Expand Up @@ -1087,7 +1097,7 @@
<div class="col-auto">
<button
type="submit"
class="btn btn-primary btn-rounded waves-effect waves-light"
class={`btn btn-rounded waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`}
disabled={isSendingMsg || isThinking || disableAction}
on:click={startListen}
>
Expand All @@ -1114,7 +1124,7 @@
<div class="col-auto">
<button
type="submit"
class="btn btn-primary btn-rounded chat-send waves-effect waves-light"
class={`btn btn-rounded chat-send waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`}
disabled={!!!_.trim(text) || isSendingMsg || isThinking || disableAction}
on:click={() => sentTextMessage()}
><span class="d-none d-md-inline-block me-2">Send</span>
Expand Down
3 changes: 2 additions & 1 deletion src/routes/page/agent/card-agent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Badge, Card, CardBody, Col } from '@sveltestrap/sveltestrap';
import { format } from '$lib/helpers/datetime';
import { _ } from 'svelte-i18n';
import { LERNER_ID } from "$lib/helpers/constants";
/** @type {import('$types').AgentModel[]} */
export let agents;
Expand Down Expand Up @@ -72,7 +73,7 @@
</li>
{#if agent.is_public }
<li class="list-inline-item me-1">
<Link href="page/agent/{agent.id}/train" class="btn btn-primary btn-sm" target="_blank" disabled>
<Link href={`/chat/${LERNER_ID}`} class="btn btn-primary btn-sm" target="_blank">
<i class="bx bx-book-open" /> {$_('Train')}
</Link>
</li>
Expand Down

0 comments on commit c5d251d

Please sign in to comment.