py2gpt
1.0.0
最近、OpenAIはGPT-4などのモデルがユーザーに代わって関数を「呼び出す」ことを可能にするGPT関数APIをリリースしました。問題は、これらの機能が指定されている形式が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.
"""Openai自身の例の1つに一致する次の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 s