77
88from apps .template .generate_analysis .generator import get_analysis_template
99from apps .template .generate_chart .generator import get_chart_template
10+ from apps .template .generate_guess_question .generator import get_guess_question_template
1011from apps .template .generate_predict .generator import get_predict_template
1112from apps .template .generate_sql .generator import get_sql_template
13+ from apps .template .select_datasource .generator import get_datasource_template
1214
1315
1416class Chat (SQLModel , table = True ):
@@ -25,11 +27,13 @@ class Chat(SQLModel, table=True):
2527class ChatRecord (SQLModel , table = True ):
2628 __tablename__ = "chat_record"
2729 id : Optional [int ] = Field (sa_column = Column (Integer , Identity (always = True ), primary_key = True ))
28- chat_id : int = Field (sa_column = Column (Integer ))
30+ chat_id : int = Field (sa_column = Column (Integer , nullable = False ))
31+ ai_modal_id : Optional [int ] = Field (sa_column = Column (Integer ))
32+ first_chat : bool = Field (sa_column = Column (Boolean , nullable = True , default = False ))
2933 create_time : datetime = Field (sa_column = Column (DateTime (timezone = True ), nullable = True ))
3034 finish_time : datetime = Field (sa_column = Column (DateTime (timezone = True ), nullable = True ))
3135 create_by : int = Field (sa_column = Column (BigInteger , nullable = True ))
32- datasource : int = Field (sa_column = Column (Integer , nullable = False ))
36+ datasource : int = Field (sa_column = Column (Integer , nullable = True ))
3337 engine_type : str = Field (max_length = 64 )
3438 question : str = Field (sa_column = Column (Text , nullable = True ))
3539 sql_answer : str = Field (sa_column = Column (Text , nullable = True ))
@@ -41,10 +45,21 @@ class ChatRecord(SQLModel, table=True):
4145 analysis : str = Field (sa_column = Column (Text , nullable = True ))
4246 predict : str = Field (sa_column = Column (Text , nullable = True ))
4347 predict_data : str = Field (sa_column = Column (Text , nullable = True ))
48+ recommended_question_answer : str = Field (sa_column = Column (Text , nullable = True ))
49+ recommended_question : str = Field (sa_column = Column (Text , nullable = True ))
50+ datasource_select_answer : str = Field (sa_column = Column (Text , nullable = True ))
4451 full_sql_message : str = Field (sa_column = Column (Text , nullable = True ))
52+ token_sql : int = Field (default = 0 , nullable = True )
4553 full_chart_message : str = Field (sa_column = Column (Text , nullable = True ))
54+ token_chart : int = Field (default = 0 , nullable = True )
4655 full_analysis_message : str = Field (sa_column = Column (Text , nullable = True ))
56+ token_analysis : int = Field (default = 0 , nullable = True )
4757 full_predict_message : str = Field (sa_column = Column (Text , nullable = True ))
58+ token_predict : int = Field (default = 0 , nullable = True )
59+ full_recommended_question_message : str = Field (sa_column = Column (Text , nullable = True ))
60+ token_recommended_question : int = Field (default = 0 , nullable = True )
61+ full_select_datasource_message : str = Field (sa_column = Column (Text , nullable = True ))
62+ token_select_datasource_question : int = Field (default = 0 , nullable = True )
4863 finish : bool = Field (sa_column = Column (Boolean , nullable = True , default = False ))
4964 error : str = Field (sa_column = Column (Text , nullable = True ))
5065 run_time : float = Field (default = 0 )
@@ -67,7 +82,7 @@ class ChatInfo(BaseModel):
6782 create_by : int = None
6883 brief : str = ''
6984 chat_type : str = "chat"
70- datasource : int = None
85+ datasource : Optional [ int ] = None
7186 engine_type : str = ''
7287 datasource_name : str = ''
7388 datasource_exists : bool = True
@@ -108,6 +123,19 @@ def predict_sys_question(self):
108123 def predict_user_question (self ):
109124 return get_predict_template ()['user' ].format (fields = self .fields , data = self .data , lang = self .lang )
110125
126+ def datasource_sys_question (self ):
127+ return get_datasource_template ()['system' ]
128+
129+ def datasource_user_question (self , datasource_list : str = "[]" ):
130+ return get_datasource_template ()['user' ].format (question = self .question , data = datasource_list , lang = self .lang )
131+
132+ def datasource_guess_sys_question (self ):
133+ return get_guess_question_template ()['system' ]
134+
135+ def datasource_guess_user_question (self , old_questions : str = "[]" ):
136+ return get_guess_question_template ()['user' ].format (question = self .question , schema = self .db_schema ,
137+ old_questions = old_questions , lang = self .lang )
138+
111139
112140class ChatQuestion (AiModelQuestion ):
113141 question : str
0 commit comments