Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -73,7 +73,8 @@ def generate_human_response(context_text):
|
|
73 |
return cache[context_text]
|
74 |
prompt = (
|
75 |
f"این متن پاسخ سوال مشتری است: \"{context_text}\".\n"
|
76 |
-
"لطفاً یک پاسخ کوتاه،
|
|
|
77 |
)
|
78 |
try:
|
79 |
response = openai.chat.completions.create(
|
@@ -82,18 +83,13 @@ def generate_human_response(context_text):
|
|
82 |
{"role": "system", "content": "شما یک پاسخگوی رسمی شرکت هستید."},
|
83 |
{"role": "user", "content": prompt}
|
84 |
],
|
85 |
-
temperature=0.
|
86 |
-
max_tokens=100,
|
87 |
)
|
88 |
answer = response.choices[0].message.content.strip()
|
89 |
-
# اطمینان از
|
90 |
if answer and not answer.endswith(('.', '!', '؟')):
|
91 |
answer += '.'
|
92 |
-
# چک کردن وجود فعل (ساده)
|
93 |
-
persian_verbs = ['است', 'هستیم', 'هستند', 'بود', 'میشود', 'میکنم', 'میکنیم']
|
94 |
-
has_verb = any(verb in answer for verb in persian_verbs)
|
95 |
-
if not has_verb and "ما" in answer:
|
96 |
-
answer = answer.rstrip('.؟!') + ' هستیم.'
|
97 |
cache[context_text] = answer
|
98 |
with open(cache_file, "wb") as f:
|
99 |
pickle.dump(cache, f)
|
|
|
73 |
return cache[context_text]
|
74 |
prompt = (
|
75 |
f"این متن پاسخ سوال مشتری است: \"{context_text}\".\n"
|
76 |
+
"لطفاً یک پاسخ کوتاه، رسمی و کاملاً مختصر به زبان فارسی تولید کن که فقط بر اساس همین متن باشد. "
|
77 |
+
"پاسخ باید یک جملهی کامل با یک فعل مناسب و پایان مشخص باشد. از تولید جملههای ناقص یا جملههایی با بیش از یک فعل خودداری کن."
|
78 |
)
|
79 |
try:
|
80 |
response = openai.chat.completions.create(
|
|
|
83 |
{"role": "system", "content": "شما یک پاسخگوی رسمی شرکت هستید."},
|
84 |
{"role": "user", "content": prompt}
|
85 |
],
|
86 |
+
temperature=0.3, # افزایش به 0.3 برای انعطافپذیری بیشتر
|
87 |
+
max_tokens=100,
|
88 |
)
|
89 |
answer = response.choices[0].message.content.strip()
|
90 |
+
# فقط اطمینان از وجود نقطه در پایان
|
91 |
if answer and not answer.endswith(('.', '!', '؟')):
|
92 |
answer += '.'
|
|
|
|
|
|
|
|
|
|
|
93 |
cache[context_text] = answer
|
94 |
with open(cache_file, "wb") as f:
|
95 |
pickle.dump(cache, f)
|