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

Method generate_analysis

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

Source from the content-addressed store, hash-verified

406 full_message=self.chat_question.db_schema)
407
408 def generate_analysis(self, _session: Session):
409 fields = self.get_fields_from_chart(_session)
410 self.chat_question.fields = orjson.dumps(fields).decode()
411 data = get_chat_chart_data(_session, self.record.id)
412 self.chat_question.data = orjson.dumps(data.get('data')).decode()
413 analysis_msg: List[Union[BaseMessage, dict[str, Any]]] = []
414
415 ds_id = self.ds.id if isinstance(self.ds, CoreDatasource) else None
416
417 self.filter_terminology_template(_session, self.current_user.oid, ds_id)
418
419 self.filter_custom_prompts(_session, CustomPromptTypeEnum.ANALYSIS, self.current_user.oid, ds_id)
420
421 analysis_msg.append(SystemPromptMessage(content=self.chat_question.analysis_sys_question()))
422 analysis_msg.append(HumanMessage(content=self.chat_question.analysis_user_question()))
423
424 self.current_logs[OperationEnum.ANALYSIS] = start_log(session=_session,
425 ai_modal_id=self.chat_question.ai_modal_id,
426 ai_modal_name=self.chat_question.ai_modal_name,
427 operate=OperationEnum.ANALYSIS,
428 record_id=self.record.id,
429 full_message=[
430 {'type': msg.type,
431 'sqlbot_system': getattr(msg, 'sqlbot_system',
432 False) is True,
433 'content': msg.content} for
434 msg
435 in analysis_msg])
436 full_thinking_text = ''
437 full_analysis_text = ''
438 token_usage = {}
439 res = process_stream(self.llm.stream(analysis_msg), token_usage)
440 for chunk in res:
441 if chunk.get('content'):
442 full_analysis_text += chunk.get('content')
443 if chunk.get('reasoning_content'):
444 full_thinking_text += chunk.get('reasoning_content')
445 yield chunk
446
447 analysis_msg.append(AIMessage(full_analysis_text))
448
449 self.current_logs[OperationEnum.ANALYSIS] = end_log(session=_session,
450 log=self.current_logs[
451 OperationEnum.ANALYSIS],
452 full_message=[
453 {'type': msg.type,
454 'sqlbot_system': getattr(msg, 'sqlbot_system',
455 False) is True,
456 'content': msg.content}
457 for msg in analysis_msg],
458 reasoning_content=full_thinking_text,
459 token_usage=token_usage)
460 self.record = save_analysis_answer(session=_session, record_id=self.record.id,
461 answer=orjson.dumps({'content': full_analysis_text}).decode())
462
463 def generate_predict(self, _session: Session):
464 fields = self.get_fields_from_chart(_session)

Callers 1

Calls 13

get_fields_from_chartMethod · 0.95
filter_custom_promptsMethod · 0.95
get_chat_chart_dataFunction · 0.90
SystemPromptMessageClass · 0.90
start_logFunction · 0.90
end_logFunction · 0.90
save_analysis_answerFunction · 0.90
process_streamFunction · 0.85
analysis_sys_questionMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected