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 form filling use case for TS #417

Merged
merged 49 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3c847f2
add csv extractor tool
leehuwuj Nov 6, 2024
85905ad
add formFilling agent and update event type
leehuwuj Nov 6, 2024
2e9d3d7
add tools and update template
leehuwuj Nov 7, 2024
ae8126f
update annotation
leehuwuj Nov 7, 2024
17b1dfe
update type
leehuwuj Nov 7, 2024
1bc9e32
allow multiple tool calls
leehuwuj Nov 7, 2024
5927861
enable e2e test for NextJS
leehuwuj Nov 7, 2024
1f9d412
revert wrong change on tools file
leehuwuj Nov 7, 2024
c632345
refactor copy code
leehuwuj Nov 8, 2024
9a022e8
refactor copy code
leehuwuj Nov 8, 2024
dc39b3e
fix typing
leehuwuj Nov 8, 2024
dc2b39e
Update for financial report
leehuwuj Nov 8, 2024
3cae9d7
add changesets
leehuwuj Nov 8, 2024
7848b83
improve code
leehuwuj Nov 8, 2024
a05d444
update with new workflow code
leehuwuj Nov 8, 2024
ef86d64
update with new workflow code
leehuwuj Nov 8, 2024
bd8812b
update workflow code
leehuwuj Nov 11, 2024
edf310a
refactor code
leehuwuj Nov 11, 2024
8b00369
improve form filling tool
leehuwuj Nov 11, 2024
24d1ef1
add generator typing
leehuwuj Nov 11, 2024
31a04b2
add back llamacloud retriever tools
leehuwuj Nov 11, 2024
0e78d38
remove code and add typing
leehuwuj Nov 11, 2024
c6c20fb
add agent message annotation
leehuwuj Nov 11, 2024
51672a8
add typing packages
leehuwuj Nov 11, 2024
291e1d6
improve stream
leehuwuj Nov 11, 2024
b517264
enable expressjs
leehuwuj Nov 11, 2024
b377aee
remove dead code
leehuwuj Nov 11, 2024
c8d204b
add missing code
leehuwuj Nov 11, 2024
15257a6
improve code
leehuwuj Nov 11, 2024
324184b
fix linting
leehuwuj Nov 11, 2024
7b27096
better error handling
leehuwuj Nov 11, 2024
88bc826
improve error handling for csv parsing
leehuwuj Nov 11, 2024
f50cff8
add missing code
leehuwuj Nov 11, 2024
70a01b5
change templates: use attachments folder
leehuwuj Nov 11, 2024
938534f
update for blog use case
leehuwuj Nov 12, 2024
ec8a3cd
refactor code
leehuwuj Nov 12, 2024
37f0e61
update typing
leehuwuj Nov 12, 2024
9258fbc
update stream
leehuwuj Nov 12, 2024
81b09ad
fix e2e and remove code
leehuwuj Nov 12, 2024
8dd5dfd
fix expressjs
leehuwuj Nov 12, 2024
ab6e5dc
improve code
leehuwuj Nov 12, 2024
613af08
remove @core package and refactor tools code
leehuwuj Nov 12, 2024
e16426b
update single agent
leehuwuj Nov 12, 2024
f07e58e
remove bind
leehuwuj Nov 12, 2024
0d9e49f
fix wrong import
leehuwuj Nov 12, 2024
2e6ad55
add missing tool call message in fin report
leehuwuj Nov 13, 2024
ba1462a
update readme
leehuwuj Nov 13, 2024
68b53cc
set type as required in AgentRunEvent
leehuwuj Nov 13, 2024
f7c0c9e
fix wrong readme
leehuwuj Nov 13, 2024
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
8 changes: 4 additions & 4 deletions helpers/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ export const installTSTemplate = async ({
rename: assetRelocator,
});

