Skip to content

Commit 1e64080

Browse files
committed
feat: get the inference provider from a registered store
Signed-off-by: Brian <[email protected]>
1 parent 40c4b40 commit 1e64080

File tree

7 files changed

+54
-14
lines changed

7 files changed

+54
-14
lines changed

packages/backend/src/studio-api-impl.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import type { RecipeManager } from './managers/recipes/RecipeManager';
4343
import type { PodmanConnection } from './managers/podmanConnection';
4444
import type { NavigationRegistry } from './registries/NavigationRegistry';
4545
import type { RpcExtension } from '@shared/messages/MessageProxy';
46+
import type { InferenceProviderRegistry } from './registries/InferenceProviderRegistry';
4647

4748
vi.mock('./ai.json', () => {
4849
return {
@@ -148,6 +149,7 @@ beforeEach(async () => {
148149
localRepositoryRegistry,
149150
{} as unknown as TaskRegistry,
150151
{} as unknown as InferenceManager,
152+
{} as unknown as InferenceProviderRegistry,
151153
{} as unknown as PlaygroundV2Manager,
152154
{} as unknown as SnippetManager,
153155
{} as unknown as CancellationTokenRegistry,

packages/backend/src/studio-api-impl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import path from 'node:path';
3333
import type { InferenceServer } from '@shared/models/IInference';
3434
import type { CreationInferenceServerOptions } from '@shared/models/InferenceServerConfig';
3535
import type { InferenceManager } from './managers/inference/inferenceManager';
36+
import type { InferenceProviderRegistry } from './registries/InferenceProviderRegistry';
3637
import type { Conversation } from '@shared/models/IPlaygroundMessage';
3738
import type { PlaygroundV2Manager } from './managers/playgroundV2Manager';
3839
import { getFreeRandomPort } from './utils/ports';
@@ -72,6 +73,7 @@ export class StudioApiImpl implements StudioAPI {
7273
private localRepositories: LocalRepositoryRegistry,
7374
private taskRegistry: TaskRegistry,
7475
private inferenceManager: InferenceManager,
76+
private InferenceProviderRegistry: InferenceProviderRegistry,
7577
private playgroundV2: PlaygroundV2Manager,
7678
private snippetManager: SnippetManager,
7779
private cancellationTokenRegistry: CancellationTokenRegistry,
@@ -144,6 +146,10 @@ export class StudioApiImpl implements StudioAPI {
144146
return this.inferenceManager.getServers();
145147
}
146148

149+
async getProviders(): Promise<string[]> {
150+
return this.InferenceProviderRegistry.getAll().map(provider => provider.type);
151+
}
152+
147153
async requestDeleteInferenceServer(...containerIds: string[]): Promise<void> {
148154
// Do not wait on the promise as the api would probably timeout before the user answer.
149155
if (containerIds.length === 0) throw new Error('At least one container id should be provided.');

packages/backend/src/studio.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ export class Studio {
398398
this.#localRepositoryRegistry,
399399
this.#taskRegistry,
400400
this.#inferenceManager,
401+
this.#inferenceProviderRegistry,
401402
this.#playgroundManager,
402403
this.#snippetManager,
403404
this.#cancellationTokenRegistry,
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
<script lang="ts">
22
import Select from '/@/lib/select/Select.svelte';
3-
import { InferenceType } from '@shared/models/IInference';
3+
import { inferenceProviders } from '/@/stores/inferenceProviders';
44
55
interface Props {
66
disabled?: boolean;
7-
value: InferenceType | undefined;
8-
exclude?: InferenceType[];
7+
value: string | undefined;
8+
exclude?: string[];
99
}
1010
let { value = $bindable(), disabled, exclude = [] }: Props = $props();
1111
12-
// Filter options based on optional exclude list
13-
const options = Object.values(InferenceType).filter(type => type !== InferenceType.NONE && !exclude.includes(type));
12+
// Create a derived store for providerOptions filtering by exclude and enabled
13+
let providerOptions = $derived(() => {
14+
return $inferenceProviders
15+
.filter(name => !exclude.includes(name))
16+
.map(name => ({
17+
value: name,
18+
label: name,
19+
}));
20+
});
1421
1522
function handleOnChange(nValue: { value: string } | undefined): void {
1623
if (nValue) {
17-
value = nValue.value as InferenceType;
24+
value = nValue.value;
1825
} else {
1926
value = undefined;
2027
}
2128
}
2229
</script>
2330

2431
<Select
25-
label="Select Inference Runtime"
26-
name="select-inference-runtime"
32+
label="Select Inference Provider"
33+
name="select-inference-provider"
2734
disabled={disabled}
2835
value={value ? { label: value, value: value } : undefined}
2936
onchange={handleOnChange}
30-
placeholder="Select Inference Runtime to use"
31-
items={options.map(type => ({
32-
value: type,
33-
label: type,
34-
}))} />
37+
placeholder="Select Inference Provider to use"
38+
items={providerOptions()} />

packages/frontend/src/pages/PlaygroundCreate.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let trackingId: string | undefined = undefined;
3636
// The trackedTasks are the tasks linked to the trackingId
3737
let trackedTasks: Task[] = [];
3838
39-
// Preset model selection
39+
// Preset model selection depending on runtime
4040
$: if (localModels.length > 0) {
4141
model = localModels[0];
4242
} else {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**********************************************************************
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
import { RPCReadable } from '/@/stores/rpcReadable';
19+
import { MSG_INFERENCE_PROVIDER_UPDATE } from '@shared/Messages';
20+
import { studioClient } from '/@/utils/client';
21+
22+
export const inferenceProviders = RPCReadable<string[]>([], MSG_INFERENCE_PROVIDER_UPDATE, studioClient.getProviders);

packages/shared/src/StudioAPI.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ export interface StudioAPI {
121121
*/
122122
getInferenceServers(): Promise<InferenceServer[]>;
123123

124+
/**
125+
* Get inference providers
126+
*/
127+
getProviders(): Promise<string[]>;
128+
124129
/**
125130
* Request to start an inference server
126131
* @param options The options to use

0 commit comments

Comments
 (0)