Giter VIP home page Giter VIP logo

py2gpt's Introduction

py2gpt

Recently, OpenAI has released the GPT function API that allows models like GPT-4 to "invoke" functions on the user's behalf. The problem is that the format, in which these functions is specified, is JSON Schema, which is relatively niche and hard to work with. This repository addresses this issue. It converts regular Python function declarations into JSON consumable by the OpenAI API.

For example, this Python code:

def get_current_weather(location: str, format: Literal["fahrenheit", "celsius"]):
    """
    Get the current weather
    :param location: The city and state, e.g. San Francisco, CA
    :param format: The temperature unit to use. Infer this from the users location.
    """

Produces the following JSON that matches one of OpenAI's own examples:

{
    'name': 'get_current_weather',
    'description': 'Get the current weather',
    'parameters': {
        'type': 'object',
        'properties': {
            'location': {
                'description': 'The city and state, e.g. San Francisco, CA',
                'type': 'string'
            },
            'format': {
                'description': 'The temperature unit to use. Infer this from the
users location.',
                'type': 'string',
                'enum': ('fahrenheit', 'celsius')
            }
        }
    },
    'required': ['location', 'format']
}

Roadmap

  • Support classes (treat them as objects with certain `"properties"
  • Support methods (treat them as functions with an additional self parameter`)
  • Support multiple functions
  • Support Enums
  • Support named tuples
  • Make the code safe for local execution
  • Refactor code and make locally executable

py2gpt's People

Contributors

janekb04 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.