mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 08:39:01 +08:00
Remove <think> for exeSql component. (#5069)
### What problem does this PR solve? #5061 #5067 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
4694604836
commit
84b4b38cbb
@ -61,6 +61,7 @@ class ExeSQL(Generate, ABC):
|
|||||||
component_name = "ExeSQL"
|
component_name = "ExeSQL"
|
||||||
|
|
||||||
def _refactor(self, ans):
|
def _refactor(self, ans):
|
||||||
|
ans = re.sub(r"<think>.*</think>", "", ans, flags=re.DOTALL)
|
||||||
match = re.search(r"```sql\s*(.*?)\s*```", ans, re.DOTALL)
|
match = re.search(r"```sql\s*(.*?)\s*```", ans, re.DOTALL)
|
||||||
if match:
|
if match:
|
||||||
ans = match.group(1) # Query content
|
ans = match.group(1) # Query content
|
||||||
@ -116,7 +117,8 @@ class ExeSQL(Generate, ABC):
|
|||||||
sql_res.append({"content": "No record in the database!"})
|
sql_res.append({"content": "No record in the database!"})
|
||||||
break
|
break
|
||||||
if self._param.db_type == 'mssql':
|
if self._param.db_type == 'mssql':
|
||||||
single_res = pd.DataFrame.from_records(cursor.fetchmany(self._param.top_n),columns = [desc[0] for desc in cursor.description])
|
single_res = pd.DataFrame.from_records(cursor.fetchmany(self._param.top_n),
|
||||||
|
columns=[desc[0] for desc in cursor.description])
|
||||||
else:
|
else:
|
||||||
single_res = pd.DataFrame([i for i in cursor.fetchmany(self._param.top_n)])
|
single_res = pd.DataFrame([i for i in cursor.fetchmany(self._param.top_n)])
|
||||||
single_res.columns = [i[0] for i in cursor.description]
|
single_res.columns = [i[0] for i in cursor.description]
|
||||||
|
@ -567,7 +567,7 @@ Requirements:
|
|||||||
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.2})
|
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.2})
|
||||||
if isinstance(kwd, tuple):
|
if isinstance(kwd, tuple):
|
||||||
kwd = kwd[0]
|
kwd = kwd[0]
|
||||||
kwd = re.sub(r"<think>.*</think>", "", kwd)
|
kwd = re.sub(r"<think>.*</think>", "", kwd, flags=re.DOTALL)
|
||||||
if kwd.find("**ERROR**") >= 0:
|
if kwd.find("**ERROR**") >= 0:
|
||||||
return ""
|
return ""
|
||||||
return kwd
|
return kwd
|
||||||
@ -597,7 +597,7 @@ Requirements:
|
|||||||
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.2})
|
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.2})
|
||||||
if isinstance(kwd, tuple):
|
if isinstance(kwd, tuple):
|
||||||
kwd = kwd[0]
|
kwd = kwd[0]
|
||||||
kwd = re.sub(r"<think>.*</think>", "", kwd)
|
kwd = re.sub(r"<think>.*</think>", "", kwd, flags=re.DOTALL)
|
||||||
if kwd.find("**ERROR**") >= 0:
|
if kwd.find("**ERROR**") >= 0:
|
||||||
return ""
|
return ""
|
||||||
return kwd
|
return kwd
|
||||||
@ -668,7 +668,7 @@ Output: What's the weather in Rochester on {tomorrow}?
|
|||||||
###############
|
###############
|
||||||
"""
|
"""
|
||||||
ans = chat_mdl.chat(prompt, [{"role": "user", "content": "Output: "}], {"temperature": 0.2})
|
ans = chat_mdl.chat(prompt, [{"role": "user", "content": "Output: "}], {"temperature": 0.2})
|
||||||
ans = re.sub(r"<think>.*</think>", "", ans)
|
ans = re.sub(r"<think>.*</think>", "", ans, flags=re.DOTALL)
|
||||||
return ans if ans.find("**ERROR**") < 0 else messages[-1]["content"]
|
return ans if ans.find("**ERROR**") < 0 else messages[-1]["content"]
|
||||||
|
|
||||||
|
|
||||||
@ -793,7 +793,7 @@ Output:
|
|||||||
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.5})
|
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.5})
|
||||||
if isinstance(kwd, tuple):
|
if isinstance(kwd, tuple):
|
||||||
kwd = kwd[0]
|
kwd = kwd[0]
|
||||||
kwd = re.sub(r"<think>.*</think>", "", kwd)
|
kwd = re.sub(r"<think>.*</think>", "", kwd, flags=re.DOTALL)
|
||||||
if kwd.find("**ERROR**") >= 0:
|
if kwd.find("**ERROR**") >= 0:
|
||||||
raise Exception(kwd)
|
raise Exception(kwd)
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class Extractor:
|
|||||||
if response:
|
if response:
|
||||||
return response
|
return response
|
||||||
response = self._llm.chat(system, hist, conf)
|
response = self._llm.chat(system, hist, conf)
|
||||||
response = re.sub(r"<think>.*</think>", "", response)
|
response = re.sub(r"<think>.*</think>", "", response, flags=re.DOTALL)
|
||||||
if response.find("**ERROR**") >= 0:
|
if response.find("**ERROR**") >= 0:
|
||||||
raise Exception(response)
|
raise Exception(response)
|
||||||
set_llm_cache(self._llm.llm_name, system, response, history, gen_conf)
|
set_llm_cache(self._llm.llm_name, system, response, history, gen_conf)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user