Skip to content

Commit 0064902

Browse files
Merge pull request #143 from DeepInsight-AI/new_pre
Modify an adaptation problem
2 parents 3d559ee + 171b684 commit 0064902

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

ai/agents/agent_instance_util.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def __init__(
6060
self.openai_proxy = None
6161
self.db_id = db_id
6262

63-
6463
def set_api_key(self, api_key, ApiType="openai", api_host=None, ApiModel=None, LlmSetting=None):
6564
self.api_key = api_key
6665
if api_host is not None:
@@ -381,7 +380,6 @@ def get_agent_mongodb_engineer(self):
381380
"""
382381
return mongodb_engineer
383382

384-
385383
def get_agent_chart_presenter_old(self):
386384
"""chart designer"""
387385
chart_llm_config = {
@@ -819,7 +817,6 @@ def get_agent_task_selector(self):
819817
return task_selector
820818

821819
def get_agent_task_planner(self):
822-
823820
""" Make plans for tasks and assign tasks to other agents step by step """
824821
task_planner = TaskPlannerAgent(
825822
name="task_planner",
@@ -1377,8 +1374,8 @@ async def task_generate_report(self, qustion_message):
13771374
analyst,
13781375
message=str(
13791376
answer_contents) + '\n' + " 以下是我的问题,请用中文回答: " + '\n' + " 1,本次生成哪些报表?简单描述一下各报表 "
1380-
+ '\n' + " 以下是一个回答案例: " + '\n' +
1381-
"""总结:
1377+
+ '\n' + " 以下是一个回答案例: " + '\n' +
1378+
"""总结:
13821379
-- Monthly Sales Summary Q1 2019: 同名图表历史已生成过,此次不再生成,若要重新生成图表,请先删除已有同名报表。2019年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
13831380
-- Summary Q1 2018: 生成成功。2018年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
13841381
""",
@@ -1536,8 +1533,8 @@ async def task_generate_report1108(self, qustion_message):
15361533
analyst,
15371534
message=str(
15381535
answer_contents) + '\n' + " 以下是我的问题,请用中文回答: " + '\n' + " 1,本次生成哪些报表?简单描述一下各报表 "
1539-
+ '\n' + " 以下是一个回答案例: " + '\n' +
1540-
"""总结:
1536+
+ '\n' + " 以下是一个回答案例: " + '\n' +
1537+
"""总结:
15411538
-- Monthly Sales Summary Q1 2019: 同名图表历史已生成过,此次不再生成,若要重新生成图表,请先删除已有同名报表。2019年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
15421539
-- Summary Q1 2018: 生成成功。2018年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
15431540
""",

ai/agents/oai/completion.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def _get_response(cls, config: Dict, raise_on_ratelimit_or_timeout=False, use_ca
214214
other_llm_name = AGENT_LLM_MODEL[agent_name]['llm'] if agent_name in AGENT_LLM_MODEL and \
215215
AGENT_LLM_MODEL[agent_name][
216216
'replace_default'] and llm_setting is not None else use_llm_name
217-
use_api_secret = llm_setting[use_llm_name]['ApiSecret'] if "ApiSecret" in llm_setting[use_llm_name] else None
217+
use_api_secret = llm_setting[use_llm_name]['ApiSecret'] if llm_setting and "ApiSecret" in llm_setting[use_llm_name] else None
218218
print("Agent_name", agent_name, 'default: llm:', use_llm_name, "url:", use_url, "model", use_model, "other LLM", other_llm_name)
219219
if other_llm_name is not None and use_llm_name != other_llm_name:
220220
use_message_count = AGENT_LLM_MODEL[agent_name]['use_message_count']
@@ -303,6 +303,18 @@ def _get_response(cls, config: Dict, raise_on_ratelimit_or_timeout=False, use_ca
303303
del config['agent_name']
304304
if "api_type" in config:
305305
del config['api_type']
306+
307+
tools = []
308+
if "functions" in config:
309+
functions = config.pop("functions")
310+
for function in functions:
311+
tools.append({
312+
"type": "function",
313+
"function": function
314+
})
315+
if len(tools) > 0:
316+
config['tools'] = tools
317+
306318
openai_completion = (
307319
openai.ChatCompletion
308320
if config["model"].replace("gpt-35-turbo", "gpt-3.5-turbo") in cls.chat_models
@@ -313,6 +325,14 @@ def _get_response(cls, config: Dict, raise_on_ratelimit_or_timeout=False, use_ca
313325
response = openai_completion.create(**config)
314326
else:
315327
response = openai_completion.create(request_timeout=request_timeout, **config)
328+
if "tool_calls" in response.choices[0].message and len(response.choices[0].message.tool_calls) > 0:
329+
tool_calls = response.choices[0].message.pop("tool_calls")
330+
function_call = tool_calls[0]
331+
response.choices[0].message['function_call'] = {
332+
"name": function_call.function.name,
333+
"arguments": function_call.function.arguments
334+
}
335+
response.choices[0]['finish_reason'] = "function_call"
316336

317337
except (
318338
ServiceUnavailableError,

bi/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from .query_runner import import_query_runners
1616
from .destinations import import_destinations
1717

18-
__version__ = "2.0.1"
19-
__DeepBI_version__ = "2.0.1"
18+
__version__ = "2.0.2"
19+
__DeepBI_version__ = "2.0.2"
2020

2121

2222
def setup_logging():

version.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Version
2+
### 2.0.2
3+
- Adapt an existing function call to the new openai version of tools
4+
25
### 2.0.1
36
- Add support LLM configurations,including BaiduQianfan、AliBailian
47

0 commit comments

Comments
 (0)