Skip to content

Commit c6f7e6f

Browse files
committed
feat: support select terminology in chat by using assistant
1 parent fd7d490 commit c6f7e6f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

backend/apps/chat/task/llm.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ def generate_analysis(self):
220220
self.chat_question.data = orjson.dumps(data.get('data')).decode()
221221
analysis_msg: List[Union[BaseMessage, dict[str, Any]]] = []
222222

223-
self.chat_question.terminologies = get_terminology_template(self.session, self.chat_question.question, self.current_user.oid)
223+
self.chat_question.terminologies = get_terminology_template(self.session, self.chat_question.question,
224+
self.current_user.oid)
224225

225226
analysis_msg.append(SystemMessage(content=self.chat_question.analysis_sys_question()))
226227
analysis_msg.append(HumanMessage(content=self.chat_question.analysis_user_question()))
@@ -498,6 +499,10 @@ def select_datasource(self):
498499
answer=orjson.dumps({'content': full_text}).decode(),
499500
datasource=_datasource,
500501
engine_type=_engine_type)
502+
503+
self.chat_question.terminologies = get_terminology_template(self.session, self.chat_question.question,
504+
self.ds.oid if isinstance(self.ds,
505+
CoreDatasource) else 1)
501506
self.init_messages()
502507

503508
if _error:
@@ -894,7 +899,10 @@ def run_task_cache(self, in_chat: bool = True):
894899

895900
def run_task(self, in_chat: bool = True):
896901
try:
897-
self.chat_question.terminologies = get_terminology_template(self.session, self.chat_question.question, self.current_user.oid)
902+
if self.ds:
903+
self.chat_question.terminologies = get_terminology_template(self.session, self.chat_question.question,
904+
self.ds.oid if isinstance(self.ds,
905+
CoreDatasource) else 1)
898906
self.init_messages()
899907

900908
# return id

backend/apps/terminology/curd/terminology.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ def to_xml_string(_dict: list[dict] | dict, root: str = 'terminologies') -> str:
418418
return pretty_xml
419419

420420

421-
def get_terminology_template(session: SessionDep, question: str, oid: int) -> str:
421+
def get_terminology_template(session: SessionDep, question: str, oid: Optional[int] = 1) -> str:
422+
if not oid:
423+
oid = 1
422424
_results = select_terminology_by_word(session, question, oid)
423425
if _results and len(_results) > 0:
424426
terminology = to_xml_string(_results)

0 commit comments

Comments
 (0)