MCPcopy Index your code
hub / github.com/dataease/SQLBot / generate_with_sub_sql

Method generate_with_sub_sql

backend/apps/chat/task/llm.py:771–818  ·  view source on GitHub ↗
(self, session: Session, sql, sub_mappings: list)

Source from the content-addressed store, hash-verified

769 answer=orjson.dumps({'content': full_sql_text}).decode())
770
771 def generate_with_sub_sql(self, session: Session, sql, sub_mappings: list):
772 sub_query = json.dumps(sub_mappings, ensure_ascii=False)
773 self.chat_question.sql = sql
774 self.chat_question.sub_query = sub_query
775 dynamic_sql_msg: List[Union[BaseMessage, dict[str, Any]]] = []
776 dynamic_sql_msg.append(SystemPromptMessage(content=self.chat_question.dynamic_sys_question()))
777 dynamic_sql_msg.append(HumanMessage(content=self.chat_question.dynamic_user_question()))
778
779 self.current_logs[OperationEnum.GENERATE_DYNAMIC_SQL] = start_log(session=session,
780 ai_modal_id=self.chat_question.ai_modal_id,
781 ai_modal_name=self.chat_question.ai_modal_name,
782 operate=OperationEnum.GENERATE_DYNAMIC_SQL,
783 record_id=self.record.id,
784 full_message=[{'type': msg.type,
785 'sqlbot_system': getattr(msg,
786 'sqlbot_system',
787 False) is True,
788 'content': msg.content}
789 for
790 msg in dynamic_sql_msg])
791
792 full_thinking_text = ''
793 full_dynamic_text = ''
794 token_usage = {}
795 res = process_stream(self.llm.stream(dynamic_sql_msg), token_usage)
796 for chunk in res:
797 if chunk.get('content'):
798 full_dynamic_text += chunk.get('content')
799 if chunk.get('reasoning_content'):
800 full_thinking_text += chunk.get('reasoning_content')
801
802 dynamic_sql_msg.append(AIMessage(full_dynamic_text))
803
804 self.current_logs[OperationEnum.GENERATE_DYNAMIC_SQL] = end_log(session=session,
805 log=self.current_logs[
806 OperationEnum.GENERATE_DYNAMIC_SQL],
807 full_message=[
808 {'type': msg.type,
809 'sqlbot_system': getattr(msg,
810 'sqlbot_system',
811 False) is True,
812 'content': msg.content}
813 for msg in dynamic_sql_msg],
814 reasoning_content=full_thinking_text,
815 token_usage=token_usage)
816
817 SQLBotLogUtil.info(full_dynamic_text)
818 return full_dynamic_text
819
820 def generate_assistant_dynamic_sql(self, _session: Session, sql, tables: List):
821 ds: AssistantOutDsSchema = self.ds

Callers 1

Calls 9

SystemPromptMessageClass · 0.90
start_logFunction · 0.90
end_logFunction · 0.90
process_streamFunction · 0.85
dynamic_sys_questionMethod · 0.80
dynamic_user_questionMethod · 0.80
getMethod · 0.65
appendMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected