I created a Geography quiz question creating function, which is used by the Assistant. The idea with function calling is that the assistant can populate the arguments of our function and also act upon the return value if there is one.
The quiz.ipynb
notebook provides an example to how we can use Function Calling with the OpenAI Assistants API.
Building on the knowledge from the previous example, I extended the function calling capability first by calling 2 functions parallel (parallel_function_calls.py
) and then, used the Weather API
and the Air Quality API
by Open Meteo to demonstrate this functionality whith a real world application example. (current-weather.ipynb
)
-
Prerequisites:
- Make sure Python3 is installed.
- If you don't have an account with OpenAI, create one here: https://openai.com/ then create a project API key under Dashboard / API keys.
-
Clone the project.
-
Create a virtual environment inside the project folder:
python -m venv venv
-
Activate the virtual environment:
Mac:
source venv/bin/activate
Windows:
venv\Scripts\activate
-
Select interpreter in VSCode:
(on Mac) - Cmd + Shift + P ---> Select Interpreter ---> Select the created
venv
environment(on Windows) -
-
Install the python dependencies:
pip install -r requirements.txt
-
Create an
.env
file in the root folder and add your project's API key:OPENAI_API_KEY=your-unique-opanai-project-key
-
Run Jupyter Notebook:
jupyter notebook
-
Run the code snippets in the given/desired order.