py2gpt
1.0.0
Récemment, OpenAI a publié l'API de la fonction GPT qui permet aux modèles comme GPT-4 de "invoquer" les fonctions au nom de l'utilisateur. Le problème est que le format, dans lequel ces fonctions sont spécifiées, est le schéma JSON, qui est relativement niche et difficile à travailler. Ce référentiel aborde ce problème. Il convertit les déclarations de fonctions Python régulières en JSON Consuable par l'API OpenAI.
Par exemple, ce code 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.
"""Produit le JSON suivant qui correspond à l'un des propres exemples d'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 avec certaines «propriétés» «propriétés» self -paramètre supplémentaire) Enum