function gpt
v2.0.0
OpenAI로 함수 호출을 처리하는 데 도움이 되는 TypeScript 라이브러리입니다.
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를 참조하세요.