-
Notifications
You must be signed in to change notification settings - Fork 26
/
ChatCraftModel.ts
92 lines (79 loc) · 2.37 KB
/
ChatCraftModel.ts
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
export class ChatCraftModel {
id: string;
vendor: string;
name: string;
/**
* @param model The model's name. Different providers give this in different
* formats. OpenAI uses `gpt-3.5-turbo` with no vendor info, while OpenRouter.ai
* uses `openai/gpt-3.5-turbo` (i.e., with vendor/* prefix).
*/
constructor(model: string) {
this.id = model;
const parts = model.split("/");
// Default to "openai" if we don't get a vendor name
this.vendor = parts.length > 1 ? parts[0] : "openai";
// If we get a vendor, use the second part, otherwise the whole thing is the model name
this.name = parts.length > 1 ? parts[1] : parts[0];
}
get logoUrl() {
const vendor = this.vendor;
if (vendor === "openai" && this.name.includes("gpt")) {
return "/openai-logo.png";
}
if (vendor === "anthropic") {
return "/anthropic-logo.png";
}
if (vendor === "google") {
return "/palm-logo.png";
}
// Use the Hugging Face logo, since it's hosted there
// https://huggingface.co/tiiuae/falcon-40b
if (vendor === "tiiuae") {
return "/hugging-face-logo.png";
}
return undefined;
}
// Simple hash from name's characters to a 6-digit hexadecimal color code
get logoBg(): string {
let hash = 0;
for (let i = 0; i < this.name.length; i++) {
hash = this.name.charCodeAt(i) + ((hash << 5) - hash);
}
let color = "#";
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 0xff;
color += ("00" + value.toString(16)).substr(-2);
}
return color;
}
/**
* Not all models (or vendors) support function calling. Currently
* OpenAI GPT models do, with gpt-3.5-turbo-0613 and gpt-4-0613 being
* the best models to use for this task, see:
* https://platform.openai.com/docs/guides/gpt/function-calling
*/
get supportsFunctionCalling() {
const { name } = this;
// The OpenAI vision models can't do function calling
return (
!this.name.includes("vision") &&
(name.startsWith("gpt-3.5-turbo") || name.startsWith("gpt-4"))
);
}
get supportsImages() {
return (
this.name.includes("vision") ||
this.name.startsWith("gpt-4-turbo") ||
this.name.startsWith("gpt-4o")
);
}
get prettyModel(): string {
return this.name;
}
toString() {
return this.id;
}
toJSON() {
return this.id;
}
}