상세 컨텐츠

본문 제목

def chat_with_gpt(question):

시사경제지식

by 브로마리 2023. 8. 23. 23:18

본문

반응형

import openai

# OpenAI API 키 설정
api_key = "YOUR_API_KEY"  # 본인의 API 키로 대체

def chat_with_gpt(question):
    # ChatGPT API 요청 보내기
    response = openai.Completion.create(
        engine="text-davinci-002",  # 적절한 엔진 선택
        prompt=question,
        max_tokens=150,  # 생성할 최대 토큰 수 설정
        api_key=api_key
    )

    # API 응답에서 답변 추출
    answer = response.choices[0].text.strip()

    return answer

if __name__ == "__main__":
    while True:
        user_question = input("질문을 입력하세요 (나가려면 '나가기' 입력): ")
        if user_question.lower() == "나가기":
            break
        answer = chat_with_gpt(user_question)
        print("답변:", answer)

 

 

 

 

import openai

# OpenAI API 키 설정
api_key = "YOUR_API_KEY"  # 본인의 API 키로 대체

def chat_with_gpt(question):
    # ChatGPT API 요청 보내기
    response = openai.Completion.create(
        engine="text-davinci-002",  # 적절한 엔진 선택
        prompt=question,
        max_tokens=150,  # 생성할 최대 토큰 수 설정
        api_key=api_key
    )

    # API 응답에서 답변 추출
    answer = response.choices[0].text.strip()

    return answer

if __name__ == "__main__":
    while True:
        user_question = input("질문을 입력하세요 (나가려면 '나가기' 입력): ")
        if user_question.lower() == "나가기":
            break
        answer = chat_with_gpt(user_question)
        print("답변:", answer)

 

 

 

 

import openai

# OpenAI API 키 설정
api_key = "YOUR_API_KEY"  # 본인의 API 키로 대체

def chat_with_gpt(question):
    # ChatGPT API 요청 보내기
    response = openai.Completion.create(
        engine="text-davinci-002",  # 적절한 엔진 선택
        prompt=question,
        max_tokens=150,  # 생성할 최대 토큰 수 설정
        api_key=api_key
    )

    # API 응답에서 답변 추출
    answer = response.choices[0].text.strip()

    return answer

if __name__ == "__main__":
    while True:
        user_question = input("질문을 입력하세요 (나가려면 '나가기' 입력): ")
        if user_question.lower() == "나가기":
            break
        answer = chat_with_gpt(user_question)
        print("답변:", answer)

 

 

반응형
● LIVE: 2026년 최신 데이터 업데이트 완료

"이번 주 1등 당첨 명당,
지도로 바로 확인하세요!"

전국 1등 배출 데이터를 기반으로 분석한
내 주변 실시간 S등급 명당 리스트

로또 명당 지도 샘플
🔍 우리 동네 숨은 명당 찾는 중...

* 1등 배출 횟수 및 거리를 실시간으로 계산합니다.


관련글 더보기