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

add LlamaCloud support for reflex template #473

Merged
merged 5 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/famous-ways-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-llama": patch
---

Change --agents paramameter to --use-case
5 changes: 5 additions & 0 deletions .changeset/green-melons-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-llama": patch
---

Add LlamaCloud support for Reflex templates
4 changes: 2 additions & 2 deletions create-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function createApp({
tools,
useLlamaParse,
observability,
agents,
useCase,
}: InstallAppArgs): Promise<void> {
const root = path.resolve(appPath);

Expand Down Expand Up @@ -84,7 +84,7 @@ export async function createApp({
tools,
useLlamaParse,
observability,
agents,
useCase,
};

// Install backend
Expand Down
12 changes: 6 additions & 6 deletions e2e/shared/multiagent_template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const templateUI: TemplateUI = "shadcn";
const templatePostInstallAction: TemplatePostInstallAction = "runApp";
const appType: AppType = templateFramework === "fastapi" ? "--frontend" : "";
const userMessage = "Write a blog post about physical standards for letters";
const templateAgents = ["financial_report", "blog", "form_filling"];
const templateUseCases = ["financial_report", "blog", "form_filling"];

for (const agents of templateAgents) {
test.describe(`Test multiagent template ${agents} ${templateFramework} ${dataSource} ${templateUI} ${appType} ${templatePostInstallAction}`, async () => {
for (const useCase of templateUseCases) {
test.describe(`Test multiagent template ${useCase} ${templateFramework} ${dataSource} ${templateUI} ${appType} ${templatePostInstallAction}`, async () => {
test.skip(
process.platform !== "linux" || process.env.DATASOURCE === "--no-files",
"The multiagent template currently only works with files. We also only run on Linux to speed up tests.",
Expand All @@ -46,7 +46,7 @@ for (const agents of templateAgents) {
postInstallAction: templatePostInstallAction,
templateUI,
appType,
agents,
useCase,
});
name = result.projectName;
appProcess = result.appProcess;
Expand All @@ -71,8 +71,8 @@ for (const agents of templateAgents) {
}) => {
test.skip(
templatePostInstallAction !== "runApp" ||
agents === "financial_report" ||
agents === "form_filling" ||
useCase === "financial_report" ||
useCase === "form_filling" ||
templateFramework === "express",
"Skip chat tests for financial report and form filling.",
);
Expand Down
10 changes: 5 additions & 5 deletions e2e/shared/reflex_template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from "@playwright/test";
import { ChildProcess } from "child_process";
import fs from "fs";
import path from "path";
import { TemplateAgents, TemplateFramework } from "../../helpers";
import { TemplateFramework, TemplateUseCase } from "../../helpers";
import { createTestDir, runCreateLlama } from "../utils";

const templateFramework: TemplateFramework = process.env.FRAMEWORK
Expand All @@ -12,16 +12,16 @@ const templateFramework: TemplateFramework = process.env.FRAMEWORK
const dataSource: string = process.env.DATASOURCE
? process.env.DATASOURCE
: "--example-file";
const templateAgents: TemplateAgents[] = ["extractor", "contract_review"];
const templateUseCases: TemplateUseCase[] = ["extractor", "contract_review"];

// The reflex template currently only works with FastAPI and files (and not on Windows)
if (
process.platform !== "win32" &&
templateFramework === "fastapi" &&
dataSource === "--example-file"
) {
for (const agents of templateAgents) {
test.describe(`Test reflex template ${agents} ${templateFramework} ${dataSource}`, async () => {
for (const useCase of templateUseCases) {
test.describe(`Test reflex template ${useCase} ${templateFramework} ${dataSource}`, async () => {
let appPort: number;
let name: string;
let appProcess: ChildProcess;
Expand All @@ -39,7 +39,7 @@ if (
vectorDb: "none",
port: appPort,
postInstallAction: "runApp",
agents,
useCase,
});
name = result.projectName;
appProcess = result.appProcess;
Expand Down
8 changes: 4 additions & 4 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type RunCreateLlamaOptions = {
tools?: string;
useLlamaParse?: boolean;
observability?: string;
agents?: string;
useCase?: string;
};

export async function runCreateLlama({
Expand All @@ -51,7 +51,7 @@ export async function runCreateLlama({
tools,
useLlamaParse,
observability,
agents,
useCase,
}: RunCreateLlamaOptions): Promise<CreateLlamaResult> {
if (!process.env.OPENAI_API_KEY || !process.env.LLAMA_CLOUD_API_KEY) {
throw new Error(
Expand Down Expand Up @@ -113,8 +113,8 @@ export async function runCreateLlama({
if (observability) {
commandArgs.push("--observability", observability);
}
if ((templateType === "multiagent" || templateType === "reflex") && agents) {
commandArgs.push("--agents", agents);
if ((templateType === "multiagent" || templateType === "reflex") && useCase) {
commandArgs.push("--use-case", useCase);
}

const command = commandArgs.join(" ");
Expand Down
35 changes: 15 additions & 20 deletions helpers/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,28 +380,32 @@ export const installPythonDependencies = (
};

export const installPythonTemplate = async ({
appName,
root,
template,
framework,
vectorDb,
postInstallAction,
modelConfig,
dataSources,
tools,
postInstallAction,
useLlamaParse,
useCase,
observability,
modelConfig,
agents,
}: Pick<
InstallTemplateArgs,
| "appName"
| "root"
| "framework"
| "template"
| "framework"
| "vectorDb"
| "postInstallAction"
| "modelConfig"
| "dataSources"
| "tools"
| "postInstallAction"
| "useLlamaParse"
| "useCase"
| "observability"
| "modelConfig"
| "agents"
>) => {
console.log("\nInitializing Python project with template:", template, "\n");
let templatePath;
Expand Down Expand Up @@ -476,21 +480,12 @@ export const installPythonTemplate = async ({
await copyRouterCode(root, tools ?? []);
}

if (template === "multiagent") {
// Copy multi-agent code
await copy("**", path.join(root), {
parents: true,
cwd: path.join(compPath, "multiagent", "python"),
rename: assetRelocator,
});
}

if (template === "multiagent" || template === "reflex") {
if (agents) {
if (useCase) {
const sourcePath =
template === "multiagent"
? path.join(compPath, "agents", "python", agents)
: path.join(compPath, "reflex", agents);
? path.join(compPath, "agents", "python", useCase)
: path.join(compPath, "reflex", useCase);

await copy("**", path.join(root), {
parents: true,
Expand All @@ -500,7 +495,7 @@ export const installPythonTemplate = async ({
} else {
console.log(
red(
`There is no agent selected for ${template} template. Please pick an agent to use via --agents flag.`,
`There is no use case selected for ${template} template. Please pick a use case to use via --use-case flag.`,
),
);
process.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type TemplateDataSource = {
};
export type TemplateDataSourceType = "file" | "web" | "db";
export type TemplateObservability = "none" | "traceloop" | "llamatrace";
export type TemplateAgents =
export type TemplateUseCase =
| "financial_report"
| "blog"
| "form_filling"
Expand Down Expand Up @@ -106,5 +106,5 @@ export interface InstallTemplateArgs {
postInstallAction?: TemplatePostInstallAction;
tools?: Tool[];
observability?: TemplateObservability;
agents?: TemplateAgents;
useCase?: TemplateUseCase;
}
18 changes: 9 additions & 9 deletions helpers/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const installTSTemplate = async ({
tools,
dataSources,
useLlamaParse,
agents,
useCase,
}: InstallTemplateArgs & { backend: boolean }) => {
console.log(bold(`Using ${packageManager}.`));

Expand Down Expand Up @@ -131,16 +131,16 @@ export const installTSTemplate = async ({
cwd: path.join(multiagentPath, "workflow"),
});

// Copy agents use case code for multiagent template
if (agents) {
console.log("\nCopying agent:", agents, "\n");
const useCasePath = path.join(compPath, "agents", "typescript", agents);
const agentsCodePath = path.join(useCasePath, "workflow");
// Copy use case code for multiagent template
if (useCase) {
console.log("\nCopying use case:", useCase, "\n");
const useCasePath = path.join(compPath, "agents", "typescript", useCase);
const useCaseCodePath = path.join(useCasePath, "workflow");

// Copy agent codes
// Copy use case codes
await copy("**", path.join(root, relativeEngineDestPath, "workflow"), {
parents: true,
cwd: agentsCodePath,
cwd: useCaseCodePath,
rename: assetRelocator,
});

Expand All @@ -153,7 +153,7 @@ export const installTSTemplate = async ({
} else {
console.log(
red(
`There is no agent selected for ${template} template. Please pick an agent to use via --agents flag.`,
`There is no use case selected for ${template} template. Please pick a use case to use via --use-case flag.`,
leehuwuj marked this conversation as resolved.
Show resolved Hide resolved
),
);
process.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ const program = new Command(packageJson.name)
false,
)
.option(
"--agents <agents>",
"--use-case <useCase>",
`

Select which agents to use for the multi-agent template (e.g: financial_report, blog).
Select which use case to use for the multi-agent template (e.g: financial_report, blog).
`,
)
.allowUnknownOption()
Expand Down
Loading
Loading