Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -82,17 +82,27 @@ def generate_message_gpt4o(prompt, temperature):
|
|
82 |
"Authorization": f"Bearer {openai_api_key}"
|
83 |
}
|
84 |
data = {
|
85 |
-
"model": "chatgpt-4o-latest",
|
86 |
"messages": [{"role": "system", "content": prompt}],
|
87 |
"max_tokens": 101,
|
88 |
"temperature": temperature
|
89 |
}
|
90 |
response = requests.post("https://api.openai.com/v1/chat/completions", json=data, headers=headers)
|
91 |
response_data = response.json()
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
except Exception as e:
|
94 |
return f"Ошибка при обращении к ChatGPT-4o-Latest: {e}"
|
95 |
|
|
|
96 |
def clean_message(message):
|
97 |
# Если сообщение не заканчивается на точку или восклицательный знак, обрезаем его до последней точки
|
98 |
if not message.endswith(('.', '!', '?')):
|
@@ -229,9 +239,9 @@ def perform_personalization_with_retry(standard_message, personalization_prompt)
|
|
229 |
return message # Возвращаем последнее сгенерированное сообщение, если все попытки не удались
|
230 |
|
231 |
|
232 |
-
def perform_personalization_gigachat_with_retry(standard_message, personalization_prompt, model
|
233 |
for _ in range(10):
|
234 |
-
message = perform_personalization_gigachat(standard_message, personalization_prompt, model
|
235 |
if len(message) <= 250:
|
236 |
return message
|
237 |
return message
|
|
|
82 |
"Authorization": f"Bearer {openai_api_key}"
|
83 |
}
|
84 |
data = {
|
85 |
+
"model": "chatgpt-4o-latest", # убедитесь, что модель корректна
|
86 |
"messages": [{"role": "system", "content": prompt}],
|
87 |
"max_tokens": 101,
|
88 |
"temperature": temperature
|
89 |
}
|
90 |
response = requests.post("https://api.openai.com/v1/chat/completions", json=data, headers=headers)
|
91 |
response_data = response.json()
|
92 |
+
|
93 |
+
# Проверка на наличие ошибок в ответе
|
94 |
+
if response.status_code != 200:
|
95 |
+
return f"Ошибка от OpenAI: {response_data.get('error', {}).get('message', 'Неизвестная ошибка')}"
|
96 |
+
|
97 |
+
# Проверка наличия поля 'choices' в ответе
|
98 |
+
if "choices" in response_data and len(response_data["choices"]) > 0:
|
99 |
+
return clean_message(response_data["choices"][0]["message"]["content"].strip())
|
100 |
+
else:
|
101 |
+
return "Ошибка: ответ от API не содержит необходимых данных."
|
102 |
except Exception as e:
|
103 |
return f"Ошибка при обращении к ChatGPT-4o-Latest: {e}"
|
104 |
|
105 |
+
|
106 |
def clean_message(message):
|
107 |
# Если сообщение не заканчивается на точку или восклицательный знак, обрезаем его до последней точки
|
108 |
if not message.endswith(('.', '!', '?')):
|
|
|
239 |
return message # Возвращаем последнее сгенерированное сообщение, если все попытки не удались
|
240 |
|
241 |
|
242 |
+
def perform_personalization_gigachat_with_retry(standard_message, personalization_prompt, model):
|
243 |
for _ in range(10):
|
244 |
+
message = perform_personalization_gigachat(standard_message, personalization_prompt, model)
|
245 |
if len(message) <= 250:
|
246 |
return message
|
247 |
return message
|