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

Method generate_sql

backend/apps/chat/task/llm.py:728–769  ·  view source on GitHub ↗
(self, _session: Session)

Source from the content-addressed store, hash-verified

726 raise _error
727
728 def generate_sql(self, _session: Session):
729 # append current question
730 self.sql_message.append(HumanMessage(
731 self.chat_question.sql_user_question(current_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
732 change_title=self.change_title)))
733
734 self.current_logs[OperationEnum.GENERATE_SQL] = start_log(session=_session,
735 ai_modal_id=self.chat_question.ai_modal_id,
736 ai_modal_name=self.chat_question.ai_modal_name,
737 operate=OperationEnum.GENERATE_SQL,
738 record_id=self.record.id,
739 full_message=[
740 {'type': msg.type,
741 'sqlbot_system': getattr(msg, 'sqlbot_system',
742 False) is True,
743 'content': msg.content} for msg
744 in self.sql_message])
745 full_thinking_text = ''
746 full_sql_text = ''
747 token_usage = {}
748 res = process_stream(self.llm.stream(self.sql_message), token_usage)
749 for chunk in res:
750 if chunk.get('content'):
751 full_sql_text += chunk.get('content')
752 if chunk.get('reasoning_content'):
753 full_thinking_text += chunk.get('reasoning_content')
754 yield chunk
755
756 self.sql_message.append(AIMessage(full_sql_text))
757
758 self.current_logs[OperationEnum.GENERATE_SQL] = end_log(session=_session,
759 log=self.current_logs[OperationEnum.GENERATE_SQL],
760 full_message=[{'type': msg.type,
761 'sqlbot_system': getattr(msg,
762 'sqlbot_system',
763 False) is True,
764 'content': msg.content}
765 for msg in self.sql_message],
766 reasoning_content=full_thinking_text,
767 token_usage=token_usage)
768 self.record = save_sql_answer(session=_session, record_id=self.record.id,
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)

Callers 1

run_taskMethod · 0.95

Calls 7

start_logFunction · 0.90
end_logFunction · 0.90
save_sql_answerFunction · 0.90
process_streamFunction · 0.85
sql_user_questionMethod · 0.80
getMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected