Skip to content

Commit

Permalink
Merge pull request #143 from DeepInsight-AI/new_pre
Browse files Browse the repository at this point in the history
Modify an adaptation problem
  • Loading branch information
lichengxin9527 authored Jun 14, 2024
2 parents 3d559ee + 171b684 commit 0064902
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
11 changes: 4 additions & 7 deletions ai/agents/agent_instance_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
""",
Expand Down Expand Up @@ -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年第一季度的月度销售总结。它包括了每个月的总销售额、利润和订单数量的详细信息.
""",
Expand Down
22 changes: 21 additions & 1 deletion ai/agents/oai/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions bi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 3 additions & 0 deletions version.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 0064902

Please sign in to comment.