mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
perf: Assistant uses workspace-level Q&A configuration
This commit is contained in:
committed by
fit2cloud-chenyw
parent
c47d0a2643
commit
bca72fc96d
@@ -268,11 +268,18 @@ class LLMService:
|
||||
return format_chart_fields(chart_info)
|
||||
|
||||
def filter_terminology_template(self, _session: Session, oid: int = None, ds_id: int = None):
|
||||
calculate_oid = oid
|
||||
calculate_ds_id = ds_id
|
||||
if self.current_assistant:
|
||||
calculate_oid = self.current_assistant.oid if self.current_assistant.type != 4 else self.current_user.oid
|
||||
if self.current_assistant.type == 1:
|
||||
calculate_ds_id = None
|
||||
self.current_logs[OperationEnum.FILTER_TERMS] = start_log(session=_session,
|
||||
operate=OperationEnum.FILTER_TERMS,
|
||||
record_id=self.record.id, local_operation=True)
|
||||
|
||||
self.chat_question.terminologies, term_list = get_terminology_template(_session, self.chat_question.question,
|
||||
oid, ds_id)
|
||||
calculate_oid, calculate_ds_id)
|
||||
self.current_logs[OperationEnum.FILTER_TERMS] = end_log(session=_session,
|
||||
log=self.current_logs[OperationEnum.FILTER_TERMS],
|
||||
full_message=term_list)
|
||||
@@ -280,12 +287,18 @@ class LLMService:
|
||||
def filter_custom_prompts(self, _session: Session, custom_prompt_type: CustomPromptTypeEnum, oid: int = None,
|
||||
ds_id: int = None):
|
||||
if SQLBotLicenseUtil.valid():
|
||||
calculate_oid = oid
|
||||
calculate_ds_id = ds_id
|
||||
if self.current_assistant:
|
||||
calculate_oid = self.current_assistant.oid if self.current_assistant.type != 4 else self.current_user.oid
|
||||
if self.current_assistant.type == 1:
|
||||
calculate_ds_id = None
|
||||
self.current_logs[OperationEnum.FILTER_CUSTOM_PROMPT] = start_log(session=_session,
|
||||
operate=OperationEnum.FILTER_CUSTOM_PROMPT,
|
||||
record_id=self.record.id,
|
||||
local_operation=True)
|
||||
self.chat_question.custom_prompt, prompt_list = find_custom_prompts(_session, custom_prompt_type, oid,
|
||||
ds_id)
|
||||
self.chat_question.custom_prompt, prompt_list = find_custom_prompts(_session, custom_prompt_type, calculate_oid,
|
||||
calculate_ds_id)
|
||||
self.current_logs[OperationEnum.FILTER_CUSTOM_PROMPT] = end_log(session=_session,
|
||||
log=self.current_logs[
|
||||
OperationEnum.FILTER_CUSTOM_PROMPT],
|
||||
@@ -296,14 +309,20 @@ class LLMService:
|
||||
operate=OperationEnum.FILTER_SQL_EXAMPLE,
|
||||
record_id=self.record.id,
|
||||
local_operation=True)
|
||||
calculate_oid = oid
|
||||
calculate_ds_id = ds_id
|
||||
if self.current_assistant:
|
||||
calculate_oid = self.current_assistant.oid if self.current_assistant.type != 4 else self.current_user.oid
|
||||
if self.current_assistant.type == 1:
|
||||
calculate_ds_id = None
|
||||
if self.current_assistant and self.current_assistant.type == 1:
|
||||
self.chat_question.data_training, example_list = get_training_template(_session,
|
||||
self.chat_question.question, oid,
|
||||
self.chat_question.question, calculate_oid,
|
||||
None, self.current_assistant.id)
|
||||
else:
|
||||
self.chat_question.data_training, example_list = get_training_template(_session,
|
||||
self.chat_question.question, oid,
|
||||
ds_id)
|
||||
self.chat_question.question, calculate_oid,
|
||||
calculate_ds_id)
|
||||
self.current_logs[OperationEnum.FILTER_SQL_EXAMPLE] = end_log(session=_session,
|
||||
log=self.current_logs[
|
||||
OperationEnum.FILTER_SQL_EXAMPLE],
|
||||
|
||||
@@ -171,15 +171,7 @@ class TokenMiddleware(BaseHTTPMiddleware):
|
||||
assistant_info = await get_assistant_info(session=session, assistant_id=payload['assistant_id'])
|
||||
assistant_info = AssistantModel.model_validate(assistant_info)
|
||||
assistant_info = AssistantHeader.model_validate(assistant_info.model_dump(exclude_unset=True))
|
||||
if assistant_info and assistant_info.type == 0:
|
||||
if payload['oid']:
|
||||
session_user.oid = int(payload['oid'])
|
||||
else:
|
||||
assistant_oid = 1
|
||||
configuration = assistant_info.configuration
|
||||
config_obj = json.loads(configuration) if configuration else {}
|
||||
assistant_oid = config_obj.get('oid', 1)
|
||||
session_user.oid = int(assistant_oid)
|
||||
session_user.oid = int(assistant_info.oid)
|
||||
|
||||
return True, session_user, assistant_info
|
||||
except Exception as e:
|
||||
@@ -226,7 +218,8 @@ class TokenMiddleware(BaseHTTPMiddleware):
|
||||
if not session_user.oid or session_user.oid == 0:
|
||||
message = trans('i18n_login.no_associated_ws', msg = trans('i18n_concat_admin'))
|
||||
raise Exception(message)
|
||||
|
||||
if session_user.oid:
|
||||
assistant_info.oid = int(session_user.oid)
|
||||
return True, session_user, assistant_info
|
||||
except Exception as e:
|
||||
SQLBotLogUtil.exception(f"Embedded validation error: {str(e)}")
|
||||
|
||||
@@ -109,6 +109,7 @@ class AssistantBase(BaseModel):
|
||||
type: int = Field(default=0, description=f"{PLACEHOLDER_PREFIX}assistant_type") # 0普通小助手 1高级 4页面嵌入
|
||||
configuration: Optional[str] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}assistant_configuration")
|
||||
description: Optional[str] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}assistant_description")
|
||||
oid: Optional[int] = Field(default=1, description=f"{PLACEHOLDER_PREFIX}oid")
|
||||
|
||||
|
||||
class AssistantDTO(AssistantBase, BaseCreatorDTO):
|
||||
|
||||
Reference in New Issue
Block a user