Skip to main content

ChatGPT Function Wrapper

Overview

This project provides a Python function wrapper that simplifies the process of converting functions with docstrings into callable functions for ChatGPT. It parses the docstring of a function and creates a description that ChatGPT can use.

Installation

You can install this package using pip:

pip install chatgpt-function

Usage

  1. Import the chatgpt_function module:

    from chatgpt_function import chatgpt_wrapper
    
  2. Define your function with a docstring using the @chatgpt_wrapper decorator:

    @chatgpt_wrapper
    def my_function(my_arg: str) -> str:
        '''This is my function.
    
        Args:
            my_arg (str): This is my argument.
    
        Returns:
            str: This is my return value.
        '''
        return "Hello World!" + my_arg
    
  3. Access the function's description using chatgpt_function():

    function_description = my_function.chatgpt_function()
    

    This will provide you with a JSON-like description that you can use as input to ChatGPT.

  4. Use the function in ChatGPT:

    from openai import ChatCompletion
    
    response = ChatCompletion.create(
        messages=messages,
        functions=[function_description],
        **kwargs
    )
    

License

This project is licensed under the MIT License.

MIT License

Copyright (c) 2023 Ron Heichman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release files for chatgpt-function 0.1.2

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

Source distribution (sdist)

Source distribution for chatgpt-function 0.1.2
File Size Uploaded
chatgpt-function-0.1.2.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chatgpt-function 0.1.2
File Interpreter ABI Platform
chatgpt_function-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / chatgpt-function-0.1.2.tar.gz

Download URL chatgpt-function-0.1.2.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
93a88d83dee640ac032eafe0c86440b95156e7549dd68181d92faff7a9531706
BLAKE2b-256 checksum
How to use checksums
7ed2e579f2d6f493438ffd6eb15e698de0659352eeffd918fb62001c51cd0bd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / chatgpt_function-0.1.2-py3-none-any.whl

Download URL chatgpt_function-0.1.2-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d14edc6df234b14740198dcd04d6e618684e2f4e2ea1fa76350d2271f74e631c
BLAKE2b-256 checksum
How to use checksums
4d8075e3dcffbbf453532febf13b39628c16156a01696f03fcb4759703f9de32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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