// Copy attachments for form filling agent
const attachmentPath = path.join(useCasePath, "attachments");
await copy("**", path.join(root), {
// Copy use case files to project root
await copy("*.*", path.join(root), {
parents: true,
cwd: attachmentPath,
cwd: useCasePath,
rename: assetRelocator,
});
} else {
console.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Decision (respond with either 'not_publish' or 'publish'):`;
new AgentRunEvent({
agent: "writer",
text: `Too many attempts (${MAX_ATTEMPTS}) to write the blog post. Proceeding with the current version.`,
type: "text",
}),
);
}
Expand Down Expand Up @@ -184,6 +185,7 @@ Decision (respond with either 'not_publish' or 'publish'):`;
text: `The post is ${postIsGood ? "" : "not "}good enough for publishing. Sending back to the writer${
postIsGood ? " for publication." : "."
}`,
type: "text",
}),
);
if (postIsGood) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
This is a [LlamaIndex](https://www.llamaindex.ai/) project using [Next.js](https://nextjs.org/) bootstrapped with [`create-llama`](https://github.com/run-llama/LlamaIndexTS/tree/main/packages/create-llama).

## Getting Started

First, install the dependencies:

```
npm install
```

Then check the parameters that have been pre-configured in the `.env` file in this directory.
Make sure you have the `OPENAI_API_KEY` set.

Second, generate the embeddings of the documents in the `./data` directory:

```
npm run generate
```

Third, run the development server:

```
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the chat UI.

## Use Case: Filling Financial CSV Template

You can start by sending an request on the chat UI to create a report comparing the finances of Apple and Tesla.
Or you can test the `/api/chat` endpoint with the following curl request:

```
curl --location 'localhost:3000/api/chat' \
--header 'Content-Type: application/json' \
--data '{ "messages": [{ "role": "user", "content": "Create a report comparing the finances of Apple and Tesla" }] }'
```

## Learn More

To learn more about LlamaIndex, take a look at the following resources:

- [LlamaIndex Documentation](https://docs.llamaindex.ai) - learn about LlamaIndex.
- [Workflows Introduction](https://docs.llamaindex.ai/en/stable/understanding/workflows/) - learn about LlamaIndex workflows.

You can check out [the LlamaIndex GitHub repository](https://github.com/run-llama/llama_index) - your feedback and contributions are welcome!
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export class FinancialReportWorkflow extends Workflow<
new AgentRunEvent({
agent: "Analyst",
text: `Starting analysis`,
type: "text",
}),
);
// Request by workflow LLM, input is a list of tool calls
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [LlamaIndex](https://www.llamaindex.ai/) project using [Next.js](https://nextjs.org/) bootstrapped with [`create-llama`](https://github.com/run-llama/LlamaIndexTS/tree/main/packages/create-llama).

## Getting Started

First, install the dependencies:

```
npm install
```

Then check the parameters that have been pre-configured in the `.env` file in this directory.
Make sure you have the `OPENAI_API_KEY` set.

Second, run the development server:

```
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the chat UI.

## Use Case: Filling Financial CSV Template

1. Upload the Apple and Tesla financial reports from the [data](./data) directory. Just send an empty message.
2. Upload the CSV file [sec_10k_template.csv](./sec_10k_template.csv) and send the message "Fill the missing cells in the CSV file".
Comment on lines +24 to +25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

The "./data" directory referenced in the README does not exist.

Please update the file path to the existing location of "sec_10k_template.csv" or add the missing "data" directory.

🔗 Analysis chain

Verify the existence and paths of referenced files.

Let's verify that the referenced files exist in the repository.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the referenced data files exist

# Check for the data directory and CSV template
fd -t f "sec_10k_template.csv" 
fd -t d "data" --max-depth 1

Length of output: 201


The agent will fill the missing cells by retrieving the information from the uploaded financial reports and return a new CSV file with the filled cells.

## Learn More

To learn more about LlamaIndex, take a look at the following resources:

- [LlamaIndex Documentation](https://docs.llamaindex.ai) - learn about LlamaIndex.
- [Workflows Introduction](https://docs.llamaindex.ai/en/stable/understanding/workflows/) - learn about LlamaIndex workflows.

You can check out [the LlamaIndex GitHub repository](https://github.com/run-llama/llama_index) - your feedback and contributions are welcome!
3 changes: 1 addition & 2 deletions templates/components/multiagent/typescript/nextjs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export async function POST(request: NextRequest) {
const { stream, dataStream } =
await createStreamFromWorkflowContext(context);

// Return using the new Response API
// TODO: StreamingTextResponse has been deprecated
// Return the two streams in one response
return new StreamingTextResponse(stream, {}, dataStream);
} catch (error) {
console.error("[LlamaIndex]", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export class FunctionCallingAgent extends Workflow<
ctx: HandlerContext<FunctionCallingAgentContextData>,
) => {
if (!this.writeEvents) return;
ctx.sendEvent(new AgentRunEvent({ agent: this.name, text: msg }));
ctx.sendEvent(
new AgentRunEvent({ agent: this.name, text: msg, type: "text" }),
);
};
}
14 changes: 1 addition & 13 deletions templates/components/multiagent/typescript/workflow/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,4 @@ export class AgentRunEvent extends WorkflowEvent<{
text: string;
type: AgentRunEventType;
data?: AgentRunEventData;
}> {
constructor(options: {
agent: string;
text: string;
type?: AgentRunEventType;
data?: AgentRunEventData;
}) {
super({
...options,
type: options.type || "text",
});
}
}
}> {}
Loading