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

Method __init__

backend/apps/chat/task/llm.py:98–175  ·  view source on GitHub ↗
(self, session: Session, current_user: CurrentUser, chat_question: ChatQuestion,
                 current_assistant: Optional[CurrentAssistant] = None, no_reasoning: bool = False,
                 embedding: bool = False, config: LLMConfig = None)

Source from the content-addressed store, hash-verified

96 base_message_round_count_limit: int = settings.GENERATE_SQL_QUERY_HISTORY_ROUND_COUNT
97
98 def __init__(self, session: Session, current_user: CurrentUser, chat_question: ChatQuestion,
99 current_assistant: Optional[CurrentAssistant] = None, no_reasoning: bool = False,
100 embedding: bool = False, config: LLMConfig = None):
101 self.sql_message = []
102 self.chart_message = []
103 self.generate_sql_logs = []
104 self.generate_chart_logs = []
105 self.current_logs = {}
106 self.chunk_list = []
107 self.current_user = current_user
108 self.current_assistant = current_assistant
109 chat_id = chat_question.chat_id
110 chat: Chat | None = session.get(Chat, chat_id)
111 if not chat:
112 raise SingleMessageError(f"Chat with id {chat_id} not found")
113 ds: CoreDatasource | AssistantOutDsSchema | None = None
114 if not chat.datasource and chat_question.datasource_id:
115 _ds = session.get(CoreDatasource, chat_question.datasource_id)
116 if _ds:
117 if _ds.oid != current_user.oid:
118 raise SingleMessageError(
119 f"Datasource with id {chat_question.datasource_id} does not belong to current workspace")
120 chat.datasource = _ds.id
121 chat.engine_type = _ds.type_name
122 # save chat
123 session.add(chat)
124 session.flush()
125 session.refresh(chat)
126 session.commit()
127
128 if chat.datasource:
129 # Get available datasource
130 if current_assistant and current_assistant.type in dynamic_ds_types:
131 self.out_ds_instance = AssistantOutDsFactory.get_instance(current_assistant)
132 ds = self.out_ds_instance.get_ds(chat.datasource)
133 if not ds:
134 raise SingleMessageError("No available datasource configuration found")
135 chat_question.engine = ds.type + get_version(ds)
136 else:
137 ds = session.get(CoreDatasource, chat.datasource)
138 if not ds:
139 raise SingleMessageError("No available datasource configuration found")
140 chat_question.engine = (ds.type_name if ds.type != 'excel' else 'PostgreSQL') + get_version(ds)
141
142 self.generate_sql_logs = list_generate_sql_logs(session=session, chart_id=chat_id)
143 self.generate_chart_logs = list_generate_chart_logs(session=session, chart_id=chat_id)
144
145 self.change_title = not get_chat_brief_generate(session=session, chat_id=chat_id)
146
147 chat_question.lang = get_lang_name(current_user.language)
148 self.trans = i18n(lang=current_user.language)
149
150 self.ds = (
151 ds if isinstance(ds, AssistantOutDsSchema) else CoreDatasource(**ds.model_dump())) if ds else None
152 self.chat_question = chat_question
153 self.config = config
154 if no_reasoning:
155 # only work while using qwen

Callers

nothing calls this directly

Calls 13

SingleMessageErrorClass · 0.90
get_versionFunction · 0.90
list_generate_sql_logsFunction · 0.90
list_generate_chart_logsFunction · 0.90
get_chat_brief_generateFunction · 0.90
CoreDatasourceClass · 0.90
get_lang_nameFunction · 0.85
get_instanceMethod · 0.80
get_dsMethod · 0.80
create_llmMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected