diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..7c1bb4ec4 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +OPENAI_API_KEY= +TAVILY_API_KEY= \ No newline at end of file diff --git a/README.md b/README.md index 417758fc6..0ebde5488 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,21 @@ An average run generates a 5-6 page research report in multiple formats such as Check it out [here](https://github.com/assafelovic/gpt-researcher/tree/master/multi_agents) or head over to our [documentation](https://docs.gptr.dev/docs/gpt-researcher/langgraph) for more information. +## 🖥️ Frontend Applications + +GPT-Researcher now features an enhanced frontend to improve the user experience and streamline the research process. The frontend offers: + +- An intuitive interface for inputting research queries +- Real-time progress tracking of research tasks +- Interactive display of research findings +- Customizable settings for tailored research experiences + +Two deployment options are available: +1. A lightweight static frontend served by FastAPI +2. A feature-rich NextJS application for advanced functionality + +For detailed setup instructions and more information about the frontend features, please visit our [documentation page](https://docs.gptr.dev/docs/gpt-researcher/frontend). + ## 🚀 Contributing We highly welcome contributions! Please check out [contributing](https://github.com/assafelovic/gpt-researcher/blob/master/CONTRIBUTING.md) if you're interested. diff --git a/application/next-env.d.ts b/application/next-env.d.ts deleted file mode 100644 index 4f11a03dc..000000000 --- a/application/next-env.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/// -/// - -// NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/docker-compose.yml b/docker-compose.yml index 71a15044a..55a91c56b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,10 +19,10 @@ services: - CHOKIDAR_USEPOLLING=true build: dockerfile: Dockerfile.dev - context: multi_agents/frontend + context: frontend/nextjs volumes: - /app/node_modules - - ./multi_agents/frontend:/app + - ./frontend/nextjs:/app restart: always ports: - 3000:3000 diff --git a/docs/docs/gpt-researcher/frontend.md b/docs/docs/gpt-researcher/frontend.md new file mode 100644 index 000000000..b7df49cdd --- /dev/null +++ b/docs/docs/gpt-researcher/frontend.md @@ -0,0 +1,86 @@ +# Frontend Application + +This frontend project aims to enhance the user experience of GPT-Researcher, providing an intuitive and efficient interface for automated research. It offers two deployment options to suit different needs and environments. + +## Option 1: Static Frontend (FastAPI) + +A lightweight solution using FastAPI to serve static files. + +#### Prerequisites +- Python 3.11+ +- pip + +#### Setup and Running + +1. Install required packages: + ``` + pip install -r requirements.txt + ``` + +2. Start the server: + ``` + python -m uvicorn main:app + ``` + +3. Access at `http://localhost:8000` + +#### Demo + + + +## Option 2: NextJS Frontend + +A more robust solution with enhanced features and performance. + +#### Prerequisites +- Node.js (v18.17.0 recommended) +- npm + +#### Setup and Running + +1. Navigate to NextJS directory: + ``` + cd nextjs + ``` + +2. Set up Node.js: + ``` + nvm install 18.17.0 + nvm use v18.17.0 + ``` + +3. Install dependencies: + ``` + npm install --legacy-peer-deps + ``` + +4. Start development server: + ``` + npm run dev + ``` + +5. Access at `http://localhost:3000` + +Note: Requires backend server on `localhost:8000` as detailed in option 1. + +#### Demo + + +## Choosing an Option + +- Static Frontend: Quick setup, lightweight deployment. +- NextJS Frontend: Feature-rich, scalable, better performance and SEO. + +For production, NextJS is recommended. + +## Frontend Features + +Our frontend enhances GPT-Researcher by providing: + +1. Intuitive Research Interface: Streamlined input for research queries. +2. Real-time Progress Tracking: Visual feedback on ongoing research tasks. +3. Interactive Results Display: Easy-to-navigate presentation of findings. +4. Customizable Settings: Adjust research parameters to suit specific needs. +5. Responsive Design: Optimal experience across various devices. + +These features aim to make the research process more efficient and user-friendly, complementing GPT-Researcher's powerful agent capabilities. \ No newline at end of file diff --git a/docs/sidebars.js b/docs/sidebars.js index 600b85424..f313e1778 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -21,6 +21,7 @@ 'gpt-researcher/introduction', 'gpt-researcher/getting-started', 'gpt-researcher/pip-package', + 'gpt-researcher/frontend', 'gpt-researcher/example', 'gpt-researcher/troubleshooting', ], @@ -34,8 +35,8 @@ 'gpt-researcher/config', 'gpt-researcher/tailored-research', 'gpt-researcher/retrievers', - 'gpt-researcher/vector-stores', 'gpt-researcher/llms', + 'gpt-researcher/vector-stores', ] }, { diff --git a/frontend/README.md b/frontend/README.md new file mode 100644 index 000000000..0c81ace3b --- /dev/null +++ b/frontend/README.md @@ -0,0 +1,85 @@ +# Frontend Application + +This frontend project aims to enhance the user experience of GPT-Researcher, providing an intuitive and efficient interface for automated research. It offers two deployment options to suit different needs and environments. + +## Option 1: Static Frontend (FastAPI) + +A lightweight solution using FastAPI to serve static files. + +#### Prerequisites +- Python 3.11+ +- pip + +#### Setup and Running + +1. Install required packages: + ``` + pip install -r requirements.txt + ``` + +2. Start the server: + ``` + python -m uvicorn main:app + ``` + +3. Access at `http://localhost:8000` + +#### Demo +https://github.com/assafelovic/gpt-researcher/assets/13554167/dd6cf08f-b31e-40c6-9907-1915f52a7110 + +## Option 2: NextJS Frontend + +A more robust solution with enhanced features and performance. + +#### Prerequisites +- Node.js (v18.17.0 recommended) +- npm + +#### Setup and Running + +1. Navigate to NextJS directory: + ``` + cd nextjs + ``` + +2. Set up Node.js: + ``` + nvm install 18.17.0 + nvm use v18.17.0 + ``` + +3. Install dependencies: + ``` + npm install --legacy-peer-deps + ``` + +4. Start development server: + ``` + npm run dev + ``` + +5. Access at `http://localhost:3000` + +Note: Requires backend server on `localhost:8000` as detailed in option 1. + +#### Demo +https://github.com/user-attachments/assets/092e9e71-7e27-475d-8c4f-9dddd28934a3 + +## Choosing an Option + +- Static Frontend: Quick setup, lightweight deployment. +- NextJS Frontend: Feature-rich, scalable, better performance and SEO. + +For production, NextJS is recommended. + +## Frontend Features + +Our frontend enhances GPT-Researcher by providing: + +1. Intuitive Research Interface: Streamlined input for research queries. +2. Real-time Progress Tracking: Visual feedback on ongoing research tasks. +3. Interactive Results Display: Easy-to-navigate presentation of findings. +4. Customizable Settings: Adjust research parameters to suit specific needs. +5. Responsive Design: Optimal experience across various devices. + +These features aim to make the research process more efficient and user-friendly, complementing GPT-Researcher's powerful agent capabilities. \ No newline at end of file diff --git a/multi_agents/frontend/.dockerignore b/frontend/nextjs/.dockerignore similarity index 100% rename from multi_agents/frontend/.dockerignore rename to frontend/nextjs/.dockerignore diff --git a/multi_agents/frontend/.eslintrc.json b/frontend/nextjs/.eslintrc.json similarity index 100% rename from multi_agents/frontend/.eslintrc.json rename to frontend/nextjs/.eslintrc.json diff --git a/multi_agents/frontend/.example.env b/frontend/nextjs/.example.env similarity index 100% rename from multi_agents/frontend/.example.env rename to frontend/nextjs/.example.env diff --git a/multi_agents/frontend/.gitignore b/frontend/nextjs/.gitignore similarity index 100% rename from multi_agents/frontend/.gitignore rename to frontend/nextjs/.gitignore diff --git a/multi_agents/frontend/.prettierrc b/frontend/nextjs/.prettierrc similarity index 100% rename from multi_agents/frontend/.prettierrc rename to frontend/nextjs/.prettierrc diff --git a/multi_agents/frontend/Dockerfile b/frontend/nextjs/Dockerfile similarity index 100% rename from multi_agents/frontend/Dockerfile rename to frontend/nextjs/Dockerfile diff --git a/multi_agents/frontend/Dockerfile.dev b/frontend/nextjs/Dockerfile.dev similarity index 100% rename from multi_agents/frontend/Dockerfile.dev rename to frontend/nextjs/Dockerfile.dev diff --git a/multi_agents/frontend/README.md b/frontend/nextjs/README.md similarity index 100% rename from multi_agents/frontend/README.md rename to frontend/nextjs/README.md diff --git a/multi_agents/frontend/actions/apiActions.ts b/frontend/nextjs/actions/apiActions.ts similarity index 100% rename from multi_agents/frontend/actions/apiActions.ts rename to frontend/nextjs/actions/apiActions.ts diff --git a/multi_agents/frontend/app/favicon.ico b/frontend/nextjs/app/favicon.ico similarity index 100% rename from multi_agents/frontend/app/favicon.ico rename to frontend/nextjs/app/favicon.ico diff --git a/multi_agents/frontend/app/globals.css b/frontend/nextjs/app/globals.css similarity index 100% rename from multi_agents/frontend/app/globals.css rename to frontend/nextjs/app/globals.css diff --git a/multi_agents/frontend/app/layout.tsx b/frontend/nextjs/app/layout.tsx similarity index 100% rename from multi_agents/frontend/app/layout.tsx rename to frontend/nextjs/app/layout.tsx diff --git a/multi_agents/frontend/app/page.tsx b/frontend/nextjs/app/page.tsx similarity index 94% rename from multi_agents/frontend/app/page.tsx rename to frontend/nextjs/app/page.tsx index 377092421..1018a6bd7 100644 --- a/multi_agents/frontend/app/page.tsx +++ b/frontend/nextjs/app/page.tsx @@ -200,8 +200,9 @@ export default function Home() { let currentReportGroup = null; let finalReportGroup = null; let sourceBlockEncountered = false; + let lastSubqueriesIndex = -1; - data.forEach((item) => { + data.forEach((item, index) => { const { type, content, metadata, output, link } = item; if (type === 'report') { @@ -234,10 +235,26 @@ export default function Home() { currentSourceGroup = null; } groupedData.push(item); + lastSubqueriesIndex = groupedData.length - 1; + } else if (type === 'sourceBlock') { + currentSourceGroup = item; + if (lastSubqueriesIndex !== -1) { + groupedData.splice(lastSubqueriesIndex + 1, 0, currentSourceGroup); + lastSubqueriesIndex = -1; + } else { + groupedData.push(currentSourceGroup); + } + sourceBlockEncountered = true; + currentSourceGroup = null; } else if (content === 'added_source_url') { if (!currentSourceGroup) { currentSourceGroup = { type: 'sourceBlock', items: [] }; - groupedData.push(currentSourceGroup); + if (lastSubqueriesIndex !== -1) { + groupedData.splice(lastSubqueriesIndex + 1, 0, currentSourceGroup); + lastSubqueriesIndex = -1; + } else { + groupedData.push(currentSourceGroup); + } sourceBlockEncountered = true; } const hostname = new URL(metadata).hostname.replace('www.', ''); diff --git a/multi_agents/frontend/components/Answer.tsx b/frontend/nextjs/components/Answer.tsx similarity index 100% rename from multi_agents/frontend/components/Answer.tsx rename to frontend/nextjs/components/Answer.tsx diff --git a/multi_agents/frontend/components/Footer.tsx b/frontend/nextjs/components/Footer.tsx similarity index 100% rename from multi_agents/frontend/components/Footer.tsx rename to frontend/nextjs/components/Footer.tsx diff --git a/multi_agents/frontend/components/Header.tsx b/frontend/nextjs/components/Header.tsx similarity index 100% rename from multi_agents/frontend/components/Header.tsx rename to frontend/nextjs/components/Header.tsx diff --git a/multi_agents/frontend/components/Hero.tsx b/frontend/nextjs/components/Hero.tsx similarity index 100% rename from multi_agents/frontend/components/Hero.tsx rename to frontend/nextjs/components/Hero.tsx diff --git a/multi_agents/frontend/components/HumanFeedback.tsx b/frontend/nextjs/components/HumanFeedback.tsx similarity index 100% rename from multi_agents/frontend/components/HumanFeedback.tsx rename to frontend/nextjs/components/HumanFeedback.tsx diff --git a/multi_agents/frontend/components/InputArea.tsx b/frontend/nextjs/components/InputArea.tsx similarity index 100% rename from multi_agents/frontend/components/InputArea.tsx rename to frontend/nextjs/components/InputArea.tsx diff --git a/multi_agents/frontend/components/Langgraph/Langgraph.js b/frontend/nextjs/components/Langgraph/Langgraph.js similarity index 100% rename from multi_agents/frontend/components/Langgraph/Langgraph.js rename to frontend/nextjs/components/Langgraph/Langgraph.js diff --git a/multi_agents/frontend/components/Question.tsx b/frontend/nextjs/components/Question.tsx similarity index 100% rename from multi_agents/frontend/components/Question.tsx rename to frontend/nextjs/components/Question.tsx diff --git a/multi_agents/frontend/components/Search.tsx b/frontend/nextjs/components/Search.tsx similarity index 100% rename from multi_agents/frontend/components/Search.tsx rename to frontend/nextjs/components/Search.tsx diff --git a/multi_agents/frontend/components/Settings/App.css b/frontend/nextjs/components/Settings/App.css similarity index 100% rename from multi_agents/frontend/components/Settings/App.css rename to frontend/nextjs/components/Settings/App.css diff --git a/multi_agents/frontend/components/Settings/ChatBox.js b/frontend/nextjs/components/Settings/ChatBox.js similarity index 100% rename from multi_agents/frontend/components/Settings/ChatBox.js rename to frontend/nextjs/components/Settings/ChatBox.js diff --git a/multi_agents/frontend/components/Settings/FileUpload.js b/frontend/nextjs/components/Settings/FileUpload.js similarity index 100% rename from multi_agents/frontend/components/Settings/FileUpload.js rename to frontend/nextjs/components/Settings/FileUpload.js diff --git a/multi_agents/frontend/components/Settings/Modal.js b/frontend/nextjs/components/Settings/Modal.js similarity index 100% rename from multi_agents/frontend/components/Settings/Modal.js rename to frontend/nextjs/components/Settings/Modal.js diff --git a/multi_agents/frontend/components/Settings/ToneSelector.js b/frontend/nextjs/components/Settings/ToneSelector.js similarity index 100% rename from multi_agents/frontend/components/Settings/ToneSelector.js rename to frontend/nextjs/components/Settings/ToneSelector.js diff --git a/multi_agents/frontend/components/SimilarTopics.tsx b/frontend/nextjs/components/SimilarTopics.tsx similarity index 100% rename from multi_agents/frontend/components/SimilarTopics.tsx rename to frontend/nextjs/components/SimilarTopics.tsx diff --git a/multi_agents/frontend/components/SourceCard.tsx b/frontend/nextjs/components/SourceCard.tsx similarity index 100% rename from multi_agents/frontend/components/SourceCard.tsx rename to frontend/nextjs/components/SourceCard.tsx diff --git a/multi_agents/frontend/components/Sources.tsx b/frontend/nextjs/components/Sources.tsx similarity index 100% rename from multi_agents/frontend/components/Sources.tsx rename to frontend/nextjs/components/Sources.tsx diff --git a/multi_agents/frontend/components/SubQuestions.tsx b/frontend/nextjs/components/SubQuestions.tsx similarity index 100% rename from multi_agents/frontend/components/SubQuestions.tsx rename to frontend/nextjs/components/SubQuestions.tsx diff --git a/multi_agents/frontend/components/Task/AccessReport.js b/frontend/nextjs/components/Task/AccessReport.js similarity index 100% rename from multi_agents/frontend/components/Task/AccessReport.js rename to frontend/nextjs/components/Task/AccessReport.js diff --git a/multi_agents/frontend/components/Task/Accordion.tsx b/frontend/nextjs/components/Task/Accordion.tsx similarity index 98% rename from multi_agents/frontend/components/Task/Accordion.tsx rename to frontend/nextjs/components/Task/Accordion.tsx index 36f736796..5a86d284b 100644 --- a/multi_agents/frontend/components/Task/Accordion.tsx +++ b/frontend/nextjs/components/Task/Accordion.tsx @@ -103,7 +103,7 @@ const Accordion = ({ logs }) => {