-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapiKey.ts
More file actions
53 lines (47 loc) · 1.35 KB
/
apiKey.ts
File metadata and controls
53 lines (47 loc) · 1.35 KB
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
import type { Arguments } from "yargs-types";
import type { z } from "zod";
import {
type globalConfigSchema,
setConfig,
} from "../../middlewares/globalConfig.ts";
import {
ANTHROPIC_PROVIDER,
GOOGLE_PROVIDER,
type ModelProvider,
OPENAI_PROVIDER,
} from "../../../manifest/dependencyManifest/labeling/model.ts";
import { input, select } from "@inquirer/prompts";
async function handler(
argv: Arguments & {
globalConfig: z.infer<typeof globalConfigSchema>;
},
) {
const globalConfig = argv.globalConfig as z.infer<typeof globalConfigSchema>;
const provider = await select({
message: "Select a provider",
choices: [
{ name: "Google", value: GOOGLE_PROVIDER },
{ name: "OpenAI", value: OPENAI_PROVIDER },
{ name: "Anthropic", value: ANTHROPIC_PROVIDER },
],
}) as ModelProvider;
const apiKey = await input({
message: "Enter the API key",
validate: (value) => {
if (value.length === 0) {
return "API key cannot be empty";
}
return true;
},
});
const labeling = globalConfig.labeling || { apiKeys: {} };
labeling.apiKeys[provider] = apiKey;
setConfig({ ...globalConfig, labeling });
console.info("API key set successfully");
}
export default {
command: "apiKey",
describe: "set an API key for a model provider in your global config",
builder: () => {},
handler,
};