import os import requests # OpenAI API キーを設定する OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "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") def get_chatgpt_response(input_text): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {OPENAI_API_KEY}" } data = { "model": "gpt-4o", "messages": [{"role": "user", "content": input_text}] } response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=data) response_json = response.json() output_text = response_json["choices"][0]["message"]["content"] return output_text def get_chatgpt_response2(input_text): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {OPENAI_API_KEY}" } data = { "model": "gpt-4o", "messages": [{"role": "user", "content": input_text}] } response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=data) response_json = response.json() output_text = response_json["choices"][0]["message"]["content"] return output_text