Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add component 'Template' #3562

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/component/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .akshare import AkShare, AkShareParam
from .crawler import Crawler, CrawlerParam
from .invoke import Invoke, InvokeParam
from .template import Template, TemplateParam


def component_class(class_name):
Expand Down
2 changes: 1 addition & 1 deletion agent/component/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _run(self, history, **kwargs):
else: retrieval_res = pd.DataFrame([])

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:
retrieval_res = self.get_input()
Expand Down
2 changes: 1 addition & 1 deletion agent/component/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _run(self, history, **kwargs):
self._param.inputs.append({"component_id": para["component_id"], "content": kwargs[para["key"]]})

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)

4 changes: 1 addition & 3 deletions api/apps/kb_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def rm():
if not KnowledgebaseService.delete_by_id(req["kb_id"]):
return get_data_error_result(
message="Database error (Knowledgebase removal)!")
tenants = UserTenantService.query(user_id=current_user.id)
for tenant in tenants:
settings.docStoreConn.deleteIdx(search.index_name(tenant.tenant_id), req["kb_id"])
settings.docStoreConn.delete({"kb_id": req["kb_id"]}, search.index_name(kbs[0].tenant_id), req["kb_id"])
return get_json_result(data=True)
except Exception as e:
return server_error_response(e)
4 changes: 2 additions & 2 deletions api/apps/user_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ def user_register(user_id, user):
"llm_name": llm.llm_name,
"model_type": llm.model_type,
"api_key": settings.API_KEY,
"api_base": settings.LLM_BASE_URL,
"max_tokens": llm.max_tokens
"api_base": settings.LLM_BASE_URL
#"max_tokens": llm.max_tokens if llm.max_tokens else 8192
}
)

Expand Down
4 changes: 3 additions & 1 deletion rag/utils/es_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def insert(self, documents: list[dict], indexName: str, knowledgebaseId: str) ->
for _ in range(ATTEMPT_TIME):
try:
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):
return res

Expand All @@ -249,7 +249,9 @@ def insert(self, documents: list[dict], indexName: str, knowledgebaseId: str) ->
return res
except Exception as e:
logging.warning("ESConnection.insert got exception: " + str(e))
res = []
if re.search(r"(Timeout|time out)", str(e), re.IGNORECASE):
res.append(str(e))
time.sleep(3)
continue
return res
Expand Down
Loading