Skip to content

Commit

Permalink
feat: Generate NEXT_PUBLIC_CHAT_API for NextJS backend to specify alt…
Browse files Browse the repository at this point in the history
…ernative backend (#445)
  • Loading branch information
marcusschiesser authored Nov 22, 2024
1 parent 6e70e32 commit 0a7dfcf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-days-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-llama": patch
---

Generate NEXT_PUBLIC_CHAT_API for NextJS backend to specify alternative backend
5 changes: 1 addition & 4 deletions create-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { configVSCode } from "./helpers/vscode";

export type InstallAppArgs = Omit<
InstallTemplateArgs,
"appName" | "root" | "isOnline" | "customApiPath"
"appName" | "root" | "isOnline" | "port"
> & {
appPath: string;
frontend: boolean;
Expand All @@ -34,7 +34,6 @@ export async function createApp({
communityProjectConfig,
llamapack,
vectorDb,
port,
postInstallAction,
dataSources,
tools,
Expand Down Expand Up @@ -80,7 +79,6 @@ export async function createApp({
communityProjectConfig,
llamapack,
vectorDb,
port,
postInstallAction,
dataSources,
tools,
Expand All @@ -100,7 +98,6 @@ export async function createApp({
...args,
root: frontendRoot,
framework: "nextjs",
customApiPath: `http://localhost:${port ?? 8000}/api/chat`,
backend: false,
});
}
Expand Down
15 changes: 7 additions & 8 deletions helpers/env-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ const getFrameworkEnvs = (
],
);
}
if (framework === "nextjs") {
result.push({
name: "NEXT_PUBLIC_CHAT_API",
description:
"The API for the chat endpoint. Set when using a custom backend (e.g. Express). Use full URL like http://localhost:8000/api/chat",
});
}
return result;
};

Expand Down Expand Up @@ -585,18 +592,10 @@ export const createBackendEnvFile = async (
export const createFrontendEnvFile = async (
root: string,
opts: {
customApiPath?: string;
vectorDb?: TemplateVectorDB;
},
) => {
const defaultFrontendEnvs = [
{
name: "NEXT_PUBLIC_CHAT_API",
description: "The backend API for chat endpoint.",
value: opts.customApiPath
? opts.customApiPath
: "http://localhost:8000/api/chat",
},
{
name: "NEXT_PUBLIC_USE_LLAMACLOUD",
description: "Let's the user change indexes in LlamaCloud projects",
Expand Down
1 change: 0 additions & 1 deletion helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ export const installTemplate = async (
} else {
// this is a frontend for a full-stack app, create .env file with model information
await createFrontendEnvFile(props.root, {
customApiPath: props.customApiPath,
vectorDb: props.vectorDb,
});
}
Expand Down
1 change: 0 additions & 1 deletion helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export interface InstallTemplateArgs {
framework: TemplateFramework;
ui: TemplateUI;
dataSources: TemplateDataSource[];
customApiPath?: string;
modelConfig: ModelConfig;
llamaCloudKey?: string;
useLlamaParse?: boolean;
Expand Down
1 change: 0 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ async function run(): Promise<void> {
...answers,
appPath: resolvedProjectPath,
packageManager,
port: options.port,
});

if (answers.postInstallAction === "VSCode") {
Expand Down

0 comments on commit 0a7dfcf

Please sign in to comment.