py2gpt
1.0.0
Недавно OpenAI выпустил API функции GPT, который позволяет таким моделям, как GPT-4 функционировать «вызовы» от имени пользователя. Проблема заключается в том, что формат, в котором указаны эти функции, представляет собой схему JSON, которая является относительно нишевой и с ним трудно работать. Этот репозиторий решает эту проблему. Он преобразует регулярные объявления функции Python в JSON, потребляемый API OpenAI.
Например, этот код 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.
"""Производит следующий JSON, который соответствует одному из собственных примеров 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 с определенными «свойствами» self параметра) Enum s