Skip to content

Commit a84743c

Browse files
authored
add LlamaCloud support for reflex template (#473)
1 parent fc5e56e commit a84743c

File tree

14 files changed

+490
-103
lines changed

14 files changed

+490
-103
lines changed

.changeset/famous-ways-give.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-llama": patch
3+
---
4+
5+
Change --agents paramameter to --use-case

.changeset/green-melons-thank.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-llama": patch
3+
---
4+
5+
Add LlamaCloud support for Reflex templates

create-app.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function createApp({
3939
tools,
4040
useLlamaParse,
4141
observability,
42-
agents,
42+
useCase,
4343
}: InstallAppArgs): Promise<void> {
4444
const root = path.resolve(appPath);
4545

@@ -84,7 +84,7 @@ export async function createApp({
8484
tools,
8585
useLlamaParse,
8686
observability,
87-
agents,
87+
useCase,
8888
};
8989

9090
// Install backend

e2e/shared/multiagent_template.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ const templateUI: TemplateUI = "shadcn";
1818
const templatePostInstallAction: TemplatePostInstallAction = "runApp";
1919
const appType: AppType = templateFramework === "fastapi" ? "--frontend" : "";
2020
const userMessage = "Write a blog post about physical standards for letters";
21-
const templateAgents = ["financial_report", "blog", "form_filling"];
21+
const templateUseCases = ["financial_report", "blog", "form_filling"];
2222

23-
for (const agents of templateAgents) {
24-
test.describe(`Test multiagent template ${agents} ${templateFramework} ${dataSource} ${templateUI} ${appType} ${templatePostInstallAction}`, async () => {
23+
for (const useCase of templateUseCases) {
24+
test.describe(`Test multiagent template ${useCase} ${templateFramework} ${dataSource} ${templateUI} ${appType} ${templatePostInstallAction}`, async () => {
2525
test.skip(
2626
process.platform !== "linux" || process.env.DATASOURCE === "--no-files",
2727
"The multiagent template currently only works with files. We also only run on Linux to speed up tests.",
@@ -46,7 +46,7 @@ for (const agents of templateAgents) {
4646
postInstallAction: templatePostInstallAction,
4747
templateUI,
4848
appType,
49-
agents,
49+
useCase,
5050
});
5151
name = result.projectName;
5252
appProcess = result.appProcess;
@@ -71,8 +71,8 @@ for (const agents of templateAgents) {
7171
}) => {
7272
test.skip(
7373
templatePostInstallAction !== "runApp" ||
74-
agents === "financial_report" ||
75-
agents === "form_filling" ||
74+
useCase === "financial_report" ||
75+
useCase === "form_filling" ||
7676
templateFramework === "express",
7777
"Skip chat tests for financial report and form filling.",
7878
);

e2e/shared/reflex_template.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from "@playwright/test";
33
import { ChildProcess } from "child_process";
44
import fs from "fs";
55
import path from "path";
6-
import { TemplateAgents, TemplateFramework } from "../../helpers";
6+
import { TemplateFramework, TemplateUseCase } from "../../helpers";
77
import { createTestDir, runCreateLlama } from "../utils";
88

99
const templateFramework: TemplateFramework = process.env.FRAMEWORK
@@ -12,16 +12,16 @@ const templateFramework: TemplateFramework = process.env.FRAMEWORK
1212
const dataSource: string = process.env.DATASOURCE
1313
? process.env.DATASOURCE
1414
: "--example-file";
15-
const templateAgents: TemplateAgents[] = ["extractor", "contract_review"];
15+
const templateUseCases: TemplateUseCase[] = ["extractor", "contract_review"];
1616

1717
// The reflex template currently only works with FastAPI and files (and not on Windows)
1818
if (
1919
process.platform !== "win32" &&
2020
templateFramework === "fastapi" &&
2121
dataSource === "--example-file"
2222
) {
23-
for (const agents of templateAgents) {
24-
test.describe(`Test reflex template ${agents} ${templateFramework} ${dataSource}`, async () => {
23+
for (const useCase of templateUseCases) {
24+
test.describe(`Test reflex template ${useCase} ${templateFramework} ${dataSource}`, async () => {
2525
let appPort: number;
2626
let name: string;
2727
let appProcess: ChildProcess;
@@ -39,7 +39,7 @@ if (
3939
vectorDb: "none",
4040
port: appPort,
4141
postInstallAction: "runApp",
42-
agents,
42+
useCase,
4343
});
4444
name = result.projectName;
4545
appProcess = result.appProcess;

e2e/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type RunCreateLlamaOptions = {
3333
tools?: string;
3434
useLlamaParse?: boolean;
3535
observability?: string;
36-
agents?: string;
36+
useCase?: string;
3737
};
3838

3939
export async function runCreateLlama({
@@ -51,7 +51,7 @@ export async function runCreateLlama({
5151
tools,
5252
useLlamaParse,
5353
observability,
54-
agents,
54+
useCase,
5555
}: RunCreateLlamaOptions): Promise<CreateLlamaResult> {
5656
if (!process.env.OPENAI_API_KEY || !process.env.LLAMA_CLOUD_API_KEY) {
5757
throw new Error(
@@ -113,8 +113,8 @@ export async function runCreateLlama({
113113
if (observability) {
114114
commandArgs.push("--observability", observability);
115115
}
116-
if ((templateType === "multiagent" || templateType === "reflex") && agents) {
117-
commandArgs.push("--agents", agents);
116+
if ((templateType === "multiagent" || templateType === "reflex") && useCase) {
117+
commandArgs.push("--use-case", useCase);
118118
}
119119

120120
const command = commandArgs.join(" ");

helpers/python.ts

+15-20
Original file line numberDiff line numberDiff line change
@@ -380,28 +380,32 @@ export const installPythonDependencies = (
380380
};
381381

382382
export const installPythonTemplate = async ({
383+
appName,
383384
root,
384385
template,
385386
framework,
386387
vectorDb,
388+
postInstallAction,
389+
modelConfig,
387390
dataSources,
388391
tools,
389-
postInstallAction,
392+
useLlamaParse,
393+
useCase,
390394
observability,
391-
modelConfig,
392-
agents,
393395
}: Pick<
394396
InstallTemplateArgs,
397+
| "appName"
395398
| "root"
396-
| "framework"
397399
| "template"
400+
| "framework"
398401
| "vectorDb"
402+
| "postInstallAction"
403+
| "modelConfig"
399404
| "dataSources"
400405
| "tools"
401-
| "postInstallAction"
406+
| "useLlamaParse"
407+
| "useCase"
402408
| "observability"
403-
| "modelConfig"
404-
| "agents"
405409
>) => {
406410
console.log("\nInitializing Python project with template:", template, "\n");
407411
let templatePath;
@@ -476,21 +480,12 @@ export const installPythonTemplate = async ({
476480
await copyRouterCode(root, tools ?? []);
477481
}
478482

479-
if (template === "multiagent") {
480-
// Copy multi-agent code
481-
await copy("**", path.join(root), {
482-
parents: true,
483-
cwd: path.join(compPath, "multiagent", "python"),
484-
rename: assetRelocator,
485-
});
486-
}
487-
488483
if (template === "multiagent" || template === "reflex") {
489-
if (agents) {
484+
if (useCase) {
490485
const sourcePath =
491486
template === "multiagent"
492-
? path.join(compPath, "agents", "python", agents)
493-
: path.join(compPath, "reflex", agents);
487+
? path.join(compPath, "agents", "python", useCase)
488+
: path.join(compPath, "reflex", useCase);
494489

495490
await copy("**", path.join(root), {
496491
parents: true,
@@ -500,7 +495,7 @@ export const installPythonTemplate = async ({
500495
} else {
501496
console.log(
502497
red(
503-
`There is no agent selected for ${template} template. Please pick an agent to use via --agents flag.`,
498+
`There is no use case selected for ${template} template. Please pick a use case to use via --use-case flag.`,
504499
),
505500
);
506501
process.exit(1);

helpers/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type TemplateDataSource = {
4949
};
5050
export type TemplateDataSourceType = "file" | "web" | "db";
5151
export type TemplateObservability = "none" | "traceloop" | "llamatrace";
52-
export type TemplateAgents =
52+
export type TemplateUseCase =
5353
| "financial_report"
5454
| "blog"
5555
| "form_filling"
@@ -106,5 +106,5 @@ export interface InstallTemplateArgs {
106106
postInstallAction?: TemplatePostInstallAction;
107107
tools?: Tool[];
108108
observability?: TemplateObservability;
109-
agents?: TemplateAgents;
109+
useCase?: TemplateUseCase;
110110
}

helpers/typescript.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const installTSTemplate = async ({
2626
tools,
2727
dataSources,
2828
useLlamaParse,
29-
agents,
29+
useCase,
3030
}: InstallTemplateArgs & { backend: boolean }) => {
3131
console.log(bold(`Using ${packageManager}.`));
3232

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

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

140-
// Copy agent codes
140+
// Copy use case codes
141141
await copy("**", path.join(root, relativeEngineDestPath, "workflow"), {
142142
parents: true,
143-
cwd: agentsCodePath,
143+
cwd: useCaseCodePath,
144144
rename: assetRelocator,
145145
});
146146

@@ -153,7 +153,7 @@ export const installTSTemplate = async ({
153153
} else {
154154
console.log(
155155
red(
156-
`There is no agent selected for ${template} template. Please pick an agent to use via --agents flag.`,
156+
`There is no use case selected for ${template} template. Please pick a use case to use via --use-case flag.`,
157157
),
158158
);
159159
process.exit(1);

index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ const program = new Command(packageJson.name)
202202
false,
203203
)
204204
.option(
205-
"--agents <agents>",
205+
"--use-case <useCase>",
206206
`
207207
208-
Select which agents to use for the multi-agent template (e.g: financial_report, blog).
208+
Select which use case to use for the multi-agent template (e.g: financial_report, blog).
209209
`,
210210
)
211211
.allowUnknownOption()

0 commit comments

Comments
 (0)