function gpt
v2.0.0
這是一個打字稿庫,可協助處理 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' } ) ,
) ;
有關如何使用該庫的更多詳細信息,請參閱 API 參考。
npm install function-gpt --save
# or
yarn add function-gpt
# or
pnpm add function-gpt
歡迎貢獻!請參閱 CONTRIBUTING.md 以了解更多資訊。