import os import openai # APIキーの設定 openai.api_key = 'API KEY' # GPT-3モデルの指定 model_engine = "gpt-3.5-turbo" messages = [{"role": "system", "content": "You are a helpful assistant."}] def gptChat(user_input): messages.append({"role": "user", "content": user_input}) try: response = openai.ChatCompletion.create( model=model_engine, messages=messages, ) except openai.error.OpenAIError as e: print(f"Error: {e}") return "" # GPT-3からの応答 message_content = response['choices'][0]['message']['content'] messages.append({"role": "assistant", "content": message_content}) return message_content while True: # ユーザーからの入力を取得 user_input = input("You: ") if user_input.strip().lower() == "quit": break print("GPT-3:", gptChat(user_input))