Skip to content

Commit 6d91a16

Browse files
author
Jicheng Lu
committed
refine llm configs
1 parent 3de9387 commit 6d91a16

13 files changed

Lines changed: 782 additions & 191 deletions

File tree

src/lib/helpers/enums.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,34 @@ const globalEvent = {
203203
export const GlobalEvent = Object.freeze(globalEvent);
204204

205205
const llmModelType = {
206-
Text: 1,
207-
Chat: 2,
208-
Image: 3,
209-
Embedding: 4,
210-
Audio: 5
206+
All: "All",
207+
Text: "Text",
208+
Chat: "Chat",
209+
Image: "Image",
210+
Embedding: "Embedding",
211+
Audio: "Audio",
212+
Realtime: "Realtime",
213+
Web: "Web"
211214
};
212215
export const LlmModelType = Object.freeze(llmModelType);
213216

217+
const llmModelCapability = {
218+
All: "All",
219+
Text: "Text",
220+
Chat: "Chat",
221+
ImageReading: "ImageReading",
222+
ImageGeneration: "ImageGeneration",
223+
ImageEdit: "ImageEdit",
224+
ImageVariation: "ImageVariation",
225+
Embedding: "Embedding",
226+
AudioTranscription: "AudioTranscription",
227+
AudioGeneration: "AudioGeneration",
228+
Realtime: "Realtime",
229+
WebSearch: "WebSearch",
230+
PdfReading: "PdfReading"
231+
};
232+
export const LlmModelCapability = Object.freeze(llmModelCapability);
233+
214234
const reasoningEffortLevel = {
215235
Minimal: "minimal",
216236
Low: "low",

src/lib/helpers/types/agentTypes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
* @property {number} max_recursion_depth
1919
* @property {number?} [max_output_tokens]
2020
* @property {string?} [reasoning_effort_level]
21+
* @property {any} [image_generation]
22+
* @property {any} [image_edit]
23+
* @property {any} [audio_transcription]
24+
* @property {any} [realtime]
2125
*/
2226

2327

src/lib/helpers/types/commonTypes.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@
3939
*/
4040

4141
/**
42-
* @typedef {Object} LlmConfigOption
43-
* @property {number?} [type]
42+
* @typedef {Object} LlmConfigFilter
43+
* @property {string[]?} [providers]
44+
* @property {string[]?} [modelIds]
45+
* @property {string[]?} [modelNames]
46+
* @property {string[]?} [modelTypes]
47+
* @property {string[]?} [modelCapabilities]
4448
* @property {boolean?} [multiModal]
45-
* @property {boolean?} [imageGeneration]
4649
*/
4750

4851
/**
@@ -55,6 +58,8 @@
5558
* @typedef {Object} LlmModelSetting
5659
* @property {string} name
5760
* @property {string} type
61+
* @property {string[]} capabilities
62+
* @property {boolean} multiModal
5863
* @property {any} reasoning
5964
*/
6065

src/lib/scss/custom/pages/_agent.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,20 @@
143143
}
144144
}
145145

146+
.agent-config-container {
147+
padding: 10px;
148+
border: 1px dashed var(--bs-primary);
149+
border-radius: 5px;
150+
}
151+
146152
.agent-utility-container {
147153
display: flex;
148154
flex-direction: column;
149155
gap: 10px;
150156
max-height: 500px;
151157
overflow-y: auto;
152158
scrollbar-width: thin;
159+
padding: 0px 10px;
153160

154161
.merge-utility {
155162
display: flex;

src/lib/services/llm-provider-service.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { endpoints } from './api-endpoints.js';
22
import { replaceUrl } from '$lib/helpers/http.js';
33
import axios from 'axios';
4+
import qs from 'qs';
45

56
/**
67
* Get provider list
@@ -26,19 +27,15 @@ export async function getLlmProviderModels(provider) {
2627

2728
/**
2829
* Get llm configs
29-
* @param {import('$commonTypes').LlmConfigOption?} [options]
30+
* @param {import('$commonTypes').LlmConfigFilter?} [filter]
3031
* @returns {Promise<import('$commonTypes').LlmConfig[]>}
3132
*/
32-
export async function getLlmConfigs(options = null) {
33+
export async function getLlmConfigs(filter = null) {
3334
const url = endpoints.llmConfigsUrl;
35+
const params = filter != null ? { filter: filter } : null;
3436
const response = await axios.get(url, {
35-
params: {
36-
options: options
37-
},
38-
paramsSerializer: {
39-
dots: true,
40-
indexes: null,
41-
}
37+
params: params,
38+
paramsSerializer: (params) => qs.stringify(params, { encode: false, allowDots: true, arrayFormat: "indices" })
4239
});
4340
return response.data;
4441
}
Lines changed: 37 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
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;
@@ -12,195 +15,57 @@
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

Comments
 (0)