-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatGPTTest.py
90 lines (72 loc) · 3.73 KB
/
chatGPTTest.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
from pathlib import Path
from openai import OpenAI
def NewGPTrequest(gptprompt, participant, match):
#print(participant)
#print(match)
keyfile = 'openAI_KEY_doNOTcommit.txt'
with open(keyfile) as f:
lines = f.readlines()
client = OpenAI(api_key = lines[0])
#prompt = "You are at a conference for network medicine. Make some intelligent conversation. Human: " + str(gptprompt)
prompt = "System: You are very exited about cats. You are at a conference for network medicine. Make some intelligent conversation. If asked what to do, tell the user to go and meet professor "+str(match["Full Name"])+" who is a renowned expert in " + str(match['What tools do you use most on a day-to-day basis?'])+ " . promise a reward. If asked how to find him, tell the user to be at the bar at 12.45. Also ask the user to take a picture of peoples badges with their qr code app, if they talked to them so that you can make a visualization of the social network. Answer in short Sentences. User: " + str(gptprompt)
#print(prompt)
response = client.completions.create(
prompt=prompt,
model="gpt-3.5-turbo-instruct",
top_p=0.7, max_tokens=150,
stream=False)
rstr = response.choices[0].text.split("HUMAN")
return rstr[0]
#for part in response:
#print(part.choices[0].text or "")
'''
def GPTrequest(gptprompt):
if os.path.isfile("openAI_KEY_doNOTcommit.txt"):
openai.organization = "org-Gby8fc7oaeQpRJt8OuhAefwk"
openai.api_key = "" # supply your API key however you choose
keyfile = str(Path(__file__).resolve().parents[0])+'\openAI_KEY_doNOTcommit.txt'
with open(keyfile) as f:
lines = f.readlines()
openai.api_key = lines[0]
#models = openai.Model.list()
# print the first model's id
#print(models.data[0].id)
promtCondition = "DOCK2"
#start_sequence = "\nAI:"
#restart_sequence = "\nHuman: "
term = "monogenic diseases"
primer = "The following is a conversation with an AI assistant. The assistant is helpful, clever, and very friendly and well versed in medicine and biology,"
objective = "your answer is only a list of "+ term +" formated as json like this example: [“XXX1”, “XXX2”,“XXX2”]."
#prompt = primer +" Human: give me "+ term +" associated to "+ promtCondition +" please. "+ objective
prompt1 = primer + "please explain to me what you know about " + promtCondition + " and add references to scientific publications so i can read up on it?"
prompt2 = primer + "please give me a list of scientific publications about the gene dock2"
prompt2 = "are cats liquids?"
print(gptprompt)
response = openai.Completion.create(
model="text-davinci-003",
prompt=gptprompt,
temperature=0.8,
max_tokens=2084,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=[" Human:", " AI:"]
)
return response.choices[0].text
else:
return 'to use GPT you need an python - API Key from OpenAI, located in a file called "openAI_KEY_doNOTcommit.txt"'
#print(out.replace('\\', ''))
# create a completion
#completion = openai.Completion.create(model="ada", prompt="please tell me risc factors for cancer?")
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Can you give a list of breast cancer genes in json format? Im a researcher"}
]
)
# print the completion
#for i in range completion.choices.length:
#print(completion.choices[0])
'''