diff --git a/ui-svelte/src/components/playground/RerankInterface.svelte b/ui-svelte/src/components/playground/RerankInterface.svelte new file mode 100644 index 00000000..40ab8957 --- /dev/null +++ b/ui-svelte/src/components/playground/RerankInterface.svelte @@ -0,0 +1,406 @@ + + +
+ +
+ + {#if editorMode === "table"} + + {/if} + +
+ + +
+
+ + {#if !hasModels} +
+

No models configured. Add models to your configuration to use reranking.

+
+ {:else if editorMode === "json"} + +
+ + {#if jsonError} +

{jsonError}

+ {/if} +
+ {:else} + +
+ + + + + + + + + + + + + + + {#each displayRows as { row, i } (i)} + + + + + + {/each} + +
Document + Score{sortIndicator()} +
+ updateDoc(i, (e.target as HTMLInputElement).value)} + disabled={isLoading} + onkeydown={handleKeyDown} + /> + + {#if isLoading && row.score === null && row.doc.trim() !== ""} + + {:else} + {formatScore(row.score)} + {/if} + + +
+
+ {/if} + + + {#if hasModels} +
+ {#if isLoading} + + {:else} + + + {/if} + + {#if error} + {error} + {:else if usage} + {usage.total_tokens} tokens + {/if} +
+ {/if} +
diff --git a/ui-svelte/src/lib/rerankApi.ts b/ui-svelte/src/lib/rerankApi.ts new file mode 100644 index 00000000..27614841 --- /dev/null +++ b/ui-svelte/src/lib/rerankApi.ts @@ -0,0 +1,27 @@ +export interface RerankResult { + index: number; + relevance_score: number; +} + +export interface RerankResponse { + model: string; + object: string; + usage: { prompt_tokens: number; total_tokens: number }; + results: RerankResult[]; +} + +export async function rerank( + model: string, + query: string, + documents: string[], + signal: AbortSignal +): Promise { + const response = await fetch("/v1/rerank", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ model, query, documents }), + signal, + }); + if (!response.ok) throw new Error(`${response.status} ${response.statusText}`); + return response.json(); +} diff --git a/ui-svelte/src/routes/Playground.svelte b/ui-svelte/src/routes/Playground.svelte index 4acc0c1a..561cff7a 100644 --- a/ui-svelte/src/routes/Playground.svelte +++ b/ui-svelte/src/routes/Playground.svelte @@ -4,8 +4,9 @@ import ImageInterface from "../components/playground/ImageInterface.svelte"; import AudioInterface from "../components/playground/AudioInterface.svelte"; import SpeechInterface from "../components/playground/SpeechInterface.svelte"; + import RerankInterface from "../components/playground/RerankInterface.svelte"; - type Tab = "chat" | "images" | "speech" | "audio"; + type Tab = "chat" | "images" | "speech" | "audio" | "rerank"; const selectedTabStore = persistentStore("playground-selected-tab", "chat"); let mobileMenuOpen = $state(false); @@ -15,6 +16,7 @@ { id: "images", label: "Images" }, { id: "speech", label: "Speech" }, { id: "audio", label: "Transcription" }, + { id: "rerank", label: "Rerank" }, ]; function selectTab(tab: Tab) { @@ -89,6 +91,9 @@
+
+ +
diff --git a/ui-svelte/src/stores/playgroundActivity.ts b/ui-svelte/src/stores/playgroundActivity.ts index d7f6ed99..ad067684 100644 --- a/ui-svelte/src/stores/playgroundActivity.ts +++ b/ui-svelte/src/stores/playgroundActivity.ts @@ -4,10 +4,11 @@ const chatStreaming = writable(false); const imageGenerating = writable(false); const speechGenerating = writable(false); const audioTranscribing = writable(false); +const rerankLoading = writable(false); export const playgroundActivity = derived( - [chatStreaming, imageGenerating, speechGenerating, audioTranscribing], - ([$chat, $image, $speech, $audio]) => $chat || $image || $speech || $audio + [chatStreaming, imageGenerating, speechGenerating, audioTranscribing, rerankLoading], + ([$chat, $image, $speech, $audio, $rerank]) => $chat || $image || $speech || $audio || $rerank ); export const playgroundStores = { @@ -15,4 +16,5 @@ export const playgroundStores = { imageGenerating, speechGenerating, audioTranscribing, + rerankLoading, };