forked from SR-Hossain/fb2tele-selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgptit.py
49 lines (36 loc) · 1.06 KB
/
gptit.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
from os import environ
from openai import OpenAI
client = OpenAI()
def has_unicode(text):
for char in text:
if ord(char) > 127:
return True
return False
def shorten_text(text):
if has_unicode(text):
prompt = text + "\n\n" + "translate text to english. output only translated text"
else:
if len(text) < 290:
return text
prompt = text + "\n\n" + "shorten text to fit within 290 characters, don't leave out key parts. output only shortened text"
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": prompt},
]
)
res = response.choices[0].message.content
# remove all unicode characters
res = "".join([char for char in res if ord(char) < 128])
return res[:440]
if __name__ == '__main__':
text = """
3/2
27.11.2023 Monday
10:15 AM : Architecture @Online
Meeting link:
Zoom Link
Join our Cloud HD Video Meeting
https://bdren.zoom.us/j/65432491498
"""
print(shorten_text(text))