11<script >
22 import { onMount } from ' svelte' ;
3- import { Card , CardBody , Input } from ' @sveltestrap/sveltestrap' ;
4- import { getLlmProviders , getLlmProviderModels } from ' $lib/services/llm-provider-service' ;
5- import { INTEGER_REGEX } from ' $lib/helpers/constants' ;
6- import { ReasoningEffortLevel } from ' $lib/helpers/enums' ;
3+ import { Card , CardBody } from ' @sveltestrap/sveltestrap' ;
4+ import { getLlmConfigs } from ' $lib/services/llm-provider-service' ;
5+ import ChatConfig from ' ./llm-configs/chat-config.svelte' ;
6+ import ImageGenerationConfig from ' ./llm-configs/image-generation-config.svelte' ;
7+ import ImageEditConfig from ' ./llm-configs/image-edit-config.svelte' ;
8+ import AudioTranscriptionConfig from ' ./llm-configs/audio-transcription-config.svelte' ;
9+ import RealtimeConfig from ' ./llm-configs/realtime-config.svelte' ;
710
811 /** @type {import('$agentTypes').AgentModel} */
912 export let agent;
1215 export let handleAgentChange = () => {};
1316
1417 export const fetchLlmConfig = () => {
15- const reasoningEffort = models .find (x => x .name === config .model )? .reasoning != null ? config .reasoning_effort_level : null ;
18+ const chatConfig = chatConfigCmp? .fetchConfig ();
19+ const imageGenerationConfig = imageGenerationConfigCmp? .fetchConfig ();
20+ const imageEditConfig = imageEditConfigCmp? .fetchConfig ();
21+ const audioTranscriptionConfig = audioTranscriptionConfigCmp? .fetchConfig ();
22+ const realtimeConfig = realtimeConfigCmp? .fetchConfig ();
1623 return {
17- ... config,
18- max_output_tokens: Number (config .max_output_tokens ) > 0 ? Number (config .max_output_tokens ) : null ,
19- reasoning_effort_level: reasoningEffort
24+ ... chatConfig,
25+ image_generation: imageGenerationConfig ? {... imageGenerationConfig} : null ,
26+ image_edit: imageEditConfig ? {... imageEditConfig} : null ,
27+ audio_transcription: audioTranscriptionConfig ? {... audioTranscriptionConfig} : null ,
28+ realtime: realtimeConfig ? {... realtimeConfig} : null
2029 };
2130 }
2231
23- const recursiveDepthLowerLimit = 1 ;
32+ /** @type {any} */
33+ let chatConfigCmp;
34+ /** @type {any} */
35+ let imageGenerationConfigCmp;
36+ /** @type {any} */
37+ let imageEditConfigCmp;
38+ /** @type {any} */
39+ let audioTranscriptionConfigCmp;
40+ /** @type {any} */
41+ let realtimeConfigCmp;
2442
25- /** @type {import('$commonTypes').LabelValuePair[]} */
26- const reasonLevelOptions = [
27- { value: ' ' , label: ' ' },
28- ... Object .entries (ReasoningEffortLevel).map (([k , v ]) => ({
29- value: v,
30- label: v
31- }))
32- ];
33-
34- let config = agent .llm_config ;
35-
36- /** @type {string[]} */
37- let providers = [];
38-
39- /** @type {import('$commonTypes').LlmModelSetting[]} */
40- let models = [];
41-
42- $: isReasoningModel = models .find (x => x .name === config .model )? .reasoning != null ;
43+ /** @type {import('$commonTypes').LlmConfig[]} */
44+ let llmConfigs = [];
4345
4446 onMount (async () => {
4547 await init ();
4648 });
4749
4850 async function init () {
49- providers = await getLlmProviders ();
50- providers = [' ' , ... providers]
51- if (!! config .provider ) {
52- models = await getLlmProviderModels (config .provider );
53- }
54- const foundProvider = providers .find (x => x === config .provider );
55- const foundModel = models .find (x => x .name === config .model );
56- config .provider = foundProvider || null ;
57- config .model = foundModel? .name || null ;
58- }
59-
60-
61-
62- /** @param {any} e */
63- async function changeProvider (e ) {
64- const provider = e .target .value ;
65- config .provider = provider || null ;
66-
67- if (!!! provider) {
68- models = [];
69- config .model = null ;
70- config .reasoning_effort_level = null ;
71- handleAgentChange ();
72- return ;
73- }
74-
75- config .is_inherit = false ;
76- models = await getLlmProviderModels (provider);
77- config .model = models[0 ]? .name ;
78- handleAgentChange ();
79- }
80-
81- /** @param {any} e */
82- function changeModel (e ) {
83- config .is_inherit = false ;
84- config .model = e .target .value || null ;
85- handleAgentChange ();
86- }
87-
88- /** @param {any} e */
89- function changeMaxRecursiveDepth (e ) {
90- let value = Number (e .target .value ) || 0 ;
51+ llmConfigs = await getLlmConfigs ();
9152
92- if (value < recursiveDepthLowerLimit) {
93- value = recursiveDepthLowerLimit;
94- }
95-
96- config .max_recursion_depth = value;
97- handleAgentChange ();
98- }
99-
100- /** @param {any} e */
101- function changeMaxOutputToken (e ) {
102- const value = Number (e .target .value ) || 0 ;
103- config .max_output_tokens = value;
104- handleAgentChange ();
105- }
106-
107- /** @param {any} e */
108- function changeReasoningEffortLevel (e ) {
109- config .reasoning_effort_level = e .target .value || null ;
110- handleAgentChange ();
111- }
112-
113- /** @param {any} e */
114- function validateIntegerInput (e ) {
115- const reg = new RegExp (INTEGER_REGEX , ' g' );
116- if (e .key !== ' Backspace' && ! reg .test (e .key )) {
117- e .preventDefault ();
118- }
11953 }
12054< / script>
12155
12256< Card>
12357 < CardBody>
12458 < div class = " text-center" >
125- < h5 class = " mt-1 mb-3 " > LLM Config < / h5>
59+ < h5 class = " mt-1 mb-1 " > LLM Configurations < / h5>
12660 < img src= " images/brands/azure-openai-logo.avif" alt= " " height= " 50" / >
127- {#if agent .llm_config ? .is_inherit }
128- < i class = " bx bx-copy" >< / i> < span class = " text-muted" > Inherited< / span>
129- {/ if }
130- < / div>
131-
132- < div class = " mb-3 row" >
133- < label for = " example-large" class = " col-md-3 col-form-label" >
134- Provider
135- < / label>
136- < div class = " col-md-9 config-item-container" >
137- < Input type= " select" value= {config .provider } on: change= {e => changeProvider (e)}>
138- {#each providers as option}
139- < option value= {option} selected= {option == config .provider }> {option}< / option>
140- {/ each}
141- < / Input>
142- < / div>
143- < / div>
144-
145- < div class = " mb-3 row" >
146- < label for = " example-text-input" class = " col-md-3 col-form-label" >
147- Model
148- < / label>
149- < div class = " col-md-9" >
150- < Input type= " select" value= {config .model } disabled= {models .length === 0 } on: change= {e => changeModel (e)}>
151- {#each models as option}
152- < option value= {option .name } selected= {option .name == config .model }> {option .name }< / option>
153- {/ each}
154- < / Input>
155- < / div>
156- < / div>
157-
158- < div class = " mb-3 row" >
159- < label for = " example-text-input" class = " col-md-3 col-form-label" >
160- Max recursive depth
161- < / label>
162- < div class = " col-md-9" >
163- < Input
164- style= " text-align: center;"
165- type= " number"
166- min= {recursiveDepthLowerLimit}
167- value= {config .max_recursion_depth }
168- on: keydown= {e => validateIntegerInput (e)}
169- on: change= {e => changeMaxRecursiveDepth (e)}
170- / >
171- < / div>
172- < / div>
173-
174- < div class = " mb-3 row" >
175- < label for = " example-text-input" class = " col-md-3 col-form-label" >
176- Max output tokens
177- < / label>
178- < div class = " col-md-9" >
179- < Input
180- style= " text-align: center;"
181- type= " number"
182- value= {config .max_output_tokens }
183- on: keydown= {e => validateIntegerInput (e)}
184- on: change= {e => changeMaxOutputToken (e)}
185- / >
186- < / div>
18761 < / div>
18862
189- {#if isReasoningModel}
190- < div class = " mb-3 row" >
191- < label for = " example-text-input" class = " col-md-3 col-form-label" >
192- Reasoning effort
193- < / label>
194- < div class = " col-md-9" >
195- < Input type= " select" value= {config .reasoning_effort_level } on: change= {e => changeReasoningEffortLevel (e)}>
196- {#each reasonLevelOptions as option}
197- < option value= {option .value } selected= {option .value == config .reasoning_effort_level }>
198- {option .label }
199- < / option>
200- {/ each}
201- < / Input>
202- < / div>
63+ < div class = " agent-utility-container" >
64+ < ChatConfig bind: this = {chatConfigCmp} {agent} {llmConfigs} {handleAgentChange} / >
65+ < ImageGenerationConfig bind: this = {imageGenerationConfigCmp} {agent} {llmConfigs} {handleAgentChange} / >
66+ < ImageEditConfig bind: this = {imageEditConfigCmp} {agent} {llmConfigs} {handleAgentChange} / >
67+ < AudioTranscriptionConfig bind: this = {audioTranscriptionConfigCmp} {agent} {llmConfigs} {handleAgentChange} / >
68+ < RealtimeConfig bind: this = {realtimeConfigCmp} {agent} {llmConfigs} {handleAgentChange} / >
20369 < / div>
204- {/ if }
20570 < / CardBody>
20671< / Card>
0 commit comments