Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,12 +44,11 @@ def get_vector_store(chunks):
|
|
| 44 |
|
| 45 |
# ✅ Conversational chain
|
| 46 |
def get_conversational_chain():
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
اگر
|
| 50 |
-
از اضافهگویی یا ساختن جواب خودداری کنید.
|
| 51 |
|
| 52 |
-
---
|
| 53 |
{context}
|
| 54 |
|
| 55 |
--- سوال:
|
|
@@ -57,12 +56,34 @@ def get_conversational_chain():
|
|
| 57 |
|
| 58 |
--- پاسخ:
|
| 59 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
model = ChatGoogleGenerativeAI(model="gemini-2.5-pro", client=genai, temperature=0.3)
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
return chain
|
| 64 |
|
| 65 |
|
|
|
|
| 66 |
# ✅ Clear history
|
| 67 |
def clear_chat_history():
|
| 68 |
st.session_state.messages = [{"role": "assistant", "content": "در خدمتیم"}]
|
|
|
|
| 44 |
|
| 45 |
# ✅ Conversational chain
|
| 46 |
def get_conversational_chain():
|
| 47 |
+
map_prompt_template = """
|
| 48 |
+
لطفاً بر اساس متن زیر فقط به سؤال پاسخ دهید.
|
| 49 |
+
اگر جواب دقیق نبود، بگویید: "اطلاعات کافی در متن موجود نیست".
|
|
|
|
| 50 |
|
| 51 |
+
--- متن:
|
| 52 |
{context}
|
| 53 |
|
| 54 |
--- سوال:
|
|
|
|
| 56 |
|
| 57 |
--- پاسخ:
|
| 58 |
"""
|
| 59 |
+
combine_prompt_template = """
|
| 60 |
+
شما یک دستیار هوشمند هستید. پاسخ نهایی را بر اساس نتایج تیکههای مختلف بنویس.
|
| 61 |
+
اگر پاسخی در متن نبود، بگویید: "اطلاعات کافی در متن موجود نیست".
|
| 62 |
+
|
| 63 |
+
--- نتایج جزئی:
|
| 64 |
+
{summaries}
|
| 65 |
+
|
| 66 |
+
--- سوال:
|
| 67 |
+
{question}
|
| 68 |
+
|
| 69 |
+
--- پاسخ نهایی:
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
model = ChatGoogleGenerativeAI(model="gemini-2.5-pro", client=genai, temperature=0.3)
|
| 73 |
+
|
| 74 |
+
map_prompt = PromptTemplate(template=map_prompt_template, input_variables=["context", "question"])
|
| 75 |
+
combine_prompt = PromptTemplate(template=combine_prompt_template, input_variables=["summaries", "question"])
|
| 76 |
+
|
| 77 |
+
chain = load_qa_chain(
|
| 78 |
+
llm=model,
|
| 79 |
+
chain_type="map_reduce",
|
| 80 |
+
map_prompt=map_prompt,
|
| 81 |
+
combine_prompt=combine_prompt
|
| 82 |
+
)
|
| 83 |
return chain
|
| 84 |
|
| 85 |
|
| 86 |
+
|
| 87 |
# ✅ Clear history
|
| 88 |
def clear_chat_history():
|
| 89 |
st.session_state.messages = [{"role": "assistant", "content": "در خدمتیم"}]
|