diff --git a/utils/agent.py b/utils/agent.py index c12fdb18..4e912758 100644 --- a/utils/agent.py +++ b/utils/agent.py @@ -517,8 +517,23 @@ def check_json(json_data): json_data += '"}' return json_data +def get_date_time_weekday(): + import datetime + + now = datetime.datetime.now() + weekday = now.weekday() + weekday_str = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'][weekday] + return "今天是:" + str(now.date()) + ",现在的时间是:" + str(now.time()) + "," + weekday_str + +def get_version_info(): + import subprocess + result = subprocess.run(['git', 'log', '-1'], stdout=subprocess.PIPE) + output = result.stdout.decode() + return output + if __name__ == "__main__": os.system("clear") + print(get_version_info()) # from langchain.agents import get_all_tool_names # print(get_all_tool_names()) diff --git a/utils/chatgpt2api.py b/utils/chatgpt2api.py index 7b371a59..d02b2760 100644 --- a/utils/chatgpt2api.py +++ b/utils/chatgpt2api.py @@ -13,7 +13,7 @@ from typing import Set import config -from utils.agent import Web_crawler, get_search_results, cut_message, get_url_text_list, get_text_token_len, check_json +from utils.agent import Web_crawler, get_search_results, cut_message, get_url_text_list, get_text_token_len, check_json, get_date_time_weekday, get_version_info from utils.function_call import function_call_list def get_filtered_keys_from_object(obj: object, *keys: str) -> Set[str]: @@ -200,8 +200,6 @@ def ask_stream( # print(repr(self.conversation.Conversation(convo_id))) # print("total tokens:", self.get_token_count(convo_id)) - - class Imagebot: def __init__( self, @@ -510,6 +508,8 @@ def get_post_body( if config.SEARCH_USE_GPT: json_post_body["functions"].append(function_call_list["web_search"]) json_post_body["functions"].append(function_call_list["url_fetch"]) + json_post_body["functions"].append(function_call_list["today"]) + json_post_body["functions"].append(function_call_list["vresion"]) return json_post_body @@ -637,6 +637,12 @@ def ask_stream( print("\n\nurl", url) function_response = Web_crawler(url) function_response, text_len = cut_message(function_response, function_call_max_tokens) + if function_call_name == "get_date_time_weekday": + function_response = eval(function_call_name)() + function_response, text_len = cut_message(function_response, function_call_max_tokens) + if function_call_name == "get_version_info": + function_response = eval(function_call_name)() + function_response, text_len = cut_message(function_response, function_call_max_tokens) else: function_response = "抱歉,直接告诉用户,无法找到相关信息" response_role = "function" diff --git a/utils/function_call.py b/utils/function_call.py index 010a8e30..312e6ca7 100644 --- a/utils/function_call.py +++ b/utils/function_call.py @@ -1,53 +1,70 @@ -function_call_list = { - "base": { - "functions": [], - "function_call": "auto" - }, - "current_weather": { - "name": "get_current_weather", - "description": "Get the current weather in a given location", - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city and state, e.g. San Francisco, CA" - }, - "unit": { - "type": "string", - "enum": ["celsius", "fahrenheit"] +function_call_list = \ +{ + "base": { + "functions": [], + "function_call": "auto" + }, + "current_weather": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA" + }, + "unit": { + "type": "string", + "enum": [ + "celsius", + "fahrenheit" + ] + } + }, + "required": [ + "location" + ] } - }, - "required": ["location"] - } - }, - "web_search": { - "name": "get_search_results", - "description": "Search Google to enhance knowledge.", - "parameters": { - "type": "object", - "properties": { - "prompt": { - "type": "string", - "description": "The prompt to search." + }, + "web_search": { + "name": "get_search_results", + "description": "Search Google to enhance knowledge.", + "parameters": { + "type": "object", + "properties": { + "prompt": { + "type": "string", + "description": "The prompt to search." + } + }, + "required": [ + "prompt" + ] } - }, - "required": ["prompt"] - } - }, - "url_fetch": { - "name": "get_url_content", - "description": "Get the webpage content of a URL", - "parameters": { - "type": "object", - "properties": { - "url": { - "type": "string", - "description": "the URL to request" + }, + "url_fetch": { + "name": "get_url_content", + "description": "Get the webpage content of a URL", + "parameters": { + "type": "object", + "properties": { + "url": { + "type": "string", + "description": "the URL to request" + } + }, + "required": [ + "url" + ] } - }, - "required": ["url"] - } - }, -} - + }, + "today": { + "name": "get_date_time_weekday", + "description": "Get the current time, date, and day of the week" + }, + "vresion": { + "name": "get_version_info", + "description": "Get version information" + }, +} \ No newline at end of file