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

Method generate_chart

backend/apps/chat/task/llm.py:901–941  ·  view source on GitHub ↗
(self, _session: Session, chart_type: Optional[str] = '', schema: Optional[str] = '')

Source from the content-addressed store, hash-verified

899 return self.build_table_filter(session=_session, sql=sql, filters=filters)
900
901 def generate_chart(self, _session: Session, chart_type: Optional[str] = '', schema: Optional[str] = ''):
902 # append current question
903 self.chart_message.append(HumanMessage(self.chat_question.chart_user_question(chart_type, schema)))
904
905 self.current_logs[OperationEnum.GENERATE_CHART] = start_log(session=_session,
906 ai_modal_id=self.chat_question.ai_modal_id,
907 ai_modal_name=self.chat_question.ai_modal_name,
908 operate=OperationEnum.GENERATE_CHART,
909 record_id=self.record.id,
910 full_message=[
911 {'type': msg.type,
912 'sqlbot_system': getattr(msg, 'sqlbot_system',
913 False) is True,
914 'content': msg.content} for
915 msg
916 in self.chart_message])
917 full_thinking_text = ''
918 full_chart_text = ''
919 token_usage = {}
920 res = process_stream(self.llm.stream(self.chart_message), token_usage)
921 for chunk in res:
922 if chunk.get('content'):
923 full_chart_text += chunk.get('content')
924 if chunk.get('reasoning_content'):
925 full_thinking_text += chunk.get('reasoning_content')
926 yield chunk
927
928 self.chart_message.append(AIMessage(full_chart_text))
929
930 self.record = save_chart_answer(session=_session, record_id=self.record.id,
931 answer=orjson.dumps({'content': full_chart_text}).decode())
932 self.current_logs[OperationEnum.GENERATE_CHART] = end_log(session=_session,
933 log=self.current_logs[OperationEnum.GENERATE_CHART],
934 full_message=[
935 {'type': msg.type,
936 'sqlbot_system': getattr(msg, 'sqlbot_system',
937 False) is True,
938 'content': msg.content}
939 for msg in self.chart_message],
940 reasoning_content=full_thinking_text,
941 token_usage=token_usage)
942
943 def check_sql(self, session: Session, res: str, operate: OperationEnum) -> tuple[str, Optional[list]]:
944 json_str = extract_nested_json(res)

Callers 1

run_taskMethod · 0.95

Calls 7

start_logFunction · 0.90
save_chart_answerFunction · 0.90
end_logFunction · 0.90
process_streamFunction · 0.85
chart_user_questionMethod · 0.80
getMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected