Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai_function_calling-0.1.0.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

openai_function_calling-0.1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file openai_function_calling-0.1.0.tar.gz.

File metadata

File hashes

Hashes for openai_function_calling-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7688a227b2f4ec575dc962e4f6982481a92528c98695c6f5f6bc4c0f4d6f8fd2
MD5 a40fa79b277f3d2fb5750ebb616e47a8
BLAKE2b-256 dfcd7a39543accd71af0ad2f916b8d1c510e85f99a07a971ffb29bb8071524f5

See more details on using hashes here.

File details

Details for the file openai_function_calling-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_function_calling-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce3de49e495f409a33e043bccc4ba56884ab2ea7bb092601a4a247a54b61806f
MD5 dd1e79269a1a8cb80509e8e644c7616d
BLAKE2b-256 25cf79a3dd61d596ebddd5d0033815ec790451cfdd33b571cb9dd92904184ce9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page