Skip to main content

PIP Package

๐ŸŒŸ Exciting News! Now, you can integrate gpt-researcher with your apps seamlessly!

Steps to Install GPT Researcher ๐Ÿ› ๏ธ

Follow these easy steps to get started:

  1. Pre-requisite: Ensure Python 3.10+ is installed on your machine ๐Ÿ’ป
  2. Install gpt-researcher: Grab the official package from PyPi.
pip install gpt-researcher
  1. Environment Variables: Create a .env file with your OpenAI API key or simply export it
export OPENAI_API_KEY={Your OpenAI API Key here}
export TAVILY_API_KEY={Your Tavily API Key here}
  1. Start using GPT Researcher in your own codebase

Example Usage ๐Ÿ“

from gpt_researcher import GPTResearcher
import asyncio


async def get_report(query: str, report_type: str) -> str:
researcher = GPTResearcher(query, report_type)
report = await researcher.run()
return report

if __name__ == "__main__":
query = "what team may win the NBA finals?"
report_type = "research_report"

report = asyncio.run(get_report(query, report_type))
print(report)

Specific Examples ๐ŸŒ

Example 1: Research Report ๐Ÿ“š

query = "Latest developments in renewable energy technologies"
report_type = "research_report"

Example 2: Resource Report ๐Ÿ“‹

query = "List of top AI conferences in 2023"
report_type = "resource_report"

Example 3: Outline Report ๐Ÿ“

query = "Outline for an article on the impact of AI in education"
report_type = "outline_report"

Integration with Web Frameworks ๐ŸŒ

FastAPI Example

from fastapi import FastAPI
from gpt_researcher import GPTResearcher
import asyncio

app = FastAPI()

@app.get("/report/{report_type}")
async def get_report(report_type: str, query: str):
researcher = GPTResearcher(query, report_type)
report = await researcher.run()
return {"report": report}

# Run the server
# uvicorn main:app --reload

Flask Example

from flask import Flask, request
from gpt_researcher import GPTResearcher
import asyncio

app = Flask(__name__)

@app.route('/report/<report_type>', methods=['GET'])
def get_report(report_type):
query = request.args.get('query')
report = asyncio.run(GPTResearcher(query, report_type).run())
return report

# Run the server
# flask run