forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenviroment.ts
64 lines (60 loc) · 2.07 KB
/
enviroment.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
import { IAgentRuntime } from "@ai16z/eliza";
import { z } from "zod";
export const imageGenEnvSchema = z
.object({
ANTHROPIC_API_KEY: z.string().optional(),
TOGETHER_API_KEY: z.string().optional(),
HEURIST_API_KEY: z.string().optional(),
FAL_API_KEY: z.string().optional(),
OPENAI_API_KEY: z.string().optional(),
})
.refine(
(data) => {
return !!(
data.ANTHROPIC_API_KEY ||
data.TOGETHER_API_KEY ||
data.HEURIST_API_KEY ||
data.FAL_API_KEY ||
data.OPENAI_API_KEY
);
},
{
message:
"At least one of ANTHROPIC_API_KEY, TOGETHER_API_KEY, HEURIST_API_KEY, FAL_API_KEY or OPENAI_API_KEY is required",
}
);
export type ImageGenConfig = z.infer<typeof imageGenEnvSchema>;
export async function validateImageGenConfig(
runtime: IAgentRuntime
): Promise<ImageGenConfig> {
try {
const config = {
ANTHROPIC_API_KEY:
runtime.getSetting("ANTHROPIC_API_KEY") ||
process.env.ANTHROPIC_API_KEY,
TOGETHER_API_KEY:
runtime.getSetting("TOGETHER_API_KEY") ||
process.env.TOGETHER_API_KEY,
HEURIST_API_KEY:
runtime.getSetting("HEURIST_API_KEY") ||
process.env.HEURIST_API_KEY,
FAL_API_KEY:
runtime.getSetting("FAL_API_KEY") ||
process.env.FAL_API_KEY,
OPENAI_API_KEY:
runtime.getSetting("OPENAI_API_KEY") ||
process.env.OPENAI_API_KEY,
};
return imageGenEnvSchema.parse(config);
} catch (error) {
if (error instanceof z.ZodError) {
const errorMessages = error.errors
.map((err) => `${err.path.join(".")}: ${err.message}`)
.join("\n");
throw new Error(
`Image generation configuration validation failed:\n${errorMessages}`
);
}
throw error;
}
}