Spaces:
Sleeping
Sleeping
Update app.py
Browse filesNOKTA KONTROLÜ EKLENDİ
app.py
CHANGED
@@ -114,6 +114,15 @@ def extract_self_answer(output: str) -> str:
|
|
114 |
return output.split("Cevap:")[-1].strip()
|
115 |
return output.strip()
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
async def selfrag_agent(question: str):
|
118 |
# 1. VDB cevabı ve kaynak url
|
119 |
result = await retrieve_sources_from_pinecone(question)
|
@@ -128,6 +137,11 @@ async def selfrag_agent(question: str):
|
|
128 |
vdb_paragraph = clean_text_output(vdb_paragraph)
|
129 |
model_paragraph = clean_text_output(model_paragraph)
|
130 |
|
|
|
|
|
|
|
|
|
|
|
131 |
# 4. Cross-encoder ile skorlama
|
132 |
candidates = []
|
133 |
candidate_urls = []
|
@@ -154,18 +168,20 @@ async def selfrag_agent(question: str):
|
|
154 |
if len(scores) == 2:
|
155 |
vdb_score = scores[0]
|
156 |
model_score = scores[1]
|
157 |
-
# Eğer modelin skoru, VDB'nin 2 katından fazlaysa modeli döndür
|
158 |
if model_score > 1.5 * vdb_score:
|
159 |
best_idx = 1
|
160 |
else:
|
161 |
best_idx = 0
|
162 |
else:
|
163 |
-
# Sadece VDB veya model varsa, en yüksek skoru seç
|
164 |
best_idx = int(np.argmax(scores))
|
165 |
|
166 |
final_answer = candidates[best_idx]
|
167 |
final_source_url = candidate_urls[best_idx]
|
168 |
|
|
|
|
|
|
|
|
|
169 |
return {
|
170 |
"answer": final_answer,
|
171 |
"source_url": final_source_url
|
|
|
114 |
return output.split("Cevap:")[-1].strip()
|
115 |
return output.strip()
|
116 |
|
117 |
+
def cut_at_last_period(text):
|
118 |
+
"""Metni son noktaya kadar keser, sonrasında kalan eksik cümleleri atar."""
|
119 |
+
last_period = text.rfind(".")
|
120 |
+
if last_period != -1:
|
121 |
+
return text[:last_period+1].strip()
|
122 |
+
return text.strip()
|
123 |
+
|
124 |
+
# ... (devamı aynı)
|
125 |
+
|
126 |
async def selfrag_agent(question: str):
|
127 |
# 1. VDB cevabı ve kaynak url
|
128 |
result = await retrieve_sources_from_pinecone(question)
|
|
|
137 |
vdb_paragraph = clean_text_output(vdb_paragraph)
|
138 |
model_paragraph = clean_text_output(model_paragraph)
|
139 |
|
140 |
+
# --- NOKTA KONTROLÜ EKLENDİ ---
|
141 |
+
vdb_paragraph = cut_at_last_period(vdb_paragraph)
|
142 |
+
model_paragraph = cut_at_last_period(model_paragraph)
|
143 |
+
# -----------------------------
|
144 |
+
|
145 |
# 4. Cross-encoder ile skorlama
|
146 |
candidates = []
|
147 |
candidate_urls = []
|
|
|
168 |
if len(scores) == 2:
|
169 |
vdb_score = scores[0]
|
170 |
model_score = scores[1]
|
|
|
171 |
if model_score > 1.5 * vdb_score:
|
172 |
best_idx = 1
|
173 |
else:
|
174 |
best_idx = 0
|
175 |
else:
|
|
|
176 |
best_idx = int(np.argmax(scores))
|
177 |
|
178 |
final_answer = candidates[best_idx]
|
179 |
final_source_url = candidate_urls[best_idx]
|
180 |
|
181 |
+
# --- SON NOKTA KONTROLÜ FINAL CEVAPTA DA ---
|
182 |
+
final_answer = cut_at_last_period(final_answer)
|
183 |
+
# -------------------------------------------
|
184 |
+
|
185 |
return {
|
186 |
"answer": final_answer,
|
187 |
"source_url": final_source_url
|