py2gpt
1.0.0
最近,OpenAI发布了GPT功能API,该API允许GPT-4之类的模型代表用户“调用”功能。问题在于,指定这些函数的格式是JSON模式,该格式相对利基,很难使用。此存储库解决了这个问题。它将常规的Python功能声明转换为OpenAI API消耗的JSON。
例如,此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自己的例子之一相匹配的JSON:
{
'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