gpt var
1.0.0
GPTVAR促进了与OpenAI API的轻松沟通,从而使提示的无缝发送并接收了响应。它可以针对其他模型进行调整,从而简化了使用GPT生成的内容为变量创建的值。
使用NPM安装GPTVAR :
npm install gpt-var在几个简单的步骤中使用GPTVAR :
导入班级
首先将GPTVAR导入您的打字稿文件:
import GPTVAR from 'gpt-var' ;创建一个实例
使用您的OpenAI API密钥初始化GPTVAR ,并且可以选择地使用您的首选模型。有关模型列表,请访问OpenAI模型概述。
const gptVar = new GPTVAR ( 'your-openai-api-key' , 'model-name' ) ;发送提示
带有您的消息和所需格式的调用prompt 。格式可以是“任何”,“数组”,“对象”或“ ObjectInarray”。
gptVar . prompt ( 'Your prompt here' , 'any' ) . then ( response => {
console . log ( response ) ;
} ) . catch ( error => {
console . error ( error ) ;
} ) ;处理响应
prompt通过GPT模型的响应返回承诺,然后您可以根据需要对其进行处理。
prompt(message: string, format: string)此方法将消息发送给GPT模型,期望以指定格式进行响应。
messages :GPT模型的输入字符串。format :预期响应格式。选项:any :返回一个原始字符串,适用于灵活或未指定格式。object :期望一个JSON对象,非常适合结构化数据。array :期望一个JSON数组,非常适合列表或序列。objectInArray :期望有一系列JSON对象,对结构化列表有用。 格式: any
将响应返回为原始字符串,非常适合非结构化数据。
gptVar . prompt ( 'Tell me a joke' , 'any' ) . then ( response => {
console . log ( 'Response:' , response ) ;
} ) ;示例响应:
"Why don't scientists trust atoms? Because they make up everything!"
格式: object
期望JSON对象响应。
gptVar . prompt ( 'Provide details about the Eiffel Tower' , 'object' ) . then ( response => {
console . log ( 'Response:' , response ) ;
} ) ;示例响应:
{
"name" : " Eiffel Tower " ,
"location" : " Paris, France " ,
"height" : " 300 meters "
}格式: array
期望JSON阵列响应。
gptVar . prompt ( 'List three famous scientists' , 'array' ) . then ( response => {
console . log ( 'Response:' , response ) ;
} ) ;示例响应:
[ " Albert Einstein " , " Marie Curie " , " Isaac Newton " ]格式: objectInArray
期望一系列JSON对象。
gptVar . prompt ( 'List major cities with their countries and populations' , 'objectInArray' ) . then ( response => {
console . log ( 'Response:' , response ) ;
} ) ;示例响应:
[
{
"city" : " New York City " ,
"country" : " USA " ,
"population" : " 8.4 million "
},
{
"city" : " Tokyo " ,
"country" : " Japan " ,
"population" : " 9.3 million "
},
{
"city" : " London " ,
"country" : " UK " ,
"population" : " 8.9 million "
}
]为了获得支持,问题或功能请求,请在我们的GitHub存储库上提交问题。