OpenAI chat GPT 자동 응답 JS > 노트용게시판

본문 바로가기


사이트 내 전체검색 (구글)

노트용게시판

OpenAI chat GPT 자동 응답 JS

페이지 정보

profile_image
작성자 최고관리자 (192.♡.0.1)
댓글 0건 조회 39회 작성일 24-12-11 21:12

본문

const scriptName = "GPT";

/**
 * (string) room : 메세지를 받은 방 이름
 * (string) sender : 전송자 닉네임
 * (boolean) isGroupChat : 단체/오픈채팅 여부
 * (void) replier.reply(message) : 응답용 객체
 * (boolean) replier.reply(room, message, hideErrorToast = false) // 전송 성공시 true, 실패시 false 반환
 * (string) imageDB.getProfileBase64() : 전송자의 프로필 이미지를 Base64로 인코딩하여 반환
 * (string) packageName : 메시지를 받은 메신저의 패키지 이름. (카카오톡 : com.kakao.talk)
 * API 키 값은 별도 확인 필요
 * 2024-12-11 작성 완
 */

let key =  ""; // Open AI 사이트에서 발급받은 API 키입력

function response(room, msg, sender, isGroupChat, replier, imageDB, packageName) {
  if (msg.startsWith("! ")) {
      cmd = msg.substr(3);
      replier.reply("[답변] \n" + getResponse(cmd));
  }
}

function getResponse(msg) {
  let result;
  let data = {"model": "gpt-3.5-turbo",
              "messages": [{"role":"user","content": msg}],
              "temperature":0.7,
              "max_tokens":512,
              "top_p":1,
              "frequency_penalty": 0.0,
              "presence_penalty":0.0
              }
  try {
      let response = org.jsoup.Jsoup.connect("https://api.openai.com/v1/chat/completions")
.header("Content-Type", "application/json")
.header("Authorization","Bearer " + key).requestBody(JSON.stringify(data))
.ignoreContentType(true)
.ignoreHttpErrors(true)
.timeout(200000)
.post()
      result1 = JSON.parse(response.text());
      result = result1.choices[0].message.content;
  } catch(e) {
      result = e;
  }
  return result;
}

댓글목록

등록된 댓글이 없습니다.


회사소개 개인정보취급방침 서비스이용약관 상단으로

contact.https://open.kakao.com/o/s20mpzke
discord.https://discord.gg/rEcZHwBuAh
웹마스터:공세인 개인정보관리책임자:공세인

Copyright © quail.kr All rights reserved.