Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -131,6 +131,34 @@ def generate_message_gigachat_plus(prompt):
|
|
131 |
except Exception as e:
|
132 |
return f"Ошибка при обращении к GigaChat-Plus: {e}"
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
# Обновляем генерацию сообщений для отображения в интерфейсе
|
135 |
def generate_messages(description, advantages, *selected_values):
|
136 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
@@ -145,26 +173,26 @@ def generate_messages(description, advantages, *selected_values):
|
|
145 |
|
146 |
yield results["prompt"], "", "", "", "", "Генерация стандартного промпта завершена"
|
147 |
|
148 |
-
results["gpt4o"] =
|
149 |
gpt4o_length = len(results["gpt4o"])
|
150 |
gpt4o_display = f"{results['gpt4o']}\n\n------\nКоличество знаков: {gpt4o_length}"
|
151 |
yield results["prompt"], gpt4o_display, "", "", "", "Сообщение GPT-4o сгенерировано"
|
152 |
|
153 |
-
results["gigachat_pro"] =
|
154 |
gigachat_pro_length = len(results["gigachat_pro"])
|
155 |
gigachat_pro_display = f"{results['gigachat_pro']}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
156 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, "", "", "Сообщение GigaChat-Pro сгенерировано"
|
157 |
|
158 |
time.sleep(2)
|
159 |
-
|
160 |
-
results["gigachat_lite"] =
|
161 |
gigachat_lite_length = len(results["gigachat_lite"])
|
162 |
gigachat_lite_display = f"{results['gigachat_lite']}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
163 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, "", "Сообщение GigaChat-Lite сгенерировано"
|
164 |
|
165 |
time.sleep(2)
|
166 |
-
|
167 |
-
results["gigachat_plus"] =
|
168 |
gigachat_plus_length = len(results["gigachat_plus"])
|
169 |
gigachat_plus_display = f"{results['gigachat_plus']}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
170 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "Все сообщения сгенерированы"
|
|
|
131 |
except Exception as e:
|
132 |
return f"Ошибка при обращении к GigaChat-Plus: {e}"
|
133 |
|
134 |
+
def generate_message_gpt4o_with_retry(prompt):
|
135 |
+
for _ in range(10): # Максимум 10 попыток
|
136 |
+
message = generate_message_gpt4o(prompt)
|
137 |
+
if len(message) <= 250:
|
138 |
+
return message
|
139 |
+
return message # Возвращаем последнее сгенерированное сообщение, если все попытки не удались
|
140 |
+
|
141 |
+
def generate_message_gigachat_pro_with_retry(prompt):
|
142 |
+
for _ in range(10):
|
143 |
+
message = generate_message_gigachat_pro(prompt)
|
144 |
+
if len(message) <= 250:
|
145 |
+
return message
|
146 |
+
return message
|
147 |
+
|
148 |
+
def generate_message_gigachat_lite_with_retry(prompt):
|
149 |
+
for _ in range(10):
|
150 |
+
message = generate_message_gigachat_lite(prompt)
|
151 |
+
if len(message) <= 250:
|
152 |
+
return message
|
153 |
+
return message
|
154 |
+
|
155 |
+
def generate_message_gigachat_plus_with_retry(prompt):
|
156 |
+
for _ in range(10):
|
157 |
+
message = generate_message_gigachat_plus(prompt)
|
158 |
+
if len(message) <= 250:
|
159 |
+
return message
|
160 |
+
return message
|
161 |
+
|
162 |
# Обновляем генерацию сообщений для отображения в интерфейсе
|
163 |
def generate_messages(description, advantages, *selected_values):
|
164 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
|
|
173 |
|
174 |
yield results["prompt"], "", "", "", "", "Генерация стандартного промпта завершена"
|
175 |
|
176 |
+
results["gpt4o"] = generate_message_gpt4o_with_retry(standard_prompt)
|
177 |
gpt4o_length = len(results["gpt4o"])
|
178 |
gpt4o_display = f"{results['gpt4o']}\n\n------\nКоличество знаков: {gpt4o_length}"
|
179 |
yield results["prompt"], gpt4o_display, "", "", "", "Сообщение GPT-4o сгенерировано"
|
180 |
|
181 |
+
results["gigachat_pro"] = generate_message_gigachat_pro_with_retry(standard_prompt)
|
182 |
gigachat_pro_length = len(results["gigachat_pro"])
|
183 |
gigachat_pro_display = f"{results['gigachat_pro']}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
184 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, "", "", "Сообщение GigaChat-Pro сгенерировано"
|
185 |
|
186 |
time.sleep(2)
|
187 |
+
|
188 |
+
results["gigachat_lite"] = generate_message_gigachat_lite_with_retry(standard_prompt)
|
189 |
gigachat_lite_length = len(results["gigachat_lite"])
|
190 |
gigachat_lite_display = f"{results['gigachat_lite']}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
191 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, "", "Сообщение GigaChat-Lite сгенерировано"
|
192 |
|
193 |
time.sleep(2)
|
194 |
+
|
195 |
+
results["gigachat_plus"] = generate_message_gigachat_plus_with_retry(standard_prompt)
|
196 |
gigachat_plus_length = len(results["gigachat_plus"])
|
197 |
gigachat_plus_display = f"{results['gigachat_plus']}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
198 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "Все сообщения сгенерированы"
|