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 لمزيد من المعلومات.