Skip to content

Commit c818bc8

Browse files
committed
remove adding api key to .env file
1 parent fc9495b commit c818bc8

File tree

3 files changed

+74
-15
lines changed

3 files changed

+74
-15
lines changed

helpers/env-variables.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ const getModelEnvs = (modelConfig: ModelConfig): EnvVar[] => {
258258
{
259259
name: "OPENAI_API_KEY",
260260
description: "The OpenAI API key to use.",
261-
value: modelConfig.apiKey,
262261
},
263262
{
264263
name: "LLM_TEMPERATURE",
@@ -275,7 +274,6 @@ const getModelEnvs = (modelConfig: ModelConfig): EnvVar[] => {
275274
{
276275
name: "ANTHROPIC_API_KEY",
277276
description: "The Anthropic API key to use.",
278-
value: modelConfig.apiKey,
279277
},
280278
]
281279
: []),
@@ -284,7 +282,6 @@ const getModelEnvs = (modelConfig: ModelConfig): EnvVar[] => {
284282
{
285283
name: "GROQ_API_KEY",
286284
description: "The Groq API key to use.",
287-
value: modelConfig.apiKey,
288285
},
289286
]
290287
: []),
@@ -293,7 +290,6 @@ const getModelEnvs = (modelConfig: ModelConfig): EnvVar[] => {
293290
{
294291
name: "GOOGLE_API_KEY",
295292
description: "The Google API key to use.",
296-
value: modelConfig.apiKey,
297293
},
298294
]
299295
: []),
@@ -311,7 +307,6 @@ const getModelEnvs = (modelConfig: ModelConfig): EnvVar[] => {
311307
{
312308
name: "MISTRAL_API_KEY",
313309
description: "The Mistral API key to use.",
314-
value: modelConfig.apiKey,
315310
},
316311
]
317312
: []),
@@ -320,7 +315,6 @@ const getModelEnvs = (modelConfig: ModelConfig): EnvVar[] => {
320315
{
321316
name: "AZURE_OPENAI_API_KEY",
322317
description: "The Azure OpenAI key to use.",
323-
value: modelConfig.apiKey,
324318
},
325319
{
326320
name: "AZURE_OPENAI_ENDPOINT",
@@ -367,7 +361,6 @@ const getModelEnvs = (modelConfig: ModelConfig): EnvVar[] => {
367361
{
368362
name: "T_SYSTEMS_LLMHUB_API_KEY",
369363
description: "API Key for T-System's AI Foundation Model.",
370-
value: modelConfig.apiKey,
371364
},
372365
]
373366
: []),

helpers/run-app.ts

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SpawnOptions, spawn } from "child_process";
2-
import { TemplateFramework } from "./types";
2+
import { ModelConfig, TemplateFramework } from "./types";
33

44
const createProcess = (
55
command: string,
@@ -26,7 +26,43 @@ const createProcess = (
2626
});
2727
};
2828

29-
export function runReflexApp(appPath: string, port: number) {
29+
const getRunEnvs = (modelConfig: ModelConfig, llamaCloudKey?: string) => {
30+
let modelAPIKey;
31+
switch (modelConfig.provider) {
32+
case "openai":
33+
modelAPIKey = { OPENAI_API_KEY: modelConfig.apiKey };
34+
break;
35+
case "azure-openai":
36+
modelAPIKey = { AZURE_OPENAI_API_KEY: modelConfig.apiKey };
37+
break;
38+
case "groq":
39+
modelAPIKey = { GROQ_API_KEY: modelConfig.apiKey };
40+
break;
41+
case "anthropic":
42+
modelAPIKey = { ANTHROPIC_API_KEY: modelConfig.apiKey };
43+
break;
44+
case "gemini":
45+
modelAPIKey = { GOOGLE_API_KEY: modelConfig.apiKey };
46+
break;
47+
case "mistral":
48+
modelAPIKey = { MISTRAL_API_KEY: modelConfig.apiKey };
49+
break;
50+
case "t-systems":
51+
modelAPIKey = { T_SYSTEMS_LLMHUB_API_KEY: modelConfig.apiKey };
52+
break;
53+
}
54+
55+
return {
56+
...modelAPIKey,
57+
LLAMA_CLOUD_API_KEY: llamaCloudKey,
58+
};
59+
};
60+
61+
export function runReflexApp(
62+
appPath: string,
63+
port: number,
64+
envs: Record<string, string | undefined>,
65+
) {
3066
const commandArgs = [
3167
"run",
3268
"reflex",
@@ -37,29 +73,51 @@ export function runReflexApp(appPath: string, port: number) {
3773
return createProcess("poetry", commandArgs, {
3874
stdio: "inherit",
3975
cwd: appPath,
76+
env: {
77+
...process.env,
78+
...envs,
79+
},
4080
});
4181
}
4282

43-
export function runFastAPIApp(appPath: string, port: number) {
83+
export function runFastAPIApp(
84+
appPath: string,
85+
port: number,
86+
envs: Record<string, string | undefined>,
87+
) {
4488
return createProcess("poetry", ["run", "dev"], {
4589
stdio: "inherit",
4690
cwd: appPath,
47-
env: { ...process.env, APP_PORT: `${port}` },
91+
env: {
92+
...process.env,
93+
...envs,
94+
APP_PORT: `${port}`,
95+
},
4896
});
4997
}
5098

51-
export function runTSApp(appPath: string, port: number) {
99+
export function runTSApp(
100+
appPath: string,
101+
port: number,
102+
envs: Record<string, string | undefined>,
103+
) {
52104
return createProcess("npm", ["run", "dev"], {
53105
stdio: "inherit",
54106
cwd: appPath,
55-
env: { ...process.env, PORT: `${port}` },
107+
env: {
108+
...process.env,
109+
...envs,
110+
PORT: `${port}`,
111+
},
56112
});
57113
}
58114

59115
export async function runApp(
60116
appPath: string,
61117
template: string,
62118
framework: TemplateFramework,
119+
modelConfig: ModelConfig,
120+
llamaCloudKey?: string,
63121
port?: number,
64122
): Promise<void> {
65123
try {
@@ -73,7 +131,8 @@ export async function runApp(
73131
: framework === "fastapi"
74132
? runFastAPIApp
75133
: runTSApp;
76-
await appRunner(appPath, port || defaultPort);
134+
const envs = getRunEnvs(modelConfig, llamaCloudKey);
135+
await appRunner(appPath, port || defaultPort, envs);
77136
} catch (error) {
78137
console.error("Failed to run app:", error);
79138
throw error;

index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,14 @@ Please check ${cyan(
355355
}
356356
} else if (answers.postInstallAction === "runApp") {
357357
console.log(`Running app in ${root}...`);
358-
await runApp(root, answers.template, answers.framework, options.port);
358+
await runApp(
359+
root,
360+
answers.template,
361+
answers.framework,
362+
answers.modelConfig,
363+
answers.llamaCloudKey,
364+
options.port,
365+
);
359366
}
360367
}
361368

0 commit comments

Comments
 (0)