py2gpt
1.0.0
Recentemente, o OpenAI lançou a API da função GPT que permite que modelos como o GPT-4 "invocem" funções em nome do usuário. O problema é que o formato, no qual essas funções são especificadas, é o esquema JSON, que é relativamente nicho e duro de trabalhar. Este repositório aborda esse problema. Ele converte declarações regulares de função python em JSON consumível pela API Openai.
Por exemplo, este código 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.
"""Produz o seguinte JSON que corresponde a um dos próprios exemplos do 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 S com certas propriedades "" self )) Enum s