Update chatgpt_api.py
Browse files- chatgpt_api.py +15 -0
chatgpt_api.py
CHANGED
|
@@ -17,4 +17,19 @@ def get_chatgpt_response(input_text):
|
|
| 17 |
response_json = response.json()
|
| 18 |
output_text = response_json["choices"][0]["message"]["content"]
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
return output_text
|
|
|
|
| 17 |
response_json = response.json()
|
| 18 |
output_text = response_json["choices"][0]["message"]["content"]
|
| 19 |
|
| 20 |
+
return output_text
|
| 21 |
+
|
| 22 |
+
def get_chatgpt3_response(input_text):
|
| 23 |
+
headers = {
|
| 24 |
+
"Content-Type": "application/json",
|
| 25 |
+
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
| 26 |
+
}
|
| 27 |
+
data = {
|
| 28 |
+
"model": "gpt-3",
|
| 29 |
+
"messages": [{"role": "user", "content": input_text}]
|
| 30 |
+
}
|
| 31 |
+
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=data)
|
| 32 |
+
response_json = response.json()
|
| 33 |
+
output_text = response_json["choices"][0]["message"]["content"]
|
| 34 |
+
|
| 35 |
return output_text
|