Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ export const EVALUATOR_ID = "2cd4b805-7078-4405-87e9-2ec9aadf8a11";
export const TRAINING_MODE = "training";

export const DEFAULT_KNOWLEDGE_COLLECTION = "BotSharp";
export const IMAGE_DATA_PREFIX = 'data:image';
export const IMAGE_DATA_PREFIX = 'data:image';

export const INTEGER_REGEX = "[0-9]+";
export const DECIMAL_REGEX = "[0-9.]+";
3 changes: 2 additions & 1 deletion src/lib/helpers/types/agentTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
* @property {string} name
* @property {string} type
* @property {string?} [displayName]
* @property {boolean} disabled
* @property {boolean} disabled
* @property {number?} [confidence]
*/

/**
Expand Down
4 changes: 3 additions & 1 deletion src/lib/scss/custom/pages/_agent.scss
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@

.utility-label {
width: 30%;
font-size: 0.95em;
flex-wrap: wrap;
}

.utility-value {
Expand Down Expand Up @@ -222,7 +224,7 @@
display: flex;

.utility-label {
font-size: 12px;
font-size: 0.95em;
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/routes/page/agent/[agentId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@
utilities: agent.utilities || [],
knowledge_bases: agent.knowledge_bases || [],
rules: agent.rules || [],
max_message_count: Number(agent.max_message_count) > 0 ? Number(agent.max_message_count) : null,
llm_config: {
...agent.llm_config,
max_output_tokens: Number(agent.llm_config.max_output_tokens) > 0 ? Number(agent.llm_config.max_output_tokens) : null
}
max_message_count: Number(agent.max_message_count) > 0 ? Number(agent.max_message_count) : null
};
isLoading = true;
saveAgent(agent).then(res => {
Expand Down Expand Up @@ -198,6 +194,7 @@
function fetchTabData() {
const data = agentTabsCmp?.fetchTabData();
if (data) {
agent.llm_config = data.llmConfig;
agent.utilities = data.utilities || [];
agent.knowledge_bases = data.knwoledgebases || [];
agent.rules = data.rules || [];
Expand Down Expand Up @@ -239,7 +236,7 @@
saveAgentDraft(data);
}

function agentDraftReset() {
function handleAgentReset() {
agent = JSON.parse(JSON.stringify(originalAgent));
agentDraft = null;
deleteAgentDraft();
Expand All @@ -266,7 +263,7 @@
profiles={agent.profiles || []}
labels={agent.labels || []}
resetable={!!agentDraft}
resetAgent={() => agentDraftReset()}
resetAgent={() => handleAgentReset()}
{handleAgentChange}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import { Card, CardBody, Input, Button } from '@sveltestrap/sveltestrap';
import { getVectorKnowledgeCollections } from '$lib/services/knowledge-base-service';
import { KnowledgeCollectionDisplayType } from '$lib/helpers/enums';
import { DECIMAL_REGEX } from '$lib/helpers/constants';

const limit = 5;
const confidLowerBound = 0;
const confidUpperBound = 1;

/** @type {import('$agentTypes').AgentModel} */
export let agent;
Expand All @@ -17,7 +20,8 @@
return {
name: x.name,
type: x.type,
disabled: x.disabled
disabled: x.disabled,
confidence: x.confidence
};
});

Expand Down Expand Up @@ -96,6 +100,44 @@
innerRefresh(innerKnowledgeBases);
}

/**
* @param {any} e
* @param {number} idx
*/
function changeConfidence(e, idx) {
const found = innerKnowledgeBases.find((_, index) => index === idx);
if (!found) return;

const value = e.target.value;
const confidence = validateConfidenceNumber(value);
found.confidence = confidence;
handleAgentChange();
innerRefresh(innerKnowledgeBases);
}

/** @param {any} e */
function validateConfidenceInput(e) {
const reg = new RegExp(DECIMAL_REGEX, 'g');
if (e.key !== 'Backspace' && !reg.test(e.key)) {
e.preventDefault();
}
}

/** @param {string} value */
function validateConfidenceNumber(value) {
let confidence;
const num = Number(value);

if (isNaN(num) || num < confidLowerBound) {
confidence = '0.0';
} else if (num >= confidUpperBound) {
confidence = '1.0';
} else {
confidence = num.toFixed(1);
}
return Number(confidence);
}

