py2gpt
1.0.0
Recientemente, Operai ha lanzado la API de la función GPT que permite que modelos como GPT-4 "invocar" las funciones en nombre del usuario. El problema es que el formato, en el que se especifican estas funciones, es el esquema JSON, que es relativamente nicho y difícil de trabajar. Este repositorio aborda este problema. Convierte las declaraciones regulares de la función de Python en el consumible JSON por la API de OpenAI.
Por ejemplo, este código de Python:
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.
"""Produce el siguiente JSON que coincide con uno de los propios ejemplos de Openai:
{
'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' ]
} object con ciertas `" propiedades " self ) Enum s