구글 스프레드 시트 chatGPT 프롬프트 함수 질문

구글 스프레드 시트 chatGPT 프롬프트 함수 질문

작성일 2023.03.10댓글 1건
    게시물 수정 , 삭제는 로그인 필요

확장프로그램으로 GPT를 연결하여 요리 레시피를 만들으라는 질문에 대한 GPT의 답변을 스프레드 시트에 불러오고 싶습니다.

GPT에 요청한 내용은 아래와 같습니다.

Write three short recipes in 4 cuts scenario format. Include ingredients, cooking tools, cooking time and detail description. 
The ingredients of the food is [ㅇㅇㅇ], the cooking tools of the food are [ㅇㅇㅇ], and the cooking time of the food is [ㅇㅇㅇ].

ㅇㅇㅇ 자리에 뭘 넣느냐에 따라 다양한 답변이 나오는 것은 확인했습니다.

빈칸에 들어갈 내용을 스프레드 시트의 셀에서 불러오고 싶은데, 함수를 어떻게 써야할지 모르겠습니다.
현재는 이렇게 썼는데 B2만 반영이 되고 나머지는 안됩니다ㅠㅠ

Write three short recipes in 4 cuts scenario format. Include ingredients, cooking tools, cooking time and detail description. 
The ingredients of the food is:"B2, the cooking tools of the food are D2, and the cooking time of the food is:" F2

어떻게 함수를 작성하면 셀에 있는 값을 하나씩 불러올 수 있을까요?


#구글 스프레드 시트 #구글 스프레드 #구글 스프레드시트 사용법 #구글 스프레드시트 바로가기 #구글 스프레드시트 공유 #구글 스프레드시트 모바일 #구글 스프레드시트 엑셀 연동 #구글 스프레드시트 단축키 #구글 스프레드시트 다운로드 #구글 스프레드 시트 줄바꿈

profile_image 익명 작성일 -

  1. Google 스프레드시트에서 "도구" 메뉴를 선택한 후 "스크립트 편집기"를 선택합니다.

  2. 스크립트 편집기 창에서 "새 프로젝트"를 선택합니다.

  3. 아래 코드를 복사하여 스크립트 편집기 창에 붙여넣습니다.

function generateRecipes() {

// GPT 요청에 필요한 문장을 작성합니다.

var prompt = "Write three short recipes in 4 cuts scenario format. Include ingredients, cooking tools, cooking time and detail description. The ingredients of the food is [ㅇㅇㅇ], the cooking tools of the food are [ㅇㅇㅇ], and the cooking time of the food is [ㅇㅇㅇ].";

// GPT 요청을 보내고 결과를 받아옵니다.

var response = UrlFetchApp.fetch("https://api.openai.com/v1/engines/davinci-codex/completions", {

method: "POST",

headers: {

"Authorization": "Bearer YOUR_API_KEY",

"Content-Type": "application/json"

},

payload: JSON.stringify({

"prompt": prompt,

"max_tokens": 1024,

"temperature": 0.7,

"n": 1,

"stop": "\n"

})

});

// 결과를 파싱하여 스프레드시트에 삽입합니다.

var result = JSON.parse(response.getContentText()).choices[0].text;

var sheet = SpreadsheetApp.getActiveSheet();

sheet.getRange(sheet.getLastRow()+1, 1).setValue(result);

}

  1. YOUR_API_KEY를 본인의 OpenAI API 키로 대체합니다.

  2. 스크립트 편집기 창에서 "실행" 메뉴를 선택한 후 "generateRecipes"를 선택합니다.

  3. GPT가 작동하고 결과가 스프레드시트에 삽입됩니다.

위 코드는 OpenAI의 Davinci Codex 엔진을 사용하여 GPT 요청을 보내고, 결과를 스프레드시트에 삽입하는 예시 코드입니다. 다른 엔진을 사용하려면 코드를 약간 수정해야 할 수 있습니다. 또한, 이 코드를 사용하기 위해서는 OpenAI API에 가입하고 API 키를 발급받아야 합니다.