File size: 1,535 Bytes
6426ece
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Template } from '@huggingface/jinja';
import { transformInput } from '$lib/utils/transformInput';

const variations = {
	variation1_with_system_prompt: {
		description: 'Variation with system prompt',
		example: {
			messages: [
				{
					role: 'system',
					content: 'You are a helpful assistant.'
				},
				{
					role: 'user',
					content: 'Hello, how are you?'
				},
				{
					role: 'assistant',
					content: "I'm doing great. How can I help you today?"
				},
				{
					role: 'user',
					content: 'Can you tell me a joke?'
				}
			],
			add_generation_prompt: true
		}
	},
	variation2_without_system_prompt: {
		description: 'Variation without system prompt',
		example: {
			messages: [
				{
					role: 'user',
					content: 'Hello, how are you?'
				},
				{
					role: 'assistant',
					content: "I'm doing great. How can I help you today?"
				},
				{
					role: 'user',
					content: 'Can you tell me a joke?'
				}
			],
			add_generation_prompt: true
		}
	}
};

export function getExampleHelloWorld(templateStr: string): Record<string, unknown> | undefined {
	const template = new Template(templateStr);
	const variationSystemPrompt = variations.variation1_with_system_prompt.example;
	const variationSystemPromptRendered = template.render(
		transformInput(variationSystemPrompt, templateStr)
	);
	if (variationSystemPromptRendered.includes('You are a helpful assistant.')) {
		return variations.variation1_with_system_prompt.example;
	}
	return variations.variation2_without_system_prompt.example;
}