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 deep research use case (Python) #482

Merged
merged 27 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions helpers/datasources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export const EXAMPLE_GDPR: TemplateDataSource = {
},
};

export const AI_REPORTS: TemplateDataSource = {
type: "file",
config: {
url: new URL(
"https://www.europarl.europa.eu/RegData/etudes/ATAG/2024/760392/EPRS_ATA(2024)760392_EN.pdf",
),
filename: "EPRS_ATA_2024_760392_EN.pdf",
},
};

export function getDataSources(
files?: string,
exampleFile?: boolean,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@types/cross-spawn": "6.0.0",
"@types/fs-extra": "11.0.4",
"@types/node": "^20.11.7",
"@types/prompts": "2.0.1",
"@types/prompts": "2.4.2",
"@types/tar": "6.1.5",
"@types/validate-npm-package-name": "3.0.0",
"async-retry": "1.3.1",
Expand Down
13 changes: 8 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 55 additions & 9 deletions questions/simple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import prompts from "prompts";
import {
AI_REPORTS,
EXAMPLE_10K_SEC_FILES,
EXAMPLE_FILE,
EXAMPLE_GDPR,
Expand All @@ -17,7 +18,8 @@ type AppType =
| "form_filling"
| "extractor"
| "contract_review"
| "data_scientist";
| "data_scientist"
| "blog";
leehuwuj marked this conversation as resolved.
Show resolved Hide resolved

type SimpleAnswers = {
appType: AppType;
Expand All @@ -34,22 +36,55 @@ export const askSimpleQuestions = async (
type: "select",
name: "appType",
message: "What app do you want to build?",
hint: "🤖: Agent, 🔀: Workflow",
choices: [
{ title: "Agentic RAG", value: "rag" },
{ title: "Data Scientist", value: "data_scientist" },
{
title: "Financial Report Generator (using Workflows)",
title: "🤖 Agentic RAG",
value: "rag",
description:
"Build a chatbot that can answer questions based on provided documents.",
},
{
title: "🤖 Data Scientist",
value: "data_scientist",
description:
"An data scientist agent that can analyze data and generate visualizations by using a code interpreter.",
},
{
title: "🤖 Code Artifact Agent",
value: "code_artifact",
description:
"An agent that can write code, run it in a sandboxed environment, and finally show the output in the chat UI.",
},
{
title: "🤖 Information Extractor",
value: "extractor",
description:
"Extract information from provided documents and return it as a structured JSON object by defining a Pydantic model.",
},
{
title: "🔀 Financial Report Generator",
value: "financial_report_agent",
description:
"Generate a financial report by analyzing the provided 10-K SEC data and use a code interpreter to create charts or conduct further analysis.",
},
{
title: "Form Filler (using Workflows)",
title: "🔀 Financial 10k SEC Form Filler",
value: "form_filling",
description:
"Extract information from 10k SEC data and use it to fill out a CSV form template.",
},
{ title: "Code Artifact Agent", value: "code_artifact" },
{ title: "Information Extractor", value: "extractor" },
{
title: "Contract Review (using Workflows)",
title: "🔀 Contract Review",
value: "contract_review",
description:
"Extract and review contracts to ensure compliance with regulations (GDPR)",
},
{
title: "🔀 Blog Writer",
value: "blog",
description:
"Write a blog post by analyzing the provided data from different perspectives and crafting a coherent blog post with citations to the data.",
},
],
},
Expand All @@ -60,7 +95,11 @@ export const askSimpleQuestions = async (
let llamaCloudKey = args.llamaCloudKey;
let useLlamaCloud = false;

if (appType !== "extractor" && appType !== "contract_review") {
if (
appType !== "extractor" &&
appType !== "contract_review" &&
appType !== "blog"
) {
const { language: newLanguage } = await prompts(
{
type: "select",
Expand Down Expand Up @@ -188,6 +227,13 @@ const convertAnswers = async (
frontend: false,
dataSources: [EXAMPLE_GDPR],
},
blog: {
template: "multiagent",
useCase: "blog",
tools: [],
frontend: true,
dataSources: [AI_REPORTS],
},
};
const results = lookup[answers.appType];
return {
Expand Down
35 changes: 6 additions & 29 deletions templates/components/agents/python/blog/README-template.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
## Overview

This example is using three agents to generate a blog post:

- a researcher that retrieves content via a RAG pipeline,
- a writer that specializes in writing blog posts and
- a reviewer that is reviewing the blog post.

There are three different methods how the agents can interact to reach their goal:

1. [Choreography](./app/agents/choreography.py) - the agents decide themselves to delegate a task to another agent
1. [Orchestrator](./app/agents/orchestrator.py) - a central orchestrator decides which agent should execute a task
1. [Explicit Workflow](./app/agents/workflow.py) - a pre-defined workflow specific for the task is used to execute the tasks
This is a [LlamaIndex](https://www.llamaindex.ai/) multi-agents project using [Workflows](https://docs.llamaindex.ai/en/stable/understanding/workflows/).

## Getting Started

Expand All @@ -35,25 +23,14 @@ Third, run the development server:
poetry run dev
```

Per default, the example is using the explicit workflow. You can change the example by setting the `EXAMPLE_TYPE` environment variable to `choreography` or `orchestrator`.
The example provides one streaming API endpoint `/api/chat`.
You can test the endpoint with the following curl request:

```
curl --location 'localhost:8000/api/chat' \
--header 'Content-Type: application/json' \
--data '{ "messages": [{ "role": "user", "content": "Write a blog post about physical standards for letters" }] }'
```

You can start editing the API by modifying `app/api/routers/chat.py` or `app/examples/workflow.py`. The API auto-updates as you save the files.
## Use Case: Blog writer

Open [http://localhost:8000](http://localhost:8000) with your browser to start the app.
The workflow writes blog posts based on documents in the [data](./data) directory. You can start with the included PDF about AI investment in 2024, or add your own documents and run generate script again.

To start the app optimized for **production**, run:
After starting the server, go to [http://localhost:8000](http://localhost:8000) and send a message to the agent to write a blog post.
E.g: "Write a post about AI investment in 2024"

```
poetry run prod
```
To update the workflow, you can edit the [writer.py](./app/workflows/writer.py) file.

## Deployments

Expand Down
34 changes: 0 additions & 34 deletions templates/components/agents/python/blog/app/agents/choreography.py

This file was deleted.

44 changes: 0 additions & 44 deletions templates/components/agents/python/blog/app/agents/orchestrator.py

This file was deleted.

35 changes: 0 additions & 35 deletions templates/components/agents/python/blog/app/agents/publisher.py

This file was deleted.

Loading
Loading