Spaces:
Runtime error
Runtime error
hello world with system prompt
Browse files
src/lib/JsonEditor/JsonEditor.svelte
CHANGED
|
@@ -6,9 +6,13 @@
|
|
| 6 |
import { linter, lintGutter, type Diagnostic } from '@codemirror/lint';
|
| 7 |
import LineWrapButton from '$lib/LineWrapButton/LineWrapButton.svelte';
|
| 8 |
import JSON5 from 'json5';
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
export let content: Record<string, unknown> = {};
|
| 11 |
export let error = '';
|
|
|
|
| 12 |
|
| 13 |
let value = JSON5.stringify(content, null, 2);
|
| 14 |
|
|
@@ -98,6 +102,17 @@
|
|
| 98 |
return diagnostics;
|
| 99 |
};
|
| 100 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
</script>
|
| 102 |
|
| 103 |
<div class="h-full overflow-scroll bg-white dark:bg-gray-900">
|
|
|
|
| 6 |
import { linter, lintGutter, type Diagnostic } from '@codemirror/lint';
|
| 7 |
import LineWrapButton from '$lib/LineWrapButton/LineWrapButton.svelte';
|
| 8 |
import JSON5 from 'json5';
|
| 9 |
+
import type { FormattedChatTemplate } from '../ChatTemplateViewer/types';
|
| 10 |
+
import { getExampleHelloWorld } from '$lib/example-inputs/helloWorld';
|
| 11 |
+
import { onMount } from 'svelte';
|
| 12 |
|
| 13 |
export let content: Record<string, unknown> = {};
|
| 14 |
export let error = '';
|
| 15 |
+
export let selectedTemplate: FormattedChatTemplate | undefined = undefined;
|
| 16 |
|
| 17 |
let value = JSON5.stringify(content, null, 2);
|
| 18 |
|
|
|
|
| 102 |
return diagnostics;
|
| 103 |
};
|
| 104 |
}
|
| 105 |
+
|
| 106 |
+
onMount(() => {
|
| 107 |
+
if (selectedTemplate) {
|
| 108 |
+
console.log('or here');
|
| 109 |
+
const exampleHelloWorld = getExampleHelloWorld(selectedTemplate.template);
|
| 110 |
+
if (exampleHelloWorld) {
|
| 111 |
+
content = exampleHelloWorld;
|
| 112 |
+
value = JSON5.stringify(content, null, 2);
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
});
|
| 116 |
</script>
|
| 117 |
|
| 118 |
<div class="h-full overflow-scroll bg-white dark:bg-gray-900">
|
src/lib/example-inputs/helloWorld.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Template } from '@huggingface/jinja';
|
| 2 |
+
|
| 3 |
+
const variations = {
|
| 4 |
+
variation1_with_system_prompt: {
|
| 5 |
+
description: 'Variation with system prompt',
|
| 6 |
+
example: {
|
| 7 |
+
messages: [
|
| 8 |
+
{
|
| 9 |
+
role: 'system',
|
| 10 |
+
content: 'You are a helpful assistant.'
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
role: 'user',
|
| 14 |
+
content: 'Hello, how are you?'
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
role: 'assistant',
|
| 18 |
+
content: "I'm doing great. How can I help you today?"
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
role: 'user',
|
| 22 |
+
content: 'Can you tell me a joke?'
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
add_generation_prompt: true
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
variation2_without_system_prompt: {
|
| 29 |
+
description: 'Variation without system prompt',
|
| 30 |
+
example: {
|
| 31 |
+
messages: [
|
| 32 |
+
{
|
| 33 |
+
role: 'user',
|
| 34 |
+
content: 'Hello, how are you?'
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
role: 'assistant',
|
| 38 |
+
content: "I'm doing great. How can I help you today?"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
role: 'user',
|
| 42 |
+
content: 'Can you tell me a joke?'
|
| 43 |
+
}
|
| 44 |
+
],
|
| 45 |
+
add_generation_prompt: true
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
export function getExampleHelloWorld(templateStr: string): Record<string, unknown> | undefined {
|
| 51 |
+
const template = new Template(templateStr);
|
| 52 |
+
const variationSystemPrompt = variations.variation1_with_system_prompt.example;
|
| 53 |
+
const variationSystemPromptRendered = template.render(variationSystemPrompt);
|
| 54 |
+
if (variationSystemPromptRendered.includes('You are a helpful assistant.')) {
|
| 55 |
+
return variations.variation1_with_system_prompt.example;
|
| 56 |
+
}
|
| 57 |
+
return variations.variation2_without_system_prompt.example;
|
| 58 |
+
}
|
src/routes/+page.svelte
CHANGED
|
@@ -254,10 +254,12 @@
|
|
| 254 |
class="relative flex h-full flex-col bg-gray-100"
|
| 255 |
style="width: {100 - leftWidth}%"
|
| 256 |
>
|
| 257 |
-
|
| 258 |
-
<
|
| 259 |
-
|
| 260 |
-
|
|
|
|
|
|
|
| 261 |
|
| 262 |
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 263 |
<div
|
|
|
|
| 254 |
class="relative flex h-full flex-col bg-gray-100"
|
| 255 |
style="width: {100 - leftWidth}%"
|
| 256 |
>
|
| 257 |
+
{#key `${modelId}-${selectedTemplate?.name}`}
|
| 258 |
+
<div class="w-full" style="height: {topHeight}%">
|
| 259 |
+
<!-- Right top pane -->
|
| 260 |
+
<JsonEditor bind:error bind:content={input} bind:selectedTemplate />
|
| 261 |
+
</div>
|
| 262 |
+
{/key}
|
| 263 |
|
| 264 |
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 265 |
<div
|