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

Method generate_predict

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

Source from the content-addressed store, hash-verified

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)
465 self.chat_question.fields = orjson.dumps(fields).decode()
466 data = get_chat_chart_data(_session, self.record.id)
467 self.chat_question.data = orjson.dumps(data.get('data')).decode()
468
469 ds_id = self.ds.id if isinstance(self.ds, CoreDatasource) else None
470 self.filter_custom_prompts(_session, CustomPromptTypeEnum.PREDICT_DATA, self.current_user.oid, ds_id)
471
472 predict_msg: List[Union[BaseMessage, dict[str, Any]]] = []
473 predict_msg.append(SystemPromptMessage(content=self.chat_question.predict_sys_question()))
474 predict_msg.append(HumanMessage(content=self.chat_question.predict_user_question()))
475
476 self.current_logs[OperationEnum.PREDICT_DATA] = start_log(session=_session,
477 ai_modal_id=self.chat_question.ai_modal_id,
478 ai_modal_name=self.chat_question.ai_modal_name,
479 operate=OperationEnum.PREDICT_DATA,
480 record_id=self.record.id,
481 full_message=[
482 {'type': msg.type,
483 'sqlbot_system': getattr(msg, 'sqlbot_system',
484 False) is True,
485 'content': msg.content} for
486 msg
487 in predict_msg])
488 full_thinking_text = ''
489 full_predict_text = ''
490 token_usage = {}
491 res = process_stream(self.llm.stream(predict_msg), token_usage)
492 for chunk in res:
493 if chunk.get('content'):
494 full_predict_text += chunk.get('content')
495 if chunk.get('reasoning_content'):
496 full_thinking_text += chunk.get('reasoning_content')
497 yield chunk
498
499 predict_msg.append(AIMessage(full_predict_text))
500 self.record = save_predict_answer(session=_session, record_id=self.record.id,
501 answer=orjson.dumps({'content': full_predict_text}).decode())
502 self.current_logs[OperationEnum.PREDICT_DATA] = end_log(session=_session,
503 log=self.current_logs[
504 OperationEnum.PREDICT_DATA],
505 full_message=[
506 {'type': msg.type,
507 'sqlbot_system': getattr(msg, 'sqlbot_system',
508 False) is True,
509 'content': msg.content}
510 for msg in predict_msg],
511 reasoning_content=full_thinking_text,
512 token_usage=token_usage)
513
514 def generate_recommend_questions_task(self, _session: Session):
515

Callers 1

Calls 12

get_fields_from_chartMethod · 0.95
filter_custom_promptsMethod · 0.95
get_chat_chart_dataFunction · 0.90
SystemPromptMessageClass · 0.90
start_logFunction · 0.90
save_predict_answerFunction · 0.90
end_logFunction · 0.90
process_streamFunction · 0.85
predict_sys_questionMethod · 0.80
predict_user_questionMethod · 0.80
getMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected