generated from ellisonleao/nvim-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoptions.ts
51 lines (44 loc) · 1.45 KB
/
options.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
import { PROVIDER_NAMES, type ProviderName } from "./providers/provider";
export type MagentaOptions = {
provider: ProviderName;
openai: { model: string };
anthropic: { model: string };
};
export const DEFAULT_OPTIONS: MagentaOptions = {
provider: "anthropic",
anthropic: {
model: "claude-3-5-sonnet-latest",
},
openai: {
model: "gpt-4o",
},
};
export function parseOptions(inputOptions: unknown): MagentaOptions {
const options = JSON.parse(JSON.stringify(DEFAULT_OPTIONS)) as MagentaOptions;
if (typeof inputOptions == "object" && inputOptions != null) {
const inputOptionsObj = inputOptions as { [key: string]: unknown };
if (
typeof inputOptionsObj["provider"] == "string" &&
PROVIDER_NAMES.indexOf(inputOptionsObj["provider"] as ProviderName) != -1
) {
options.provider = inputOptionsObj.provider as ProviderName;
}
if (typeof inputOptionsObj["anthropic"] == "object") {
const anthropicOptions = inputOptionsObj["anthropic"] as {
[key: string]: unknown;
};
if (typeof anthropicOptions["model"] == "string") {
options.anthropic.model = anthropicOptions.model;
}
}
if (typeof inputOptionsObj["openai"] == "object") {
const openaiOptions = inputOptionsObj["openai"] as {
[key: string]: unknown;
};
if (typeof openaiOptions["model"] == "string") {
options.openai.model = openaiOptions.model;
}
}
}
return options;
}