Title: OpenAI functions with Chainlit Tags: [openai-functions]
This folder is showing how to use OpenAI functions with Chainlit.
OpenAI functions enable GPT to use functions you defined in your code. To run the example, follow the instructions of the main readme.
To get started with using OpenAI functions in Chainlit, follow these steps:
- Clone the repository and navigate to the
openai-functions
directory. - Ensure you have an OpenAI API key and set it as an environment variable
OPENAI_API_KEY
. - Define your custom functions that you want GPT to use. For example, a simple weather function is provided:
def get_current_weather(location, unit="Fahrenheit"):
"""Get the current weather in a given location"""
weather_info = {
"location": location,
"temperature": "72",
"unit": unit,
"forecast": ["sunny", "windy"],
}
return json.dumps(weather_info)
- Use the
@cl.step
decorator to create steps that call your custom functions and handle the interaction with the GPT model. - Run your Chainlit app using the provided
app.py
as a starting point. - Interact with your application through the Chainlit interface, where you can chat with GPT-4 and it will use your custom functions to respond.
Remember to follow the instructions in the main readme for setting up your Chainlit environment.
Title: OpenAI functions with Chainlit
Tags: [open-ai, functions]