diff --git a/ai/agents/agent_instance_util.py b/ai/agents/agent_instance_util.py index 34d591b3..60c471d6 100644 --- a/ai/agents/agent_instance_util.py +++ b/ai/agents/agent_instance_util.py @@ -60,7 +60,6 @@ def __init__( self.openai_proxy = None self.db_id = db_id - def set_api_key(self, api_key, ApiType="openai", api_host=None, ApiModel=None, LlmSetting=None): self.api_key = api_key if api_host is not None: @@ -381,7 +380,6 @@ def get_agent_mongodb_engineer(self): """ return mongodb_engineer - def get_agent_chart_presenter_old(self): """chart designer""" chart_llm_config = { @@ -819,7 +817,6 @@ def get_agent_task_selector(self): return task_selector def get_agent_task_planner(self): - """ Make plans for tasks and assign tasks to other agents step by step """ task_planner = TaskPlannerAgent( name="task_planner", @@ -1377,8 +1374,8 @@ async def task_generate_report(self, qustion_message): analyst, message=str( answer_contents) + '\n' + " 以下是我的问题,请用中文回答: " + '\n' + " 1,本次生成哪些报表?简单描述一下各报表 " - + '\n' + " 以下是一个回答案例: " + '\n' + - """总结: + + '\n' + " 以下是一个回答案例: " + '\n' + + """总结: -- Monthly Sales Summary Q1 2019: 同名图表历史已生成过,此次不再生成,若要重新生成图表,请先删除已有同名报表。2019年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息. -- Summary Q1 2018: 生成成功。2018年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息. """, @@ -1536,8 +1533,8 @@ async def task_generate_report1108(self, qustion_message): analyst, message=str( answer_contents) + '\n' + " 以下是我的问题,请用中文回答: " + '\n' + " 1,本次生成哪些报表?简单描述一下各报表 " - + '\n' + " 以下是一个回答案例: " + '\n' + - """总结: + + '\n' + " 以下是一个回答案例: " + '\n' + + """总结: -- Monthly Sales Summary Q1 2019: 同名图表历史已生成过,此次不再生成,若要重新生成图表,请先删除已有同名报表。2019年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息. -- Summary Q1 2018: 生成成功。2018年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息. """, diff --git a/ai/agents/oai/completion.py b/ai/agents/oai/completion.py index 2e442030..e6d99b47 100644 --- a/ai/agents/oai/completion.py +++ b/ai/agents/oai/completion.py @@ -214,7 +214,7 @@ def _get_response(cls, config: Dict, raise_on_ratelimit_or_timeout=False, use_ca other_llm_name = AGENT_LLM_MODEL[agent_name]['llm'] if agent_name in AGENT_LLM_MODEL and \ AGENT_LLM_MODEL[agent_name][ 'replace_default'] and llm_setting is not None else use_llm_name - use_api_secret = llm_setting[use_llm_name]['ApiSecret'] if "ApiSecret" in llm_setting[use_llm_name] else None + use_api_secret = llm_setting[use_llm_name]['ApiSecret'] if llm_setting and "ApiSecret" in llm_setting[use_llm_name] else None print("Agent_name", agent_name, 'default: llm:', use_llm_name, "url:", use_url, "model", use_model, "other LLM", other_llm_name) if other_llm_name is not None and use_llm_name != other_llm_name: 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 del config['agent_name'] if "api_type" in config: del config['api_type'] + + tools = [] + if "functions" in config: + functions = config.pop("functions") + for function in functions: + tools.append({ + "type": "function", + "function": function + }) + if len(tools) > 0: + config['tools'] = tools + openai_completion = ( openai.ChatCompletion 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 response = openai_completion.create(**config) else: response = openai_completion.create(request_timeout=request_timeout, **config) + if "tool_calls" in response.choices[0].message and len(response.choices[0].message.tool_calls) > 0: + tool_calls = response.choices[0].message.pop("tool_calls") + function_call = tool_calls[0] + response.choices[0].message['function_call'] = { + "name": function_call.function.name, + "arguments": function_call.function.arguments + } + response.choices[0]['finish_reason'] = "function_call" except ( ServiceUnavailableError, diff --git a/bi/__init__.py b/bi/__init__.py index 86ec4ddc..37d59a1d 100644 --- a/bi/__init__.py +++ b/bi/__init__.py @@ -15,8 +15,8 @@ from .query_runner import import_query_runners from .destinations import import_destinations -__version__ = "2.0.1" -__DeepBI_version__ = "2.0.1" +__version__ = "2.0.2" +__DeepBI_version__ = "2.0.2" def setup_logging(): diff --git a/version.md b/version.md index bd652a05..1b877177 100644 --- a/version.md +++ b/version.md @@ -1,4 +1,7 @@ # Version +### 2.0.2 +- Adapt an existing function call to the new openai version of tools + ### 2.0.1 - Add support LLM configurations,including BaiduQianfan、AliBailian