Update app.py
Browse files
app.py
CHANGED
@@ -567,7 +567,7 @@ book_embeddings = load_embeddings_from_cache()
|
|
567 |
|
568 |
if query:
|
569 |
found = False
|
570 |
-
threshold = 0.
|
571 |
|
572 |
# بررسی اینکه آیا امبدینگهای سوال قبلاً محاسبه شده یا خیر
|
573 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
@@ -615,9 +615,11 @@ if query:
|
|
615 |
|
616 |
else:
|
617 |
final_prompt = f"""
|
618 |
-
لطفاً برای سوال زیر پاسخی حرفهای، دقیق و روان تولید کن که مرتبط و معتبر باشد. و از
|
619 |
سوال:
|
620 |
{query}
|
|
|
|
|
621 |
"""
|
622 |
new_response = llm([SystemMessage(content="You are a helpful assistant."), HumanMessage(content=final_prompt)])
|
623 |
final_answer = new_response.content.strip()
|
@@ -629,7 +631,7 @@ if query:
|
|
629 |
break
|
630 |
|
631 |
if not found:
|
632 |
-
prompt = f"لطفاً بر اساس سوال زیر یک متن مرتبط و معنادار تولید کن و جملات ساختگی استفاده نکن و از جملات موجود در اسناد و جملات معتبر استفاده کن
|
633 |
response = llm([SystemMessage(content="You are a helpful assistant."), HumanMessage(content=prompt)])
|
634 |
rewritten = response.content.strip()
|
635 |
rewritten = clean_text(rewritten)
|
|
|
567 |
|
568 |
if query:
|
569 |
found = False
|
570 |
+
threshold = 0.66
|
571 |
|
572 |
# بررسی اینکه آیا امبدینگهای سوال قبلاً محاسبه شده یا خیر
|
573 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
|
|
615 |
|
616 |
else:
|
617 |
final_prompt = f"""
|
618 |
+
لطفاً برای سوال زیر پاسخی حرفهای، دقیق و روان تولید کن که مرتبط و معتبر باشد. و از متن ساختگی پرهیز کن و از دیتای متن مرتبط نیز استفاده کن از زبانی جز فارسی استفاده نکن :
|
619 |
سوال:
|
620 |
{query}
|
621 |
+
متن مرتبط:
|
622 |
+
{sentence}
|
623 |
"""
|
624 |
new_response = llm([SystemMessage(content="You are a helpful assistant."), HumanMessage(content=final_prompt)])
|
625 |
final_answer = new_response.content.strip()
|
|
|
631 |
break
|
632 |
|
633 |
if not found:
|
634 |
+
prompt = f"لطفاً بر اساس سوال زیر یک متن مرتبط و معنادار تولید کن و جملات ساختگی استفاده نکن و از جملات موجود در اسناد و جملات معتبر استفاده کن و از زبانی جز فارسی استفاده نکن:\n\nسوال: {query}"
|
635 |
response = llm([SystemMessage(content="You are a helpful assistant."), HumanMessage(content=prompt)])
|
636 |
rewritten = response.content.strip()
|
637 |
rewritten = clean_text(rewritten)
|