@@ -42,6 +42,8 @@ def __init__(
4242 self .delay_messages = delay_messages
4343 self .outgoing = outgoing
4444 self .incoming = incoming
45+ # add by lu, Set the model name in use
46+ self .llm_in_use_name = None
4547
4648 # self.base_mysql_info = online_base_mysql_info
4749 self .base_mysql_info = local_base_mysql_info
@@ -51,111 +53,80 @@ def __init__(
5153 self .base_postgresql_info = local_base_postgresql_info
5254 self .base_mongodb_info = local_base_mongodb_info
5355 self .base_starrocks_info = None
54-
5556 self .is_log_out = True
56-
5757 self .language_mode = default_language_mode
5858 self .set_language_mode (self .language_mode )
59-
6059 self .api_key_use = False
61-
6260 self .openai_proxy = None
6361 self .db_id = db_id
6462
65- def set_api_key (self , api_key , api_host = None , in_use = CONFIG .apikey_openai ):
66- self .api_key = api_key
6763
68- if in_use == CONFIG .apikey_openai :
64+ def set_api_key (self , api_key , ApiType = "openai" , api_host = None , ApiModel = None , LlmSetting = None ):
65+ self .api_key = api_key
66+ if api_host is not None :
67+ # api_base = "https://api.openai.com/"
68+ print ('api_host: ' , api_host )
6969 self .config_list_gpt4 = [
7070 {
71- 'model' : 'gpt-4' ,
71+ 'model' : ApiModel ,
7272 'api_key' : api_key ,
73+ 'api_base' : api_host ,
74+ 'api_type' : ApiType ,
75+ 'llm_setting' : LlmSetting
7376 },
7477 ]
7578
7679 self .config_list_gpt4_turbo = [
7780 {
78- 'model' : 'gpt-4-1106-preview' ,
81+ 'model' : ApiModel ,
7982 'api_key' : self .api_key ,
80-
83+ 'api_base' : api_host ,
84+ 'api_type' : ApiType ,
85+ 'llm_setting' : LlmSetting
8186 },
8287 ]
8388
8489 self .config_list_gpt35_turbo = [
8590 {
8691 'model' : 'gpt-3.5-turbo-1106' ,
8792 'api_key' : self .api_key ,
93+ 'api_base' : api_host ,
94+ 'api_type' : ApiType ,
95+ 'llm_setting' : LlmSetting
8896 },
8997 ]
98+ else :
9099
91- if api_host is not None :
92- # api_base = "https://api.openai.com/"
93- print ('api_host: ' , api_host )
94- self .config_list_gpt4 [0 ]['api_base' ] = api_host
95- self .config_list_gpt4_turbo [0 ]['api_base' ] = api_host
96- self .config_list_gpt35_turbo [0 ]['api_base' ] = api_host
97-
98- elif in_use == CONFIG .apikey_deepinsight :
99100 self .config_list_gpt4 = [
100101 {
101- 'model' : 'gpt-4' ,
102+ 'model' : ApiModel ,
102103 'api_key' : api_key ,
104+ 'api_type' : ApiType ,
105+ 'llm_setting' : LlmSetting
103106 },
104107 ]
105108
106109 self .config_list_gpt4_turbo = [
107110 {
108- 'model' : 'gpt-4-1106-preview' ,
111+ 'model' : ApiModel ,
109112 'api_key' : self .api_key ,
110113
114+ 'api_type' : ApiType ,
115+ 'llm_setting' : LlmSetting
111116 },
112117 ]
113118
114119 self .config_list_gpt35_turbo = [
115120 {
116121 'model' : 'gpt-3.5-turbo-1106' ,
117122 'api_key' : self .api_key ,
123+ 'api_type' : ApiType ,
124+ 'llm_setting' : LlmSetting
118125 },
119126 ]
120127
121128 if api_host is not None :
122- print ('api_host: ' , api_host )
123- self .config_list_gpt4 [0 ]['api_base' ] = api_host
124- self .config_list_gpt4_turbo [0 ]['api_base' ] = api_host
125- self .config_list_gpt35_turbo [0 ]['api_base' ] = api_host
126-
127- elif in_use == CONFIG .apikey_azure :
128- self .config_list_gpt4 = [
129- {
130- 'model' : 'gpt-4' ,
131- 'api_key' : api_key ,
132- 'api_type' : 'azure' ,
133- 'model' : 'gpt-4' ,
134- 'api_version' : "2023-07-01-preview" ,
135- },
136- ]
137-
138- self .config_list_gpt4_turbo = [
139- {
140- 'model' : 'gpt-4-1106-preview' ,
141- 'api_key' : self .api_key ,
142- 'api_type' : 'azure' ,
143- 'model' : 'gpt-4' ,
144- 'api_version' : "2023-07-01-preview" ,
145- },
146- ]
147-
148- self .config_list_gpt35_turbo = [
149- {
150- 'model' : 'gpt-3.5-turbo-1106' ,
151- 'api_key' : self .api_key ,
152- 'api_type' : 'azure' ,
153- 'model' : 'gpt-4' ,
154- 'api_version' : "2023-07-01-preview" ,
155- },
156- ]
157-
158- if api_host is not None :
129+ # api_base = "https://api.openai.com/"
159130 print ('api_host: ' , api_host )
160131 self .config_list_gpt4 [0 ]['api_base' ] = api_host
161132 self .config_list_gpt4_turbo [0 ]['api_base' ] = api_host
@@ -364,7 +335,7 @@ def get_agent_mongodb_engineer(self):
364335 Example Query information about all users: {"collection": "users"};
365336 Example Query the '_id' and 'name' fields of all users: {"collection": "users", "fields": {"_id": 1, "name": 2}};
366337 Example Query the user named "deep": {"collection": "users", "query": {"name": "deep"}};
367- Example Query all users whose names start with 'deep': {"collection": "users","query":{"name": {"$regex": "^deep"}}}
338+ Example Query all users whose names start with 'deep': {"collection": "users","query":{"name": {"$regex": "^deep"}}}
368339 Example Query the number of users starting with 'deep' among all users :{"collection": "users","query":{"name": {"$regex": "^deep"}},"count":"1"}
369340 Query the top 10 users in descending order of "name":{"collection": "users","sort":[{"name":"name", "direction": -1}],"limit":10}
370341 This is a mongodb database, not mysql, do not use mysql statements,Must be returned using the sample json format.
@@ -1129,7 +1100,7 @@ def get_agent_mysql_matplotlib_assistant(self):
11291100 If you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user.
11301101 If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try.
11311102 When you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible.
1132- The database name needs to be replaced with the actual database name in the database connection string, "your_dbname" in the database connection string "mongodb://your_host:your_port/your_dbname" must be replaced with the actual database name: q
1103+ The database name needs to be replaced with the actual database name in the database connection string, "your_dbname" in the database connection string "mongodb://your_host:your_port/your_dbname" must be replaced with the actual database name: q
11331104 Reply "TERMINATE" in the end when everything is done.
11341105 When you find an answer, You are a report analysis, you have the knowledge and skills to turn raw data into information and insight, which can be used to make business decisions.include your analysis in your reply.
11351106 """ + '\n ' + self .base_mysql_info + '\n ' + python_base_dependency + '\n ' + MYSQL_MATPLOTLIB_TIPS_MESS ,
@@ -1356,7 +1327,7 @@ async def task_generate_report(self, qustion_message):
13561327 "description" ]
13571328 await planner_user .initiate_chat (
13581329 manager ,
1359- message = 'This is database related information: ' + '\n ' + self .base_message + '\n ' + " This is my question: " + '\n ' + str (
1330+ message = 'This is database related information: ' + '\n ' + self .base_message + '\n ' + " This is my question: " + '\n ' + str (
13601331 q_str ),
13611332 )
13621333
@@ -1406,8 +1377,8 @@ async def task_generate_report(self, qustion_message):
14061377 analyst ,
14071378 message = str (
14081379 answer_contents ) + '\n ' + " 以下是我的问题,请用中文回答: " + '\n ' + " 1,本次生成哪些报表?简单描述一下各报表 "
1409- + '\n ' + " 以下是一个回答案例: " + '\n ' +
1410- """总结:
1380+ + '\n ' + " 以下是一个回答案例: " + '\n ' +
1381+ """总结:
14111382 -- Monthly Sales Summary Q1 2019: 同名图表历史已生成过,此次不再生成,若要重新生成图表,请先删除已有同名报表。2019年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
14121383 -- Summary Q1 2018: 生成成功。2018年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
14131384 """ ,
@@ -1437,7 +1408,7 @@ async def task_generate_report(self, qustion_message):
14371408 return "报表生成失败,请检查相关数据是否充分。"
14381409
14391410 async def task_generate_report1108 (self , qustion_message ):
1440- """ 任务类型1: 调用 bi, 生成报表 """
1411+ """ 任务类型1: 调用 bi, 生成报表 """
14411412 try :
14421413 print ('运行 【task_generate_report】函数' )
14431414 error_times = 0 # 失败次数
@@ -1514,7 +1485,7 @@ async def task_generate_report1108(self, qustion_message):
15141485 "description" ]
15151486 await planner_user .initiate_chat (
15161487 manager ,
1517- message = 'This is database related information: ' + '\n ' + self .base_message + '\n ' + " This is my question: " + '\n ' + str (
1488+ message = 'This is database related information: ' + '\n ' + self .base_message + '\n ' + " This is my question: " + '\n ' + str (
15181489 q_str ),
15191490 )
15201491
@@ -1565,8 +1536,8 @@ async def task_generate_report1108(self, qustion_message):
15651536 analyst ,
15661537 message = str (
15671538 answer_contents ) + '\n ' + " 以下是我的问题,请用中文回答: " + '\n ' + " 1,本次生成哪些报表?简单描述一下各报表 "
1568- + '\n ' + " 以下是一个回答案例: " + '\n ' +
1569- """总结:
1539+ + '\n ' + " 以下是一个回答案例: " + '\n ' +
1540+ """总结:
15701541 -- Monthly Sales Summary Q1 2019: 同名图表历史已生成过,此次不再生成,若要重新生成图表,请先删除已有同名报表。2019年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
15711542 -- Summary Q1 2018: 生成成功。2018年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
15721543 """ ,
@@ -1598,7 +1569,7 @@ async def task_generate_report1108(self, qustion_message):
15981569 return "报表生成失败,请检查相关数据是否充分。"
15991570
16001571 async def task_analysis_data (self , qustion_message ):
1601- """ 任务类型2: 数据分析 """
1572+ """ 任务类型2: 数据分析 """
16021573 try :
16031574 base_content = []
16041575 report_demand_list = []
@@ -1752,7 +1723,7 @@ async def task_analysis_data(self, qustion_message):
17521723 return "分析数据失败,请检查相关数据是否充分。"
17531724
17541725 async def task_delete_chart (self , qustion_message ):
1755- """ 任务类型3: 删除图表 """
1726+ """ 任务类型3: 删除图表 """
17561727 print ('运行 【task_delete_chart】函数' )
17571728 logger .info ("from user:[{}" .format (self .user_name ) + "] , " + "运行 【task_delete_chart】函数" )
17581729
@@ -1823,7 +1794,7 @@ async def task_delete_chart(self, qustion_message):
18231794 return "删除图表失败。 请检查提供的图表列表格式是否正确以及图表名称是否存在。"
18241795
18251796 async def task_chart_img (self , qustion_message ):
1826- """ 任务类型: 使用 matplotlib 生成图表图片,暂时停用 """
1797+ """ 任务类型: 使用 matplotlib 生成图表图片,暂时停用 """
18271798 try :
18281799
18291800 base_content = []
0 commit comments