function addKnowledgeBase() {
innerKnowledgeBases = [
...innerKnowledgeBases,
Expand Down Expand Up @@ -136,7 +178,8 @@
name: x.name,
type: x.type,
displayName: x.displayName,
disabled: x.disabled
disabled: x.disabled,
confidence: x.confidence
}
}) || [];
}
Expand Down Expand Up @@ -198,6 +241,28 @@
</div>
</div>
</div>
<div class="utility-row utility-row-secondary">
<div class="utility-content">
<div class="utility-list-item">
<div class="utility-label line-align-center">
{'Confidence'}
</div>
<div class="utility-value">
<div class="utility-input line-align-center">
<Input
type="text"
class="text-center"
bind:value={knowledge.confidence}
disabled={knowledge.disabled}
on:keydown={e => validateConfidenceInput(e)}
on:blur={e => changeConfidence(e, uid)}
/>
</div>
<div class="utility-delete line-align-center"></div>
</div>
</div>
</div>
</div>
</div>
{/each}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
import { onMount } from 'svelte';
import { Card, CardBody, Input } from '@sveltestrap/sveltestrap';
import { getLlmProviders, getLlmProviderModels } from '$lib/services/llm-provider-service';
import { INTEGER_REGEX } from '$lib/helpers/constants';

/** @type {import('$agentTypes').AgentModel} */
export let agent;

/** @type {() => void} */
export let handleAgentChange = () => {};

export const fetchLlmConfig = () => {
return {
...config,
max_output_tokens: Number(config.max_output_tokens) > 0 ? Number(config.max_output_tokens) : null
};
}

export const fetchOriginalLlmConfig = () => {};

export const refresh = () => {
config = agent.llm_config;
init();
Expand Down Expand Up @@ -56,7 +66,6 @@
}

config.is_inherit = false;
// handleAgentChange();
models = await getLlmProviderModels(provider);
config.model = models[0]?.name;
handleAgentChange();
Expand Down Expand Up @@ -89,6 +98,14 @@
config.max_output_tokens = value;
handleAgentChange();
}

/** @param {any} e */
function validateIntegerInput(e) {
const reg = new RegExp(INTEGER_REGEX, 'g');
if (e.key !== 'Backspace' && !reg.test(e.key)) {
e.preventDefault();
}
}
</script>

<Card>
Expand Down Expand Up @@ -138,6 +155,7 @@
min={recursiveDepthLowerLimit}
max={recursiveDepthUpperLimit}
value={config.max_recursion_depth}
on:keydown={e => validateIntegerInput(e)}
on:change={e => changeMaxRecursiveDepth(e)}
/>
</div>
Expand All @@ -152,6 +170,7 @@
style="text-align: center;"
type="number"
value={config.max_output_tokens}
on:keydown={e => validateIntegerInput(e)}
on:change={e => changeMaxOutputToken(e)}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<FormGroup class="agent-prompt-body">
<div class="mb-2" style="display: flex; gap: 10px;">
<div class="line-align-center fw-bold">
{'Prompts:'}
{'Contents:'}
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
Expand Down
2 changes: 2 additions & 0 deletions src/routes/page/agent/[agentId]/agent-tabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
export let handleAgentChange = () => {};

export const fetchTabData = () => {
const llmConfig = agentLlmConfigCmp?.fetchLlmConfig();
const utilities = agentUtilityCmp?.fetchUtilities();
const knwoledgebases = agentKnowledgeBaseCmp?.fetchKnowledgeBases();
const rules = agentEventRuleCmp?.fetchRules();

return {
llmConfig,
utilities: utilities || [],
knwoledgebases: knwoledgebases || [],
rules: rules || []
Expand Down
4 changes: 2 additions & 2 deletions src/routes/page/knowledge-base/documents/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
import CollectionCreateModal from '../common/collection/collection-create-modal.svelte';
import AdvancedSearch from '../common/search/advanced-search.svelte';
import KnowledgeDocumentUpload from './knowledge-document-upload.svelte';
import { DECIMAL_REGEX } from '$lib/helpers/constants';

const pageSize = 8;
const duration = 2000;
const maxLength = 4096;
const step = 0.1;
const numberRegex = "[0-9\.]+";
const enableVector = true;
const collectionType = KnowledgeCollectionType.Document;
const includedPayloads = [
Expand Down Expand Up @@ -241,7 +241,7 @@

/** @param {any} e */
function validateConfidenceInput(e) {
var reg = new RegExp(numberRegex, 'g');
const reg = new RegExp(DECIMAL_REGEX, 'g');
if (e.key !== 'Backspace' && !reg.test(e.key)) {
e.preventDefault();
}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/page/knowledge-base/question-answer/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import VectorItem from '../common/vector-table/vector-item.svelte';
import VectorItemEditModal from '../common/vector-table/vector-item-edit-modal.svelte';
import CollectionCreateModal from '../common/collection/collection-create-modal.svelte';
import { DECIMAL_REGEX } from '$lib/helpers/constants';


const pageSize = 8;
const duration = 2000;
const maxLength = 4096;
const numberRegex = "[0-9\.]+";
const step = 0.1;
const enableVector = true;
const collectionType = KnowledgeCollectionType.QuestionAnswer;
Expand Down Expand Up @@ -218,7 +218,7 @@

/** @param {any} e */
function validateConfidenceInput(e) {
var reg = new RegExp(numberRegex, 'g');
const reg = new RegExp(DECIMAL_REGEX, 'g');
if (e.key !== 'Backspace' && !reg.test(e.key)) {
e.preventDefault();
}
Expand Down