| import os |
| import requests |
|
|
| |
| OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "sk-proj-arrJA9XvKeo5nfYXLgmeT3BlbkFJNnqFQL9G8qTdYXsBvhJc") |
|
|
| 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 |