gpt var
1.0.0
GPTVAR OpenAI API와 쉽게 의사 소통을 촉진하여 프롬프트의 원활한 전송 및 응답을받을 수있게합니다. 다른 모델에 적응할 수 있으며 GPT 생성 컨텐츠를 사용하여 변수의 값 생성을 단순화 할 수 있습니다.
NPM을 사용하여 GPTVAR 설치 :
npm install gpt-var 몇 가지 간단한 단계로 GPTVAR 활용하십시오.
클래스를 가져 오십시오
TypeScript 파일로 GPTVAR 가져 오면서 시작하십시오.
import GPTVAR from 'gpt-var' ;인스턴스를 만듭니다
OpenAI API 키와 선호하는 모델로 GPTVAR 초기화하십시오. 모델 목록을 보려면 OpenAI 모델 개요를 방문하십시오.
const gptVar = new GPTVAR ( 'your-openai-api-key' , 'model-name' ) ;프롬프트를 보내십시오
메시지와 원하는 형식으로 prompt 호출하십시오. 형식은 'Any', 'Array', 'Object'또는 '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 저장소에 문제를 제기하십시오.