-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpt.py
63 lines (49 loc) · 1.45 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import openai
def gptTweet(openai_api_key):
# api key
openai.api_key = openai_api_key
# max_tokens
max_tkns = 14000
# persona behind Twitter account
persona = ""
# what to tweet about
prompt = ""
# Use the OpenAI API to generate tweet with given persona
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=[
{"role": "system", "content": persona},
{"role": "user", "content": prompt},
],
max_tokens=max_tkns,
temperature=0.9,
top_p=0.5,
frequency_penalty=1,
presence_penalty=1
)
tweet_content = response['choices'][0]['message']['content']
return tweet_content()
def gptReply(openai_api_key, read_tweet):
# api key
openai.api_key = openai_api_key
# max_tokens
max_tkns = 14000
# persona behind Twitter account
persona = ""
# what to tweet about
prompt = ""
# Use the OpenAI API to generate tweet with given persona
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=[
{"role": "system", "content": persona},
{"role": "user", "content": prompt + read_tweet},
],
max_tokens=max_tkns,
temperature=0.9,
top_p=0.5,
frequency_penalty=1,
presence_penalty=1
)
reply_content = response['choices'][0]['message']['content']
return reply_content()