diff --git a/packages/create-llama/helpers/install.ts b/packages/create-llama/helpers/install.ts index 27d8f8132e776a9c2ae819beff24b948e7139075..9f0f20356265081bbb062454b14d1c9059544900 100644 --- a/packages/create-llama/helpers/install.ts +++ b/packages/create-llama/helpers/install.ts @@ -8,13 +8,13 @@ import type { PackageManager } from "./get-pkg-manager"; * * @returns A Promise that resolves once the installation is finished. */ -export async function install( +export async function callPackageManager( /** Indicate which package manager to use. */ packageManager: PackageManager, /** Indicate whether there is an active Internet connection.*/ isOnline: boolean, + args: string[] = ["install"], ): Promise<void> { - let args: string[] = ["install"]; if (!isOnline) { console.log( yellow("You appear to be offline.\nFalling back to the local cache."), diff --git a/packages/create-llama/templates/types/simple/fastapi/data/101.pdf b/packages/create-llama/templates/components/data/101.pdf similarity index 100% rename from packages/create-llama/templates/types/simple/fastapi/data/101.pdf rename to packages/create-llama/templates/components/data/101.pdf diff --git a/packages/create-llama/templates/index.ts b/packages/create-llama/templates/index.ts index 732bedf3be75422d5f62be7cb37fe30c715325fa..9ff80cc02f8f7780a1f0e6677ce05980ae5bf30e 100644 --- a/packages/create-llama/templates/index.ts +++ b/packages/create-llama/templates/index.ts @@ -1,5 +1,5 @@ import { copy } from "../helpers/copy"; -import { install } from "../helpers/install"; +import { callPackageManager } from "../helpers/install"; import fs from "fs/promises"; import os from "os"; @@ -7,7 +7,12 @@ import path from "path"; import { bold, cyan } from "picocolors"; import { version } from "../package.json"; -import { InstallTemplateArgs, TemplateFramework } from "./types"; +import { PackageManager } from "../helpers/get-pkg-manager"; +import { + InstallTemplateArgs, + TemplateEngine, + TemplateFramework, +} from "./types"; const envFileNameMap: Record<TemplateFramework, string> = { nextjs: ".env.local", @@ -31,6 +36,48 @@ const createEnvLocalFile = async ( } }; +const copyTestData = async ( + root: string, + framework: TemplateFramework, + packageManager?: PackageManager, + engine?: TemplateEngine, +) => { + if (engine === "context" || framework === "fastapi") { + const srcPath = path.join(__dirname, "components", "data"); + const destPath = path.join(root, "data"); + console.log(`\nCopying test data to ${cyan(destPath)}\n`); + await copy("**", destPath, { + parents: true, + cwd: srcPath, + }); + } + + if (packageManager && engine === "context") { + console.log( + `\nRunning ${cyan("npm run generate")} to generate the context data.\n`, + ); + await callPackageManager(packageManager, true, ["run", "generate"]); + console.log(); + } +}; + +const rename = (name: string) => { + switch (name) { + case "gitignore": + case "eslintrc.json": { + return `.${name}`; + } + // README.md is ignored by webpack-asset-relocator-loader used by ncc: + // https://github.com/vercel/webpack-asset-relocator-loader/blob/e9308683d47ff507253e37c9bcbb99474603192b/src/asset-relocator.js#L227 + case "README-template.md": { + return "README.md"; + } + default: { + return name; + } + } +}; + /** * Install a LlamaIndex internal template to a given `root` directory. */ @@ -45,7 +92,6 @@ const installTSTemplate = async ({ ui, eslint, customApiPath, - openAIKey, }: InstallTemplateArgs) => { console.log(bold(`Using ${packageManager}.`)); @@ -57,23 +103,6 @@ const installTSTemplate = async ({ const copySource = ["**"]; if (!eslint) copySource.push("!eslintrc.json"); - const rename = (name: string) => { - switch (name) { - case "gitignore": - case "eslintrc.json": { - return `.${name}`; - } - // README.md is ignored by webpack-asset-relocator-loader used by ncc: - // https://github.com/vercel/webpack-asset-relocator-loader/blob/e9308683d47ff507253e37c9bcbb99474603192b/src/asset-relocator.js#L227 - case "README-template.md": { - return "README.md"; - } - default: { - return name; - } - } - }; - await copy(copySource, root, { parents: true, cwd: templatePath, @@ -115,8 +144,6 @@ const installTSTemplate = async ({ }); } - await createEnvLocalFile(root, framework, openAIKey); - /** * Update the package.json scripts. */ @@ -205,18 +232,14 @@ const installTSTemplate = async ({ console.log(); - await install(packageManager, isOnline); + await callPackageManager(packageManager, isOnline); }; const installPythonTemplate = async ({ root, template, framework, - openAIKey, -}: Pick< - InstallTemplateArgs, - "root" | "framework" | "template" | "openAIKey" ->) => { +}: Pick<InstallTemplateArgs, "root" | "framework" | "template">) => { console.log("\nInitializing Python project with template:", template, "\n"); const templatePath = path.join(__dirname, "types", template, framework); await copy("**", root, { @@ -239,8 +262,6 @@ const installPythonTemplate = async ({ }, }); - await createEnvLocalFile(root, framework, openAIKey); - console.log( "\nPython project, dependencies won't be installed automatically.\n", ); @@ -253,6 +274,17 @@ export const installTemplate = async (props: InstallTemplateArgs) => { } else { await installTSTemplate(props); } + + // Copy the environment file to the target directory. + await createEnvLocalFile(props.root, props.framework, props.openAIKey); + + // Copy test pdf file + await copyTestData( + props.root, + props.framework, + props.packageManager, + props.engine, + ); }; export * from "./types"; diff --git a/packages/create-llama/templates/types/streaming/fastapi/data/101.pdf b/packages/create-llama/templates/types/streaming/fastapi/data/101.pdf deleted file mode 100644 index ae5acffd5398b7c59e2df9e6dead2d99128b719c..0000000000000000000000000000000000000000 Binary files a/packages/create-llama/templates/types/streaming/fastapi/data/101.pdf and /dev/null differ