mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 16:19:01 +08:00
Add component 'Template' (#3562)
### What problem does this PR solve? #3560 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
193b08a3ed
commit
ee50f78d99
@ -30,6 +30,7 @@ from .tushare import TuShare, TuShareParam
|
|||||||
from .akshare import AkShare, AkShareParam
|
from .akshare import AkShare, AkShareParam
|
||||||
from .crawler import Crawler, CrawlerParam
|
from .crawler import Crawler, CrawlerParam
|
||||||
from .invoke import Invoke, InvokeParam
|
from .invoke import Invoke, InvokeParam
|
||||||
|
from .template import Template, TemplateParam
|
||||||
|
|
||||||
|
|
||||||
def component_class(class_name):
|
def component_class(class_name):
|
||||||
|
@ -145,7 +145,7 @@ class Generate(ComponentBase):
|
|||||||
else: retrieval_res = pd.DataFrame([])
|
else: retrieval_res = pd.DataFrame([])
|
||||||
|
|
||||||
for n, v in kwargs.items():
|
for n, v in kwargs.items():
|
||||||
prompt = re.sub(r"\{%s\}" % re.escape(n), re.escape(str(v)), prompt)
|
prompt = re.sub(r"\{%s\}" % re.escape(n), str(v), prompt)
|
||||||
|
|
||||||
if not self._param.inputs and prompt.find("{input}") >= 0:
|
if not self._param.inputs and prompt.find("{input}") >= 0:
|
||||||
retrieval_res = self.get_input()
|
retrieval_res = self.get_input()
|
||||||
|
@ -79,7 +79,7 @@ class Template(ComponentBase):
|
|||||||
self._param.inputs.append({"component_id": para["component_id"], "content": kwargs[para["key"]]})
|
self._param.inputs.append({"component_id": para["component_id"], "content": kwargs[para["key"]]})
|
||||||
|
|
||||||
for n, v in kwargs.items():
|
for n, v in kwargs.items():
|
||||||
content = re.sub(r"\{%s\}" % re.escape(n), re.escape(str(v)), content)
|
content = re.sub(r"\{%s\}" % re.escape(n), str(v), content)
|
||||||
|
|
||||||
return Template.be_output(content)
|
return Template.be_output(content)
|
||||||
|
|
||||||
|
@ -167,9 +167,7 @@ def rm():
|
|||||||
if not KnowledgebaseService.delete_by_id(req["kb_id"]):
|
if not KnowledgebaseService.delete_by_id(req["kb_id"]):
|
||||||
return get_data_error_result(
|
return get_data_error_result(
|
||||||
message="Database error (Knowledgebase removal)!")
|
message="Database error (Knowledgebase removal)!")
|
||||||
tenants = UserTenantService.query(user_id=current_user.id)
|
settings.docStoreConn.delete({"kb_id": req["kb_id"]}, search.index_name(kbs[0].tenant_id), req["kb_id"])
|
||||||
for tenant in tenants:
|
|
||||||
settings.docStoreConn.deleteIdx(search.index_name(tenant.tenant_id), req["kb_id"])
|
|
||||||
return get_json_result(data=True)
|
return get_json_result(data=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return server_error_response(e)
|
return server_error_response(e)
|
||||||
|
@ -517,8 +517,8 @@ def user_register(user_id, user):
|
|||||||
"llm_name": llm.llm_name,
|
"llm_name": llm.llm_name,
|
||||||
"model_type": llm.model_type,
|
"model_type": llm.model_type,
|
||||||
"api_key": settings.API_KEY,
|
"api_key": settings.API_KEY,
|
||||||
"api_base": settings.LLM_BASE_URL,
|
"api_base": settings.LLM_BASE_URL
|
||||||
"max_tokens": llm.max_tokens
|
#"max_tokens": llm.max_tokens if llm.max_tokens else 8192
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ class ESConnection(DocStoreConnection):
|
|||||||
for _ in range(ATTEMPT_TIME):
|
for _ in range(ATTEMPT_TIME):
|
||||||
try:
|
try:
|
||||||
r = self.es.bulk(index=(indexName), operations=operations,
|
r = self.es.bulk(index=(indexName), operations=operations,
|
||||||
refresh=False, timeout="600s")
|
refresh=False, timeout="60s")
|
||||||
if re.search(r"False", str(r["errors"]), re.IGNORECASE):
|
if re.search(r"False", str(r["errors"]), re.IGNORECASE):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -249,7 +249,9 @@ class ESConnection(DocStoreConnection):
|
|||||||
return res
|
return res
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning("ESConnection.insert got exception: " + str(e))
|
logging.warning("ESConnection.insert got exception: " + str(e))
|
||||||
|
res = []
|
||||||
if re.search(r"(Timeout|time out)", str(e), re.IGNORECASE):
|
if re.search(r"(Timeout|time out)", str(e), re.IGNORECASE):
|
||||||
|
res.append(str(e))
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
continue
|
continue
|
||||||
return res
|
return res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user