-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPT.py
39 lines (34 loc) · 982 Bytes
/
GPT.py
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
36
37
38
39
import requests
import json
import os
def promptGPT2(system, text, temp):
url = "https://api.openai.com/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": os.getenv("OPENAI_API_KEY")
}
data = {
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": system,
},
{"role": "user", "content": text}],
"temperature": temp,
}
response = requests.post(url, headers=headers, json=data)
output = response.json()['choices'][0]['message']['content']
return output
def getEmbeddings(text):
url = 'https://api.openai.com/v1/embeddings'
headers = {
"Content-Type": "application/json",
"Authorization": os.getenv("OPENAI_API_KEY")
}
data = {
"input": text,
"model": "text-embedding-ada-002"
}
response = requests.post(url, headers=headers, json=data)
return response.json()