Skip to content

Commit bca72fc

Browse files
perf: Assistant uses workspace-level Q&A configuration
1 parent c47d0a2 commit bca72fc

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

backend/apps/chat/task/llm.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,37 @@ def get_fields_from_chart(self, _session: Session):
268268
return format_chart_fields(chart_info)
269269

270270
def filter_terminology_template(self, _session: Session, oid: int = None, ds_id: int = None):
271+
calculate_oid = oid
272+
calculate_ds_id = ds_id
273+
if self.current_assistant:
274+
calculate_oid = self.current_assistant.oid if self.current_assistant.type != 4 else self.current_user.oid
275+
if self.current_assistant.type == 1:
276+
calculate_ds_id = None
271277
self.current_logs[OperationEnum.FILTER_TERMS] = start_log(session=_session,
272278
operate=OperationEnum.FILTER_TERMS,
273279
record_id=self.record.id, local_operation=True)
280+
274281
self.chat_question.terminologies, term_list = get_terminology_template(_session, self.chat_question.question,
275-
oid, ds_id)
282+
calculate_oid, calculate_ds_id)
276283
self.current_logs[OperationEnum.FILTER_TERMS] = end_log(session=_session,
277284
log=self.current_logs[OperationEnum.FILTER_TERMS],
278285
full_message=term_list)
279286

280287
def filter_custom_prompts(self, _session: Session, custom_prompt_type: CustomPromptTypeEnum, oid: int = None,
281288
ds_id: int = None):
282289
if SQLBotLicenseUtil.valid():
290+
calculate_oid = oid
291+
calculate_ds_id = ds_id
292+
if self.current_assistant:
293+
calculate_oid = self.current_assistant.oid if self.current_assistant.type != 4 else self.current_user.oid
294+
if self.current_assistant.type == 1:
295+
calculate_ds_id = None
283296
self.current_logs[OperationEnum.FILTER_CUSTOM_PROMPT] = start_log(session=_session,
284297
operate=OperationEnum.FILTER_CUSTOM_PROMPT,
285298
record_id=self.record.id,
286299
local_operation=True)
287-
self.chat_question.custom_prompt, prompt_list = find_custom_prompts(_session, custom_prompt_type, oid,
288-
ds_id)
300+
self.chat_question.custom_prompt, prompt_list = find_custom_prompts(_session, custom_prompt_type, calculate_oid,
301+
calculate_ds_id)
289302
self.current_logs[OperationEnum.FILTER_CUSTOM_PROMPT] = end_log(session=_session,
290303
log=self.current_logs[
291304
OperationEnum.FILTER_CUSTOM_PROMPT],
@@ -296,14 +309,20 @@ def filter_training_template(self, _session: Session, oid: int = None, ds_id: in
296309
operate=OperationEnum.FILTER_SQL_EXAMPLE,
297310
record_id=self.record.id,
298311
local_operation=True)
312+
calculate_oid = oid
313+
calculate_ds_id = ds_id
314+
if self.current_assistant:
315+
calculate_oid = self.current_assistant.oid if self.current_assistant.type != 4 else self.current_user.oid
316+
if self.current_assistant.type == 1:
317+
calculate_ds_id = None
299318
if self.current_assistant and self.current_assistant.type == 1:
300319
self.chat_question.data_training, example_list = get_training_template(_session,
301-
self.chat_question.question, oid,
320+
self.chat_question.question, calculate_oid,
302321
None, self.current_assistant.id)
303322
else:
304323
self.chat_question.data_training, example_list = get_training_template(_session,
305-
self.chat_question.question, oid,
306-
ds_id)
324+
self.chat_question.question, calculate_oid,
325+
calculate_ds_id)
307326
self.current_logs[OperationEnum.FILTER_SQL_EXAMPLE] = end_log(session=_session,
308327
log=self.current_logs[
309328
OperationEnum.FILTER_SQL_EXAMPLE],

backend/apps/system/middleware/auth.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,7 @@ async def validateAssistant(self, assistantToken: Optional[str], trans: I18n) ->
171171
assistant_info = await get_assistant_info(session=session, assistant_id=payload['assistant_id'])
172172
assistant_info = AssistantModel.model_validate(assistant_info)
173173
assistant_info = AssistantHeader.model_validate(assistant_info.model_dump(exclude_unset=True))
174-
if assistant_info and assistant_info.type == 0:
175-
if payload['oid']:
176-
session_user.oid = int(payload['oid'])
177-
else:
178-
assistant_oid = 1
179-
configuration = assistant_info.configuration
180-
config_obj = json.loads(configuration) if configuration else {}
181-
assistant_oid = config_obj.get('oid', 1)
182-
session_user.oid = int(assistant_oid)
174+
session_user.oid = int(assistant_info.oid)
183175

184176
return True, session_user, assistant_info
185177
except Exception as e:
@@ -226,7 +218,8 @@ async def validateEmbedded(self, param: str, trans: I18n) -> tuple[any]:
226218
if not session_user.oid or session_user.oid == 0:
227219
message = trans('i18n_login.no_associated_ws', msg = trans('i18n_concat_admin'))
228220
raise Exception(message)
229-
221+
if session_user.oid:
222+
assistant_info.oid = int(session_user.oid)
230223
return True, session_user, assistant_info
231224
except Exception as e:
232225
SQLBotLogUtil.exception(f"Embedded validation error: {str(e)}")

backend/apps/system/schemas/system_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class AssistantBase(BaseModel):
109109
type: int = Field(default=0, description=f"{PLACEHOLDER_PREFIX}assistant_type") # 0普通小助手 1高级 4页面嵌入
110110
configuration: Optional[str] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}assistant_configuration")
111111
description: Optional[str] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}assistant_description")
112+
oid: Optional[int] = Field(default=1, description=f"{PLACEHOLDER_PREFIX}oid")
112113

113114

114115
class AssistantDTO(AssistantBase, BaseCreatorDTO):

0 commit comments

Comments
 (0)