py2gpt
1.0.0
เมื่อเร็ว ๆ นี้ OpenAI ได้เปิดตัวฟังก์ชั่น GPT Function API ที่อนุญาตให้โมเดลเช่น GPT-4 ถึง "เรียกใช้" ฟังก์ชั่นในนามของผู้ใช้ ปัญหาคือรูปแบบที่ระบุฟังก์ชั่นเหล่านี้คือ JSON Schema ซึ่งค่อนข้างเฉพาะและทำงานได้ยาก ที่เก็บนี้แก้ไขปัญหานี้ มันแปลงการประกาศฟังก์ชั่น Python ปกติเป็น JSON ที่บริโภคโดย OpenAI API
ตัวอย่างเช่นรหัส 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