(self, _session: Session)
| 512 | token_usage=token_usage) |
| 513 | |
| 514 | def generate_recommend_questions_task(self, _session: Session): |
| 515 | |
| 516 | # get schema |
| 517 | if self.ds and not self.chat_question.db_schema: |
| 518 | self.chat_question.db_schema, tables = self.out_ds_instance.get_db_schema( |
| 519 | self.ds.id, self.chat_question.question) if self.out_ds_instance else get_table_schema( |
| 520 | session=_session, |
| 521 | current_user=self.current_user, ds=self.ds, |
| 522 | question=self.chat_question.question, |
| 523 | embedding=False) |
| 524 | |
| 525 | # Get sample data for all tables |
| 526 | # if not self.out_ds_instance: |
| 527 | # self.chat_question.sample_data = get_tables_sample_data( |
| 528 | # session=_session, |
| 529 | # current_user=self.current_user, |
| 530 | # ds=self.ds) |
| 531 | |
| 532 | guess_msg: List[Union[BaseMessage, dict[str, Any]]] = [] |
| 533 | guess_msg.append(SystemPromptMessage(content=self.chat_question.guess_sys_question(self.articles_number))) |
| 534 | |
| 535 | old_questions = list(map(lambda q: q.strip(), get_old_questions(_session, self.record.datasource))) |
| 536 | guess_msg.append( |
| 537 | HumanMessage(content=self.chat_question.guess_user_question(orjson.dumps(old_questions).decode()))) |
| 538 | |
| 539 | self.current_logs[OperationEnum.GENERATE_RECOMMENDED_QUESTIONS] = start_log(session=_session, |
| 540 | ai_modal_id=self.chat_question.ai_modal_id, |
| 541 | ai_modal_name=self.chat_question.ai_modal_name, |
| 542 | operate=OperationEnum.GENERATE_RECOMMENDED_QUESTIONS, |
| 543 | record_id=self.record.id, |
| 544 | full_message=[ |
| 545 | {'type': msg.type, |
| 546 | 'sqlbot_system': getattr(msg, |
| 547 | 'sqlbot_system', |
| 548 | False) is True, |
| 549 | 'content': msg.content} for |
| 550 | msg |
| 551 | in guess_msg]) |
| 552 | full_thinking_text = '' |
| 553 | full_guess_text = '' |
| 554 | token_usage = {} |
| 555 | res = process_stream(self.llm.stream(guess_msg), token_usage) |
| 556 | for chunk in res: |
| 557 | if chunk.get('content'): |
| 558 | full_guess_text += chunk.get('content') |
| 559 | if chunk.get('reasoning_content'): |
| 560 | full_thinking_text += chunk.get('reasoning_content') |
| 561 | yield chunk |
| 562 | |
| 563 | guess_msg.append(AIMessage(full_guess_text)) |
| 564 | |
| 565 | self.current_logs[OperationEnum.GENERATE_RECOMMENDED_QUESTIONS] = end_log(session=_session, |
| 566 | log=self.current_logs[ |
| 567 | OperationEnum.GENERATE_RECOMMENDED_QUESTIONS], |
| 568 | full_message=[ |
| 569 | {'type': msg.type, |
| 570 | 'sqlbot_system': getattr(msg, |
| 571 | 'sqlbot_system', |
no test coverage detected