File size: 1,168 Bytes
cac126a
 
 
 
d34f7c1
cac126a
 
 
 
 
 
 
b3bec9f
cac126a
 
 
 
 
 
ff2aaa4
 
277999a
ff2aaa4
 
 
 
 
02738ef
ff2aaa4
 
 
 
 
 
cac126a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import requests

# OpenAI API キーを設定する
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