Helper functions to generate OpenAI GPT function calling requests.
Project description
OpenAI Function Calling
Helper functions to generate OpenAI ChatGPT function calling requests. See the official Function Calling reference for more information.
Installation
Install from PyPi with:
pip install openai-function-calling
Usage
from openai_function_calling import Function, FunctionDict, Parameter
def get_current_weather(location: str, unit: str) -> str:
# Do some stuff here...
# Define the function parameters.
location_parameter = Parameter(
name="location",
type="string",
description="The city and state, e.g. San Francisco, CA"
)
unit_parameter = Parameter(
name="unit",
type="string",
description="The temperature unit to use.",
enum=["celsius", "fahrenheit"]
)
# Define the function.
get_current_weather_function = Function(
"get_current_weather",
"Get the current weather",
[location_parameter, unit_parameter],
)
# Convert to a JSON schema dict to send to OpenAI.
get_current_weather_function_dict = get_current_weather_function.to_dict()
# Get the function to call from ChatGPT.
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=[
{"role": "user", "content": "What will the weather be like in Boston, MA tomorrow?"}
],
functions=[get_current_weather_function_dict],
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file openai_function_calling-0.1.0.tar.gz
.
File metadata
- Download URL: openai_function_calling-0.1.0.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7688a227b2f4ec575dc962e4f6982481a92528c98695c6f5f6bc4c0f4d6f8fd2 |
|
MD5 | a40fa79b277f3d2fb5750ebb616e47a8 |
|
BLAKE2b-256 | dfcd7a39543accd71af0ad2f916b8d1c510e85f99a07a971ffb29bb8071524f5 |
File details
Details for the file openai_function_calling-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: openai_function_calling-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce3de49e495f409a33e043bccc4ba56884ab2ea7bb092601a4a247a54b61806f |
|
MD5 | dd1e79269a1a8cb80509e8e644c7616d |
|
BLAKE2b-256 | 25cf79a3dd61d596ebddd5d0033815ec790451cfdd33b571cb9dd92904184ce9 |