Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ The Nova System process is iterative and cyclical, involving the following key s
|
|
| 32 |
- Chatbot prompt in English with sections: Persona, Tone, Guidelines, About Us, Responses to Common Questions, Contact Information, Additional Guidelines. Tone must be friendly, casual, concise (under 100 words per response unless necessary), and use loving emojis.
|
| 33 |
- Knowledge base in JSON-like format with fields: name, description, variants (size and price), objectID.
|
| 34 |
- FAQ in JSON-like format with categories, topics, questions, and short, friendly answers.
|
| 35 |
-
-
|
| 36 |
3. **Iterations and Expert Dialogue:** Conduct iterations with the following steps in Persian (Farsi):
|
| 37 |
- **DCE's Instructions:** Provide instructions for PEE and CAE.
|
| 38 |
- **PEE Output:** Generate or refine chatbot prompt, knowledge base, and FAQ.
|
|
@@ -41,7 +41,9 @@ The Nova System process is iterative and cyclical, involving the following key s
|
|
| 41 |
4. **Iterate the Process:** Continue until high-quality outputs are achieved.
|
| 42 |
5. **Present the Final Outputs:**
|
| 43 |
- Final prompt in English with specified sections.
|
| 44 |
-
- Knowledge base
|
|
|
|
|
|
|
| 45 |
|
| 46 |
Conduct all dialogues in Persian, but output the final prompt in English and knowledge base/FAQ in JSON-like format. Ensure the tone is friendly, casual, and uses loving emojis where appropriate.
|
| 47 |
"""
|
|
@@ -56,6 +58,24 @@ def convert_to_serializable(obj):
|
|
| 56 |
return {key: convert_to_serializable(value) for key, value in obj.items()}
|
| 57 |
return obj
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# تابع برای خوندن و پردازش فایلهای اکسل
|
| 60 |
def process_excel_files(file1, file2):
|
| 61 |
global business_info, product_info
|
|
@@ -184,14 +204,14 @@ def end_process():
|
|
| 184 |
# تولید خروجی نهایی
|
| 185 |
final_prompt = f"""
|
| 186 |
{mother_prompt}
|
| 187 |
-
فرایند iterationها تموم شده. لطفاً خروجی نهایی رو تولید کنید:
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
اطلاعات کسبوکار: {json.dumps(business_info_serializable, ensure_ascii=False)}
|
| 192 |
اطلاعات محصولات: {json.dumps(product_info_serializable, ensure_ascii=False)}
|
| 193 |
تاریخچ�� iterationها:\n{iteration_history}
|
| 194 |
-
خرو
|
| 195 |
"""
|
| 196 |
final_response = client.chat.completions.create(
|
| 197 |
model="gpt-4o",
|
|
@@ -199,11 +219,11 @@ def end_process():
|
|
| 199 |
)
|
| 200 |
final_output = final_response.choices[0].message.content
|
| 201 |
|
| 202 |
-
# جداسازی خروجیها
|
| 203 |
-
parts =
|
| 204 |
-
prompt_output = parts[0]
|
| 205 |
-
knowledge_base_output = parts[1]
|
| 206 |
-
faq_output = parts[2]
|
| 207 |
|
| 208 |
iteration_history += "\n**فرایند تموم شد و خروجی نهایی آمادهست! 🎉**\n"
|
| 209 |
return iteration_history, prompt_output, knowledge_base_output, faq_output
|
|
|
|
| 32 |
- Chatbot prompt in English with sections: Persona, Tone, Guidelines, About Us, Responses to Common Questions, Contact Information, Additional Guidelines. Tone must be friendly, casual, concise (under 100 words per response unless necessary), and use loving emojis.
|
| 33 |
- Knowledge base in JSON-like format with fields: name, description, variants (size and price), objectID.
|
| 34 |
- FAQ in JSON-like format with categories, topics, questions, and short, friendly answers.
|
| 35 |
+
- **Critical Analysis Expert (CAE):** Review and critique outputs, ensuring they match the desired tone, structure, and detail level, providing improvement suggestions.
|
| 36 |
3. **Iterations and Expert Dialogue:** Conduct iterations with the following steps in Persian (Farsi):
|
| 37 |
- **DCE's Instructions:** Provide instructions for PEE and CAE.
|
| 38 |
- **PEE Output:** Generate or refine chatbot prompt, knowledge base, and FAQ.
|
|
|
|
| 41 |
4. **Iterate the Process:** Continue until high-quality outputs are achieved.
|
| 42 |
5. **Present the Final Outputs:**
|
| 43 |
- Final prompt in English with specified sections.
|
| 44 |
+
- Knowledge base in JSON-like format.
|
| 45 |
+
- FAQ in JSON-like format.
|
| 46 |
+
- Separate each section with exactly "---" (three dashes) and nothing else.
|
| 47 |
|
| 48 |
Conduct all dialogues in Persian, but output the final prompt in English and knowledge base/FAQ in JSON-like format. Ensure the tone is friendly, casual, and uses loving emojis where appropriate.
|
| 49 |
"""
|
|
|
|
| 58 |
return {key: convert_to_serializable(value) for key, value in obj.items()}
|
| 59 |
return obj
|
| 60 |
|
| 61 |
+
# تابع برای اعتبارسنجی و اصلاح خروجی
|
| 62 |
+
def validate_and_fix_output(output):
|
| 63 |
+
parts = output.split("---")
|
| 64 |
+
if len(parts) != 3:
|
| 65 |
+
# اگه جداکنندهها درست نبودن، تلاش میکنیم محتوا رو جدا کنیم
|
| 66 |
+
prompt_start = output.find("### Persona")
|
| 67 |
+
kb_start = output.find("[") if "[" in output else output.find("{")
|
| 68 |
+
faq_start = output.find("{", output.find("}") + 1) if "}" in output else -1
|
| 69 |
+
|
| 70 |
+
if prompt_start != -1 and kb_start != -1 and faq_start != -1:
|
| 71 |
+
prompt = output[prompt_start:kb_start].strip()
|
| 72 |
+
kb = output[kb_start:faq_start].strip()
|
| 73 |
+
faq = output[faq_start:].strip()
|
| 74 |
+
return [prompt, kb, faq]
|
| 75 |
+
else:
|
| 76 |
+
return ["پرامپت تولید نشد 😔", "پایگاه دانش تولید نشد 😕", "FAQ تولید نشد 🥳"]
|
| 77 |
+
return [part.strip() for part in parts]
|
| 78 |
+
|
| 79 |
# تابع برای خوندن و پردازش فایلهای اکسل
|
| 80 |
def process_excel_files(file1, file2):
|
| 81 |
global business_info, product_info
|
|
|
|
| 204 |
# تولید خروجی نهایی
|
| 205 |
final_prompt = f"""
|
| 206 |
{mother_prompt}
|
| 207 |
+
فرایند iterationها تموم شده. لطفاً خروجی نهایی رو به این شکل تولید کنید:
|
| 208 |
+
1. پرامپت چتبات به انگلیسی با بخشهای: Persona, Tone, Guidelines, About Us, Responses to Common Questions, Contact Information, Additional Guidelines. لحن باید دوستانه، عامیانه، کوتاه (زیر 100 کلمه) و با ایموجیهای جذاب باشه. متن اضافی مثل "Here are the outputs" نذارید، فقط پرامپت خالص.
|
| 209 |
+
2. پایگاه دانش به فرمت JSON-like با فیلدهای: name, description, variants (size و price), objectID.
|
| 210 |
+
3. FAQ به فرمت JSON-like با دستهبندیها (مثل Service Basics, Care Instructions)، موضوعات، سوالات و جوابهای کوتاه و دوستانه.
|
| 211 |
اطلاعات کسبوکار: {json.dumps(business_info_serializable, ensure_ascii=False)}
|
| 212 |
اطلاعات محصولات: {json.dumps(product_info_serializable, ensure_ascii=False)}
|
| 213 |
تاریخچ�� iterationها:\n{iteration_history}
|
| 214 |
+
هر بخش رو با دقیقاً "---" (سه تا خط تیره بدون فاصله یا متن اضافی) جدا کنید.
|
| 215 |
"""
|
| 216 |
final_response = client.chat.completions.create(
|
| 217 |
model="gpt-4o",
|
|
|
|
| 219 |
)
|
| 220 |
final_output = final_response.choices[0].message.content
|
| 221 |
|
| 222 |
+
# اعتبارسنجی و جداسازی خروجیها
|
| 223 |
+
parts = validate_and_fix_output(final_output)
|
| 224 |
+
prompt_output = parts[0] if len(parts) > 0 else "پرامپت تولید نشد 😔"
|
| 225 |
+
knowledge_base_output = parts[1] if len(parts) > 1 else "پایگاه دانش تولید نشد 😕"
|
| 226 |
+
faq_output = parts[2] if len(parts) > 2 else "FAQ تولید نشد 🥳"
|
| 227 |
|
| 228 |
iteration_history += "\n**فرایند تموم شد و خروجی نهایی آمادهست! 🎉**\n"
|
| 229 |
return iteration_history, prompt_output, knowledge_base_output, faq_output
|