This Python script prompts the user to input a company name and retrieves information about the company using OpenAI and SerpAPIWrapper.
- Python 3.7 or higher
Additionally, you need to set the following environment variables with your API keys:
OPENAI_API_KEY
: Your OpenAI API keySERPAPI_API_KEY
: Your SerpAPIWrapper API key
export OPENAI_API_KEY=your_openai_api_key
export SERPAPI_API_KEY=your_serpapi_api_key
- Clone the project
- Install dependencies
pip install -r requirements.txt
- Open a terminal and navigate to the directory where the script is located.
- Run the script with the command
python main.py
. - When prompted, enter the name of the company you want to retrieve information for. If you do not enter anything, the default value is
Prematch GmbH
as in the Linkedin original post. - The script will then use the LangChain library to retrieve the following information about the company:
- Description
- Founders
- Funding rounds
- Location
- Website
- The script will print out the retrieved information.
The readme.md
file provides a brief overview of how to use the script. Here is a more detailed description of what the script does:
- The script imports the necessary modules from the
langchain
package, as well as theos
module. - A prompt template is defined using a string. The template includes a placeholder for the company name.
- The user is prompted to input a company name using the
input
function. If the user does not enter anything, the default value isPrematch GmbH
. - A
PromptTemplate
object is created using thetemplate
string and theinput_variables
parameter. Theinput_variables
parameter specifies that thecompany
variable will be used in thetemplate
. - The OpenAI API key and the SerpAPIWrapper API key are retrieved from environment variables using the
os.environ.get
function. - An
OpenAI
object is created using the retrieved API key, a temperature of 0, and thetext-davinci-003
model. - A
SerpAPIWrapper
object is created using the retrieved API key. - A
Tool
object is created using thesearch.run
method from theSerpAPIWrapper
object, along with a name, description, and function. - An
Agent
object is created using theinitialize_agent
function from thelangchain.agents
module. TheAgent
object uses thesearch_tool
andllm
objects, and specifies that it is anAgentType.SELF_ASK_WITH_SEARCH
agent. - The prompt string is formatted with the
company
variable using theformat
method, and is printed to the console. - The
run
method of theAgent
object is called with the formatted prompt string as an argument. Therun
method retrieves the requested information from OpenAI and SerpAPIWrapper and prints it to the console.
The idea of the project originated from a Linkedin post by Dries Faems