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