상세 컨텐츠

본문 제목

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)

 

 

반응형

궁금할 만한 핫토픽 모음

아이폰16 Pro, 자급제, 사전 예약, 네이버 쇼핑 top 50




김포 재개발 대장주 한강 수자인 오브센트




챗GPT GPT-4o 무료로 그림 그리기



관련글 더보기