py2gpt
1.0.0
Baru-baru ini, OpenAI telah merilis API fungsi GPT yang memungkinkan model seperti GPT-4 untuk "memanggil" fungsi atas nama pengguna. Masalahnya adalah bahwa format, di mana fungsi -fungsi ini ditentukan, adalah skema JSON, yang relatif niche dan sulit dikerjakan. Repositori ini membahas masalah ini. Ini mengubah deklarasi fungsi python reguler menjadi JSON yang dapat dikonsumsi oleh Openai API.
Misalnya, kode Python ini:
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.
"""Menghasilkan JSON berikut yang cocok dengan salah satu contoh Openai sendiri:
{
'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 dengan "properti" tertentu " self tambahan`) Enum s