Skip to main content

GPT-Funcs

Automatically pass your funcions defined in Python to ChatGPT have it call them back seemlessly.

You can do all that in a single line:

gptfuncs.add_function_hooks("funcs.py", lambda funcs: openai_api("Say hi", funcs))

Under the hood

gptfuncs.add_function_hooks():

  • Loads a python file specified as the parameter and encodes the function signatures to JSON
  • Calls back the functions dynamically after ChatGPT responds

Use PEP-8 style to document your function signatures (see funcs.py for an example.)

Example

def chat_completion_request(messages, functions=None, model=None):
    # post request to OpenAI api
    # ...

# Our functions are defined in funcs.py so we just pass that in to gptfuncs.add_function_hooks
# and in handles everything
res = gptfuncs.add_function_hooks("funcs.py", lambda funcs: chat_completion_request(
  model="gpt-3.5-turbo-0613",
  messages=[{"role": "user", "content": "Sing me a poem about Hackernews."}],
  functions=funcs
))

# normal api result after all the functions have been called
print(res)

funcs.py:

import os
import subprocess


def play_music(audio_data_hex):
    """
    Play music to user.

    Args:
        audio_data_hex (string): Hex representation of the raw audio binary data with 44100 sample rate.
    """
    bin_data = base64.b64decode(audio_data_hex)
    file_path = "/tmp/a.mp3"
    with open(file_path, "wb") as file:
        file.write(bin_data)

    print(f"Binary file saved as: {file_path}")
    os.system("/usr/bin/afplay " + file_path)


def speak(sentence, spoken_speed=210):
    """
    Convert the sentence to spoken words and speak it to user.

    Args:
        sentence (string): English sentence that should be spoken.
        spoken_speed (number): A value from 100 to 300 determining how fast the sentence is spoken.
    """
    subprocess.Popen(['say', '-v', 'Karen', '-r', str(spoken_speed), sentence])

Metadata

Release files for gptfuncs 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gptfuncs 1.0.0
File Size Uploaded Provenance Actions
gptfuncs-1.0.0.tar.gz 2.1 kB Without provenance Details for gptfuncs-1.0.0.tar.gz

Release files / gptfuncs-1.0.0.tar.gz

Download URL gptfuncs-1.0.0.tar.gz
Size 2.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2e1a6f38ce409bac54b9d9333d9c60479cd5e89b9c4d67c32f19f283ac7b85d8
BLAKE2b-256 checksum
How to use checksums
5eae3d9608cc6cd1a71b1854cf581bd4222c1ca5e6a38c4f76e7a7fed903592f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for gptfuncs 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page