File size: 5,300 Bytes
b1426d3
b924465
97c4991
1778c9e
b924465
58843c4
9b4caaa
899d9c6
9b4caaa
b924465
 
c670717
b924465
 
 
 
 
1778c9e
b924465
97c4991
 
 
 
 
c670717
97c4991
 
f415c95
97c4991
 
b924465
b34bca6
b924465
 
 
c670717
 
 
b924465
 
 
 
 
 
 
 
 
 
 
 
97c4991
 
 
 
 
 
f36471e
 
1778c9e
97c4991
 
b924465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b34bca6
b924465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b34bca6
b924465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
058d10c
b924465
f48efbb
f36471e
 
 
 
 
f48efbb
19d1d46
 
1778c9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import type { GenerationConfig } from "$lib/components/inference-playground/generation-config-settings.js";
import type { ChatCompletionInputMessage } from "@huggingface/tasks";
import typia from "typia";
import type { ConversationEntityMembers } from "./state/conversations.svelte";

export type ConversationMessage = Pick<ChatCompletionInputMessage, "name" | "role"> & {
	content?: string;
	images?: string[];
};

export type Conversation = {
	model: Model | CustomModel;
	config: GenerationConfig;
	messages: ConversationMessage[];
	systemMessage: ConversationMessage;
	streaming: boolean;
	provider?: string;
} & Pick<ConversationEntityMembers, "structuredOutput">;

export type ConversationWithCustomModel = Conversation & {
	model: CustomModel;
};

export type ConversationWithHFModel = Conversation & {
	model: Model;
};

export const isHFModel = typia.createIs<Model>();
export const isCustomModel = typia.createIs<CustomModel>();

interface TokenizerConfig {
	chat_template?: string | Array<{ name: string; template: string }>;
	model_max_length?: number;
}

// export type ModelWithTokenizer = Model & {
// 	tokenizerConfig: TokenizerConfig;
// };

export type Model = {
	_id: string;
	id: string;
	inferenceProviderMapping: InferenceProviderMapping[];
	trendingScore: number;
	config: Config;
	tags: string[];
	pipeline_tag: PipelineTag;
	library_name?: LibraryName;
};

export type CustomModel = {
	id: string;
	/** UUID */
	_id: string;
	endpointUrl: string;
	accessToken?: string;
	/** @default "text-generation" */
	pipeline_tag?: PipelineTag;
	supports_response_schema?: boolean;
};

export type Config = {
	architectures: string[];
	model_type: string;
	tokenizer_config: TokenizerConfig;
	auto_map?: AutoMap;
	quantization_config?: QuantizationConfig;
};

export type AutoMap = {
	AutoConfig: string;
	AutoModel?: string;
	AutoModelForCausalLM: string;
	AutoModelForSequenceClassification?: string;
	AutoModelForTokenClassification?: string;
	AutoModelForQuestionAnswering?: string;
};

export type QuantizationConfig = {
	quant_method: string;
	bits?: number;
};

// export type TokenizerConfig = {
// 	bos_token?: Token | BosTokenEnum | null;
// 	chat_template: ChatTemplateElement[] | string;
// 	eos_token: Token | EOSTokenEnum;
// 	pad_token?: Token | null | string;
// 	unk_token?: Token | UnkTokenEnum | null;
// 	use_default_system_prompt?: boolean;
// };

export type Token = {
	__type: Type;
	content: Content;
	lstrip: boolean;
	normalized: boolean;
	rstrip: boolean;
	single_word: boolean;
};

export enum Type {
	AddedToken = "AddedToken",
}

export enum Content {
	BeginOfSentence = "<|begin▁of▁sentence|>",
	ContentS = "</s>",
	EndOfSentence = "<|end▁of▁sentence|>",
	S = "<s>",
	Unk = "<unk>",
}

export enum BosTokenEnum {
	BeginOfText = "<|begin_of_text|>",
	Bos = "<bos>",
	BosToken = "<BOS_TOKEN>",
	Endoftext = "<|endoftext|>",
	IMStart = "<|im_start|>",
	S = "<s>",
	Startoftext = "<|startoftext|>",
}

export type ChatTemplateElement = {
	name: string;
	template: string;
};

export enum EOSTokenEnum {
	EOS = "<eos>",
	EndOfText = "<|end_of_text|>",
	EndOfTurnToken = "<|END_OF_TURN_TOKEN|>",
	Endoftext = "<|endoftext|>",
	EotID = "<|eot_id|>",
	IMEnd = "<|im_end|>",
	S = "</s>",
}

export enum UnkTokenEnum {
	Endoftext = "<|endoftext|>",
	Unk = "<unk>",
}

export type InferenceProviderMapping = {
	provider: string;
	providerId: string;
	status: Status;
	task: Task;
};

export enum Provider {
	Cerebras = "cerebras",
	FalAI = "fal-ai",
	FireworksAI = "fireworks-ai",
	HFInference = "hf-inference",
	Hyperbolic = "hyperbolic",
	Nebius = "nebius",
	Novita = "novita",
	Replicate = "replicate",
	Sambanova = "sambanova",
	Together = "together",
	Cohere = "cohere",
}

export enum Status {
	Live = "live",
	Staging = "staging",
}

export enum Task {
	Conversational = "conversational",
}

export enum LibraryName {
	Mlx = "mlx",
	Transformers = "transformers",
	Vllm = "vllm",
}

export enum PipelineTag {
	TextGeneration = "text-generation",
	ImageTextToText = "image-text-to-text",
}

export const pipelineTagLabel: Record<PipelineTag, string> = {
	[PipelineTag.TextGeneration]: "Text→Text",
	[PipelineTag.ImageTextToText]: "Image+Text→Text",
};

export type MaybeGetter<T> = T | (() => T);

export type ValueOf<T> = T[keyof T];

export interface GenerationStatistics {
	latency: number;
	tokens: number;
}

export type ModelsJson = {
	[modelId: string]: ModelJsonSpec;
};

export interface ModelJsonSpec {
	max_tokens?: number;
	max_input_tokens?: number;
	max_output_tokens?: number;
	input_cost_per_token?: number;
	output_cost_per_token?: number;
	output_cost_per_reasoning_token?: number;
	litellm_provider: string;
	mode?: string;
	supports_function_calling?: boolean;
	supports_parallel_function_calling?: boolean;
	supports_vision?: boolean;
	supports_audio_input?: boolean;
	supports_audio_output?: boolean;
	supports_prompt_caching?: boolean;
	supports_response_schema?: boolean;
	supports_system_messages?: boolean;
	supports_reasoning?: boolean;
	supports_web_search?: boolean;
	search_context_cost_per_query?: SearchContextCostPerQuery;
	deprecation_date?: string;
}

export interface SearchContextCostPerQuery {
	search_context_size_low: number;
	search_context_size_medium: number;
	search_context_size_high: number;
}