-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
220 lines (167 loc) · 5.67 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import openai
from openai import OpenAI
from utils.get_env import OPENAI_API_KEY
client = OpenAI(api_key=OPENAI_API_KEY)
"""
!!! WRITE CLEAR AND SPECIFIC INSTRUCTIONS !!!
"""
"""
BETTER PROMPT #1
"""
numbers = [1, 2, 3, 4, 5]
user_prompt_1 = f'''
Do some random actions on your mind with the numbers below, delimited by triple backticks.
Numbers: ```{numbers}```
'''
"""
BETTER PROMPT #2
"""
user_prompt_2 = f'''
Configure the NGINX Web Server for hosting.
Following next steps:
1. Some
2. Some
3. Some
'''
"""
BETTER PROMPT #3
!!! USE RTF !!!
ROLE | TASK | FORMAT
! USE SYSTEM ROLE !
! GOOD AND CLEAR PROMPT (TASK) !
! FORMAT RESPONSE !
"""
# Imported asking for clear format response
"""
BETTER PROMPT #4
FEW-SHOT
!!! GIVE TO PROMPT SOME EXAMPLES OF RESPONSE BY ADDING DIALOG SYSTEM WITH ROLES USER AND ASSISTANT (STYLE, FORMAT, ELSE) !!!
"""
"""
BETTER PROMPT #5
!!! WRITE STEP BY STEP INSTRUCTIONS !!!
"""
"""
BETTER PROMPT #6
TIME TO THINK FOR MODEL :)
GIVE TO SYSTEM ROLE TASK LIKE:
!!! DO THIS TASK AND AFTER YOU GET YOUR OWN SOLUTION CHECK THE EQUALS BETWEEN YOUR SOLUTION AND MY SOLUTION !!!
"""
"""
BETTER PROMPT #7
ADD HINTS FOR MODEL
- LIKE:
1. write the simple function
def (OR import)
IT WILL BE GENERATE PYTHON FUNC BECAUSE WE PROVIDE THE PYTHON HINTS
"""
"""
BETTER PROMPT #8
!!! MODEL MUST WRITE ONLY FACTS !!!
- LIKE:
1. WRITE SOME POPULAR POEM FROM POPULAR AUTHOR
CHECK ONLY FACTS FROM TRUE PUBLIC SOURCES SUCH AS: WIKI, else.
IF YOU CAN'T FOUND, THEN JUST SAY I HAVE NOT INFORMATION
"""
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": user_prompt_2}
]
)
print(completion.choices[0].message.content)
"""
--- DALL-E MODEL ---
"""
prompt = "Generate a cool street-wearing boy in cap who sitting on coach with laptop and programming python applications." \
"1. image must be from behind of this boy !"
response = client.images.generate(
model='dall-e-2',
prompt=prompt,
style='vivid',
# style='natural',
size='1024x1024',
quality='standard',
n=1
)
image = open('static/main.png', 'rb')
image_create_response = client.images.create_variation(
image=image,
n=1,
size='1024x1024'
)
mask = open('static/mask.png', 'rb')
image_edit_response = client.images.edit(
image=image,
mask=mask,
prompt='The device takes a picture and theres "Python" title in the background.',
n=1,
size='1024x1024'
)
print(response.data[0].url)
"""
--- WHISPER MODEL ---
"""
file = 'static/sound.mp3'
with open(file, 'rb') as audio_file:
transcription = client.audio.transcriptions.create(
model='whisper-1',
file=audio_file
)
print(transcription.text)
rus_file = 'static/rus_sound.mp3'
with open('static/rus_sound.mp3', 'rb') as audio_file:
translation = client.audio.translations.create(
model='whisper-1',
file=audio_file
)
print(translation.text)
"""
--- TTS MODEL ---
"""
text = 'In your opinion, what kind of language policy should we have in Ukraine? We live in Ukraine. Ukrainian language is an ' \
'evolutionary process. For me, the question of language has always been a matter of time. I believe that we should not break ' \
'anyone. Just like they burned Ukrainian language from this territory. '
text_ua = "Якою, на Вашу думку, має бути мовна політика в Україні? Ми живемо в Україні. Українська мова - це еволюційний процес. " \
"еволюційний процес. Для мене питання мови завжди було питанням часу. Я вважаю, що ми не повинні ламати нікого. нікого. Так " \
"само, як спалили українську мову з цієї території. "
response = client.audio.speech.create(
model='tts-1',
voice='nova',
input=text_ua
)
response.stream_to_file('tts.mp3')
"""
--- EMBEDDINGS MODEL ---
"""
embedding = openai.embeddings.create(
model="text-embedding-3-small",
input="red"
)
print(embedding.data[0].embedding)
"""
DIALOG WITH GPT
"""
questions = []
bot_responses = []
messages = []
system_prompt = "Answer as concisely as possible."
messages.append({"role": "system", "content": system_prompt})
while True:
current_question = input('Me:')
if current_question in ['exit', 'quit']:
break
if current_question.lower() == '':
continue
messages.append({"role": "user", "content": current_question})
questions.append(current_question)
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=0.85
)
current_response = completion.choices[0].message.content
print(f"Response: {current_response}")
bot_responses.append(current_response)
messages.append({"role": "assistant", "content": current_response})