py2gpt
1.0.0
في الآونة الأخيرة ، أصدرت Openai واجهة برمجة تطبيقات وظيفة 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 S مع بعض الخصائص " self إضافية) Enum