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

Method run_analysis_or_predict_task

backend/apps/chat/task/llm.py:1509–1642  ·  view source on GitHub ↗
(self, action_type: str, in_chat: bool = True, stream: bool = True)

Source from the content-addressed store, hash-verified

1507 self.chunk_list.append(chunk)
1508
1509 def run_analysis_or_predict_task(self, action_type: str, in_chat: bool = True, stream: bool = True):
1510 json_result: Dict[str, Any] = {'success': True}
1511 _session = None
1512 try:
1513 _session = session_maker()
1514 if in_chat:
1515 yield 'data:' + orjson.dumps({'type': 'id', 'id': self.get_record().id}).decode() + '\n\n'
1516 else:
1517 if stream:
1518 yield '> ' + self.trans('i18n_chat.record_id_in_mcp') + str(self.get_record().id) + '\n'
1519 yield '> ' + self.get_record().question + '\n\n'
1520 if not stream:
1521 json_result['record_id'] = self.get_record().id
1522
1523 if action_type == 'analysis':
1524 # generate analysis
1525 analysis_res = self.generate_analysis(_session)
1526 full_text = ''
1527 for chunk in analysis_res:
1528 full_text += chunk.get('content')
1529 if in_chat:
1530 yield 'data:' + orjson.dumps(
1531 {'content': chunk.get('content'), 'reasoning_content': chunk.get('reasoning_content'),
1532 'type': 'analysis-result'}).decode() + '\n\n'
1533 else:
1534 if stream:
1535 yield chunk.get('content')
1536 if in_chat:
1537 yield 'data:' + orjson.dumps({'type': 'info', 'msg': 'analysis generated'}).decode() + '\n\n'
1538 yield 'data:' + orjson.dumps({'type': 'analysis_finish'}).decode() + '\n\n'
1539 else:
1540 if stream:
1541 yield '\n\n'
1542 if not stream:
1543 json_result['content'] = full_text
1544
1545 elif action_type == 'predict':
1546 # generate predict
1547 analysis_res = self.generate_predict(_session)
1548 full_text = ''
1549 for chunk in analysis_res:
1550 full_text += chunk.get('content')
1551 if in_chat:
1552 yield 'data:' + orjson.dumps(
1553 {'content': chunk.get('content'), 'reasoning_content': chunk.get('reasoning_content'),
1554 'type': 'predict-result'}).decode() + '\n\n'
1555 if in_chat:
1556 yield 'data:' + orjson.dumps({'type': 'info', 'msg': 'predict generated'}).decode() + '\n\n'
1557
1558 has_data = self.check_save_predict_data(session=_session, res=full_text)
1559 if has_data:
1560 if in_chat:
1561 yield 'data:' + orjson.dumps({'type': 'predict-success'}).decode() + '\n\n'
1562 else:
1563 chart = get_chat_chart_config(_session, self.record.id)
1564 origin_data = get_chat_chart_data(_session, self.record.id)
1565 predict_data = get_chat_predict_data(_session, self.record.id)
1566

Callers 1

Calls 15

get_recordMethod · 0.95
generate_analysisMethod · 0.95
generate_predictMethod · 0.95
finishMethod · 0.95
save_errorMethod · 0.95
get_chat_chart_configFunction · 0.90
get_chat_chart_dataFunction · 0.90
get_chat_predict_dataFunction · 0.90
format_json_dataFunction · 0.90
request_pictureFunction · 0.85

Tested by

no test coverage detected