|
3 | 3 | import { fly } from 'svelte/transition'; |
4 | 4 | import { _ } from 'svelte-i18n'; |
5 | 5 | import util from "lodash"; |
6 | | - import { Button, Card, CardBody, Col, Row } from '@sveltestrap/sveltestrap'; |
| 6 | + import { Button, Card, CardBody, Col, Row, Tooltip } from '@sveltestrap/sveltestrap'; |
7 | 7 | import LoadingDots from '$lib/common/LoadingDots.svelte'; |
8 | 8 | import HeadTitle from '$lib/common/HeadTitle.svelte'; |
9 | 9 | import Breadcrumb from '$lib/common/Breadcrumb.svelte'; |
10 | 10 | import Markdown from '$lib/common/markdown/Markdown.svelte'; |
11 | 11 | import InstructionState from '../instruction-components/instruction-state.svelte'; |
12 | 12 | import { getAgents } from '$lib/services/agent-service'; |
13 | 13 | import LoadingToComplete from '$lib/common/LoadingToComplete.svelte'; |
14 | | - import { sendChatCompletion } from '$lib/services/instruct-service'; |
| 14 | + import { executeAgentInstruction } from '$lib/services/instruct-service'; |
15 | 15 | import { getLlmConfigs } from '$lib/services/llm-provider-service'; |
16 | 16 | import { LlmModelType } from '$lib/helpers/enums'; |
17 | 17 | import NavBar from '$lib/common/nav-bar/NavBar.svelte'; |
18 | 18 | import NavItem from '$lib/common/nav-bar/NavItem.svelte'; |
19 | | - import InstructionTemplate from '../instruction-components/instruction-template.svelte'; |
| 19 | + import InstructionAgent from '../instruction-components/instruction-agent.svelte'; |
20 | 20 | import InstructionLlm from '../instruction-components/instruction-llm.svelte'; |
21 | 21 |
|
22 | 22 | const maxLength = 64000; |
|
25 | 25 |
|
26 | 26 | /** @type {any[]}*/ |
27 | 27 | const tabs = [ |
28 | | - { name: 'instruction-template', displayText: 'Template' }, |
| 28 | + { name: 'instruction-agent', displayText: 'Agent' }, |
29 | 29 | { name: 'instruction-llm', displayText: 'LLM Config' }, |
30 | 30 | { name: 'instruction-states', displayText: 'States' } |
31 | 31 | ]; |
32 | 32 |
|
33 | 33 | let isLoading = false; |
| 34 | + let isError = false; |
34 | 35 | let isThinking = false; |
35 | 36 | let requestDone = false; |
36 | 37 | |
37 | 38 | let text = ''; |
38 | 39 | let instruction = ''; |
39 | 40 | let result = ''; |
40 | 41 | let elapsedTime = ''; |
| 42 | + let errorText = 'Please select an agent to proceed!'; |
41 | 43 |
|
42 | 44 | /** @type {import('$agentTypes').AgentModel | null} */ |
43 | 45 | let selectedAgent = null; |
|
79 | 81 | }); |
80 | 82 |
|
81 | 83 | function sendRequest() { |
| 84 | + if (!selectedAgent) { |
| 85 | + isError = true; |
| 86 | + errorText = 'Please select an agent to proceed!'; |
| 87 | + setTimeout(() => { |
| 88 | + isError = false; |
| 89 | + errorText = ''; |
| 90 | + }, 1500); |
| 91 | + return; |
| 92 | + } |
| 93 | +
|
82 | 94 | isThinking = true; |
83 | 95 | requestDone = false; |
84 | 96 | elapsedTime = ''; |
85 | 97 | const formattedStates = formatStates(states); |
86 | 98 | const start = new Date(); |
87 | | - sendChatCompletion({ |
| 99 | + const agentId = selectedAgent?.id || ''; |
| 100 | + executeAgentInstruction(agentId, { |
88 | 101 | text: util.trim(text) || '', |
89 | | - instruction: util.trim(instruction) || null, |
90 | | - agentId: selectedAgent?.id, |
91 | | - provider: selectedProvider?.provider || DEFAULT_PROVIDER, |
92 | | - model: selectedModel || DEFAULT_MODEL, |
| 102 | + instruction: '#TEMPLATE#', |
| 103 | + provider: selectedProvider?.provider, |
| 104 | + model: selectedModel, |
93 | 105 | template: selectedTemplate, |
94 | 106 | states: formattedStates |
95 | 107 | }).then(res => { |
96 | | - result = res || ''; |
| 108 | + result = res?.text || ''; |
97 | 109 | }).finally(() => { |
98 | 110 | isThinking = false; |
99 | 111 | requestDone = true; |
|
167 | 179 |
|
168 | 180 | <HeadTitle title="{$_('Instruction')}" /> |
169 | 181 | <Breadcrumb pagetitle="{$_('Testing')}" title="{$_('Instruction')}"/> |
170 | | -<LoadingToComplete isLoading={isLoading} /> |
| 182 | +<LoadingToComplete isLoading={isLoading} isError={isError} errorText={errorText} /> |
171 | 183 |
|
172 | 184 | <div class="d-xl-flex"> |
173 | 185 | <div class="w-100"> |
|
244 | 256 | <div class="line-align-center"> |
245 | 257 | <!-- svelte-ignore a11y-click-events-have-key-events --> |
246 | 258 | <!-- svelte-ignore a11y-no-static-element-interactions --> |
247 | | - <i |
| 259 | + <!-- <i |
248 | 260 | class="mdi mdi-refresh text-primary clickable" |
249 | 261 | data-bs-toggle="tooltip" |
250 | 262 | data-bs-placement="bottom" |
251 | 263 | title={'Reset'} |
252 | 264 | on:click={e => resetInstruction()} |
253 | | - /> |
| 265 | + /> --> |
| 266 | + <div class="demo-tooltip-icon line-align-center" id="demo-tooltip"> |
| 267 | + <i class="bx bx-info-circle" /> |
| 268 | + </div> |
| 269 | + <Tooltip target="demo-tooltip" placement="right" class="demo-tooltip-note"> |
| 270 | + <div>Please select an agent to proceed!</div> |
| 271 | + </Tooltip> |
254 | 272 | </div> |
255 | 273 | </div> |
256 | 274 | </Col> |
|
264 | 282 | class='form-control knowledge-textarea' |
265 | 283 | rows={19} |
266 | 284 | maxlength={maxLength} |
267 | | - disabled={isThinking} |
268 | | - placeholder={'Enter instruction...'} |
| 285 | + disabled |
| 286 | + placeholder={''} |
269 | 287 | bind:value={instruction} |
270 | 288 | /> |
271 | | - <div class="text-secondary text-end text-count"> |
| 289 | + <!-- <div class="text-secondary text-end text-count"> |
272 | 290 | <div>{instruction?.length || 0}/{maxLength}</div> |
273 | | - </div> |
| 291 | + </div> --> |
274 | 292 | </div> |
275 | 293 | </div> |
276 | 294 | </Col> |
277 | 295 | <Col lg="5" class="instruction-gap"> |
278 | 296 | <Card> |
279 | 297 | <CardBody> |
280 | | - |
281 | 298 | <NavBar |
282 | 299 | id={'instruction-nav-container'} |
283 | 300 | disableDefaultStyles |
|
297 | 314 | {/each} |
298 | 315 | </NavBar> |
299 | 316 | |
300 | | - <div class:hide={selectedTab !== 'instruction-template'}> |
301 | | - <InstructionTemplate |
| 317 | + <div class:hide={selectedTab !== 'instruction-agent'}> |
| 318 | + <InstructionAgent |
302 | 319 | agents={agents} |
303 | 320 | disabled={isThinking} |
304 | | - on:agentSelected={e => onAgentSelected(e)} |
| 321 | + on:selectAgent={e => onAgentSelected(e)} |
305 | 322 | /> |
306 | 323 | </div> |
307 | 324 | <div class:hide={selectedTab !== 'instruction-llm'}> |
|
310 | 327 | disabled={isThinking} |
311 | 328 | selectedProvider={selectedProvider} |
312 | 329 | selectedModel={selectedModel} |
313 | | - on:llmSelected={e => onLlmSelected(e)} |
| 330 | + on:selectLlm={e => onLlmSelected(e)} |
314 | 331 | /> |
315 | 332 | </div> |
316 | 333 | <div class:hide={selectedTab !== 'instruction-states'}> |
|
0 commit comments