function gpt
v2.0.0
Il s'agit d'une bibliothèque dactylographiée qui permet de gérer les appels de fonctions avec OpenAI.
import { gptFunction , gptString , FunctionCallingProvider } from 'function-gpt' ;
// Define the type of the input parameter for functions above.
class BrowseParams {
// Decorate each field with @gptObjectField to provide necessary metadata.
@ gptString ( 'url of the web page to browse' )
public url ! : string ;
}
// Create your own class that extends FunctionCallingProvider.
class BrowseProvider extends FunctionCallingProvider {
// Define functions that you want to provide to OpenAI for function calling.
// Decorate each function with @gptFunction to provide necessary metadata.
// The function should accept a single parameter that is a typed object.
@ gptFunction ( 'make http request to a url and return its html content' , BrowseParams )
async browse ( params : BrowseParams ) {
const response = await fetch ( params . url ) ;
return await response . text ( ) ;
}
}
const provider = new BrowseProvider ( ) ;
const schema = await provider . getSchema ( ) ;
const result = await provider . handleFunctionCall (
'browse' ,
JSON . stringify ( { url : 'https://www.google.com' } ) ,
) ;
Consultez les références API pour des informations plus détaillées sur l’utilisation de la bibliothèque.
npm install function-gpt --save
# or
yarn add function-gpt
# or
pnpm add function-gpt
Les contributions sont les bienvenues ! Voir CONTRIBUTING.md pour plus d'informations.