Learn to use OpenAI’s tool call feature with Exa’s Search Integration
Pre-requisites and installation
openai
library to perform OpenAI API calls and completionsexa_py
library to perform Exa searchrich
library to make the output more readableSet up the environment variables
.env
file in the root of your project and set the EXA_API_KEY
and OPENAI_API_KEY
environment variable to your API keys respectively. Visit the OpenAI playground and the Exa dashboard to generate your API keys.What is OpenAI tool calling?
exa_search
function we define with the arguments provided.Use Exa Search as an OpenAI tool
SYSTEM_MESSAGE
, which explains to OpenAI what it is supposed to do:exa_search
function that will call Exa’s search_and_contents
function with the query:main
function to bring it all together, and handle the user input and interaction with OpenAI:Running the code
openai_search.py
, and make sure the .env
file containing the API keys we previously created is in the same directory as the script.Then run the script using the following command from your terminal: