Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add e2e testing for llamacloud datasource #181

Merged
merged 17 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
run: pnpm run e2e
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
LLAMA_CLOUD_API_KEY: ${{ secrets.LLAMA_CLOUD_API_KEY }}
working-directory: .

- uses: actions/upload-artifact@v3
Expand Down
10 changes: 7 additions & 3 deletions e2e/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const templateFrameworks: TemplateFramework[] = [
"express",
"fastapi",
];
const dataSources: string[] = ["--no-files", "--example-file"];
const dataSources: string[] = ["--no-files", "--example-file", "--llamacloud"];
marcusschiesser marked this conversation as resolved.
Show resolved Hide resolved
const templateUIs: TemplateUI[] = ["shadcn", "html"];
const templatePostInstallActions: TemplatePostInstallAction[] = [
"none",
Expand All @@ -31,6 +31,10 @@ for (const templateType of templateTypes) {
for (const templatePostInstallAction of templatePostInstallActions) {
const appType: AppType =
templateFramework === "nextjs" ? "" : "--frontend";
const userMessage =
dataSource !== "--no-files"
? "Physical standard for letters"
: "Hello";
test.describe(`try create-llama ${templateType} ${templateFramework} ${dataSource} ${templateUI} ${appType} ${templatePostInstallAction}`, async () => {
let port: number;
let externalPort: number;
Expand Down Expand Up @@ -75,7 +79,7 @@ for (const templateType of templateTypes) {
}) => {
test.skip(templatePostInstallAction !== "runApp");
await page.goto(`http://localhost:${port}`);
await page.fill("form input", "hello");
await page.fill("form input", userMessage);
const [response] = await Promise.all([
page.waitForResponse(
(res) => {
Expand Down Expand Up @@ -106,7 +110,7 @@ for (const templateType of templateTypes) {
messages: [
{
role: "user",
content: "Hello",
content: userMessage,
},
],
},
Expand Down
2 changes: 2 additions & 0 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export async function runCreateLlama(
"--no-llama-parse",
"--observability",
"none",
"--llama-cloud-key",
process.env.LLAMA_CLOUD_API_KEY,
marcusschiesser marked this conversation as resolved.
Show resolved Hide resolved
].join(" ");
console.log(`running command '${command}' in ${cwd}`);
const appProcess = exec(command, {
Expand Down
6 changes: 4 additions & 2 deletions helpers/env-variables.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ciInfo from "ci-info";
import fs from "fs/promises";
import path from "path";
import { TOOL_SYSTEM_PROMPT_ENV_VAR, Tool } from "./tools";
Expand All @@ -9,6 +10,7 @@ import {
TemplateVectorDB,
} from "./types";

import { randomUUID } from "crypto";
import { TSYSTEMS_LLMHUB_API_URL } from "./providers/llmhub";

export type EnvVar = {
Expand Down Expand Up @@ -142,12 +144,12 @@ const getVectorDBEnvs = (
name: "LLAMA_CLOUD_INDEX_NAME",
marcusschiesser marked this conversation as resolved.
Show resolved Hide resolved
description:
"The name of the LlamaCloud index to use (part of the LlamaCloud project).",
value: "test",
value: ciInfo.isCI ? randomUUID() : "test",
marcusschiesser marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "LLAMA_CLOUD_PROJECT_NAME",
description: "The name of the LlamaCloud project.",
value: "Default",
value: ciInfo.isCI ? "create-llama" : "Default",
},
{
name: "LLAMA_CLOUD_BASE_URL",
Expand Down
6 changes: 5 additions & 1 deletion helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ async function generateContextData(
const llamaCloudKeyConfigured = useLlamaParse
? llamaCloudKey || process.env["LLAMA_CLOUD_API_KEY"]
: true;
// only generate for non-vector db or llamacloud with key
const canGenerateVectorDb =
vectorDb === "none" ||
(vectorDb === "llamacloud" && llamaCloudKeyConfigured);
const hasVectorDb = vectorDb && vectorDb !== "none";
if (modelConfigured && llamaCloudKeyConfigured && !hasVectorDb) {
if (modelConfigured && llamaCloudKeyConfigured && canGenerateVectorDb) {
marcusschiesser marked this conversation as resolved.
Show resolved Hide resolved
// If all the required environment variables are set, run the generate script
if (framework === "fastapi") {
if (isHavingPoetryLockFile()) {
Expand Down
12 changes: 10 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import prompts from "prompts";
import terminalLink from "terminal-link";
import checkForUpdate from "update-check";
import { createApp } from "./create-app";
import { getDataSources } from "./helpers/datasources";
import { EXAMPLE_FILE, getDataSources } from "./helpers/datasources";
import { getPkgManager } from "./helpers/get-pkg-manager";
import { isFolderEmpty } from "./helpers/is-folder-empty";
import { initializeGlobalAgent } from "./helpers/proxy";
Expand Down Expand Up @@ -194,8 +194,16 @@ if (process.argv.includes("--no-llama-parse")) {
program.askModels = process.argv.includes("--ask-models");
if (process.argv.includes("--no-files")) {
program.dataSources = [];
} else {
} else if (process.argv.includes("--example-file")) {
program.dataSources = getDataSources(program.files, program.exampleFile);
} else if (process.argv.includes("--llamacloud")) {
program.dataSources = [
{
type: "llamacloud",
config: {},
},
EXAMPLE_FILE,
];
}

const packageManager = !!program.useNpm
Expand Down
2 changes: 1 addition & 1 deletion questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ export const askQuestions = async (
}

// Ask for LlamaCloud API key when using a LlamaCloud index or LlamaParse
if (isUsingLlamaCloud || program.useLlamaParse) {
if ((isUsingLlamaCloud || program.useLlamaParse) && !program.llamaCloudKey) {
marcusschiesser marked this conversation as resolved.
Show resolved Hide resolved
if (ciInfo.isCI) {
program.llamaCloudKey = getPrefOrDefault("llamaCloudKey");
} else {
Expand Down
Loading