1. Shin Jungi
  2. PowerBuilder
  3. Tuesday, 7 March 2023 06:01 AM UTC

Do you have OPEN AI ( ChatGPT API library PBL)? I'm trying to test it with the source code below, but it says there is no supported library.

- Below -

string ls_api_key, ls_question, ls_answer
n_cst_openai_api n_api
window w_question

// 테이블 생성 (만약 Tbl_API_QA 테이블이 이미 존재한다면 아무런 작업도 하지 않음)
if NOT tablepresent('Tbl_API_QA') then
CREATE TABLE Tbl_API_QA (
question VARCHAR(255),
answer VARCHAR(255)
)
end if

// OpenAI GPT-3 API 키
//ls_api_key = 'your_api_key_here'

//신준기 ChatGPT API 키값
ls_api_key = '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'

// API 연결
n_api = create n_cst_openai_api
n_api.of_SetAPIKey(ls_api_key)

// 질문 입력 화면 생성
w_question = CREATE window w_question WITH TITLE = '질문 입력' HEIGHT = 200 WIDTH = 400 MAXIMIZE = false MINIMIZE = false MENU = false

// 질문 입력 필드 생성
w_question.createTextEdit('te_question', 10, 10, 380, 50)

// 답변 출력 필드 생성
w_question.createTextEdit('te_answer', 10, 70, 380, 100, ReadOnly!)

// 질문 입력 버튼 생성
w_question.createPushButton('pb_ask', 10, 180, 180, 20, '질문하기')

// 닫기 버튼 생성
w_question.createPushButton('pb_close', 200, 180, 190, 20, '닫기')

// 질문 입력 버튼 클릭 이벤트
w_question.pb_ask.Object.DataWindow.Table.Update = true
w_question.pb_ask.Clicked = true
w_question.pb_ask.clicked = pb_ask_Clicked
w_question.te_question.modified = false

// 닫기 버튼 클릭 이벤트
w_question.pb_close.Object.DataWindow.Table.Update = true
w_question.pb_close.Clicked = true
w_question.pb_close.clicked = pb_close_Clicked

// 질문 입력 화면 열기
w_question.open()

// API 연결 종료
n_api.of_Release()

// 질문 입력 버튼 클릭 이벤트 함수
FUNCTION pb_ask_Clicked ()
string ls_question, ls_answer
n_cst_openai_api n_api

// 질문 가져오기
ls_question = w_question.te_question.text

// ChatGPT API 호출
n_api = create n_cst_openai_api
n_api.of_SetAPIKey(ls_api_key)
ls_answer = n_api.of_GenerateText(ls_question)

// 결과 출력
w_question.te_answer.text = ls_answer
w_question.te_answer.setfocus()

// API 객체 해제
n_api.of_Release()

// 질문과 답변 테이블에 저장
DECLARE q_insert RECORD
q_insert.question = ls_question
q_insert.answer = ls_answer
INSERT INTO Tbl_API_QA (question, answer) VALUES (q_insert.question, q_insert.answer)

END FUNCTION

// 닫기 버튼 클릭 이벤트 함수
FUNCTION pb_close_Clicked ()
w_question.close()
END FUNCTION

Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 7 March 2023 15:43 PM UTC
  2. PowerBuilder
  3. # 1

ChatGPT is a REST based API with JSON data. You should be able use the RESTClient object to handle the calls.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.