Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -75,7 +75,7 @@ def generate_standard_prompt(description, advantages, *selected_values):
|
|
75 |
return prompt
|
76 |
|
77 |
# Функции для генерации сообщений
|
78 |
-
def generate_message_gpt4o(prompt,
|
79 |
try:
|
80 |
headers = {
|
81 |
"Content-Type": "application/json",
|
@@ -85,7 +85,7 @@ def generate_message_gpt4o(prompt, temperature=1):
|
|
85 |
"model": "chatgpt-4o-latest",
|
86 |
"messages": [{"role": "system", "content": prompt}],
|
87 |
"max_tokens": 101,
|
88 |
-
"temperature":
|
89 |
}
|
90 |
response = requests.post("https://api.openai.com/v1/chat/completions", json=data, headers=headers)
|
91 |
response_data = response.json()
|
@@ -103,32 +103,32 @@ def clean_message(message):
|
|
103 |
return message
|
104 |
|
105 |
# Обновленные функции генерации сообщений с учетом обрезки незаконченных предложений
|
106 |
-
def generate_message_gigachat_pro(prompt,
|
107 |
try:
|
108 |
messages = [SystemMessage(content=prompt)]
|
109 |
-
chat_pro = GigaChat(credentials=gc_key, model='GigaChat-Pro', max_tokens=68, temperature=
|
110 |
res = chat_pro(messages)
|
111 |
cleaned_message = clean_message(res.content.strip())
|
112 |
return cleaned_message
|
113 |
except Exception as e:
|
114 |
return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
115 |
|
116 |
-
def generate_message_gigachat_lite(prompt,
|
117 |
try:
|
118 |
time.sleep(2)
|
119 |
messages = [SystemMessage(content=prompt)]
|
120 |
-
chat_lite = GigaChat(credentials=gc_key, model='GigaChat', max_tokens=68, temperature=
|
121 |
res = chat_lite(messages)
|
122 |
cleaned_message = clean_message(res.content.strip())
|
123 |
return cleaned_message
|
124 |
except Exception as e:
|
125 |
return f"Ошибка при обращении к GigaChat-Lite: {e}"
|
126 |
|
127 |
-
def generate_message_gigachat_plus(prompt,
|
128 |
try:
|
129 |
time.sleep(2)
|
130 |
messages = [SystemMessage(content=prompt)]
|
131 |
-
chat_plus = GigaChat(credentials=gc_key, model='GigaChat-Plus', max_tokens=68, temperature=
|
132 |
res = chat_plus(messages)
|
133 |
cleaned_message = clean_message(res.content.strip())
|
134 |
return cleaned_message
|
@@ -168,6 +168,14 @@ def generate_message_gigachat_plus_with_retry(prompt, gigachat_plus_temperature)
|
|
168 |
def generate_messages(description, advantages, gpt4o_temperature, gigachat_pro_temperature, gigachat_lite_temperature, gigachat_plus_temperature, *selected_values):
|
169 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
yield results["prompt"], "", "", "", "", "Генерация стандартного промпта завершена"
|
172 |
|
173 |
results["gpt4o"] = generate_message_gpt4o_with_retry(standard_prompt, gpt4o_temperature)
|
|
|
75 |
return prompt
|
76 |
|
77 |
# Функции для генерации сообщений
|
78 |
+
def generate_message_gpt4o(prompt, gpt4o_temperature=1):
|
79 |
try:
|
80 |
headers = {
|
81 |
"Content-Type": "application/json",
|
|
|
85 |
"model": "chatgpt-4o-latest",
|
86 |
"messages": [{"role": "system", "content": prompt}],
|
87 |
"max_tokens": 101,
|
88 |
+
"temperature": gpt4o_temperature # Передача температуры
|
89 |
}
|
90 |
response = requests.post("https://api.openai.com/v1/chat/completions", json=data, headers=headers)
|
91 |
response_data = response.json()
|
|
|
103 |
return message
|
104 |
|
105 |
# Обновленные функции генерации сообщений с учетом обрезки незаконченных предложений
|
106 |
+
def generate_message_gigachat_pro(prompt, gigachat_pro_temperature=0.87):
|
107 |
try:
|
108 |
messages = [SystemMessage(content=prompt)]
|
109 |
+
chat_pro = GigaChat(credentials=gc_key, model='GigaChat-Pro', max_tokens=68, temperature=gigachat_pro_temperature, verify_ssl_certs=False)
|
110 |
res = chat_pro(messages)
|
111 |
cleaned_message = clean_message(res.content.strip())
|
112 |
return cleaned_message
|
113 |
except Exception as e:
|
114 |
return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
115 |
|
116 |
+
def generate_message_gigachat_lite(prompt, gigachat_lite_temperature=0.87):
|
117 |
try:
|
118 |
time.sleep(2)
|
119 |
messages = [SystemMessage(content=prompt)]
|
120 |
+
chat_lite = GigaChat(credentials=gc_key, model='GigaChat', max_tokens=68, temperature=gigachat_lite_temperature, verify_ssl_certs=False)
|
121 |
res = chat_lite(messages)
|
122 |
cleaned_message = clean_message(res.content.strip())
|
123 |
return cleaned_message
|
124 |
except Exception as e:
|
125 |
return f"Ошибка при обращении к GigaChat-Lite: {e}"
|
126 |
|
127 |
+
def generate_message_gigachat_plus(prompt, gigachat_plus_temperature=0.87):
|
128 |
try:
|
129 |
time.sleep(2)
|
130 |
messages = [SystemMessage(content=prompt)]
|
131 |
+
chat_plus = GigaChat(credentials=gc_key, model='GigaChat-Plus', max_tokens=68, temperature=gigachat_plus_temperature, verify_ssl_certs=False)
|
132 |
res = chat_plus(messages)
|
133 |
cleaned_message = clean_message(res.content.strip())
|
134 |
return cleaned_message
|
|
|
168 |
def generate_messages(description, advantages, gpt4o_temperature, gigachat_pro_temperature, gigachat_lite_temperature, gigachat_plus_temperature, *selected_values):
|
169 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
170 |
|
171 |
+
results = {
|
172 |
+
"prompt": standard_prompt,
|
173 |
+
"gpt4o": None,
|
174 |
+
"gigachat_pro": None,
|
175 |
+
"gigachat_lite": None,
|
176 |
+
"gigachat_plus": None
|
177 |
+
}
|
178 |
+
|
179 |
yield results["prompt"], "", "", "", "", "Генерация стандартного промпта завершена"
|
180 |
|
181 |
results["gpt4o"] = generate_message_gpt4o_with_retry(standard_prompt, gpt4o_temperature)
|