pycoze 0.1.238__py3-none-any.whl → 0.1.240__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pycoze/bot/agent/agent_types/openai_func_call_agent.py +1 -45
- pycoze/bot/agent_chat.py +6 -11
- {pycoze-0.1.238.dist-info → pycoze-0.1.240.dist-info}/METADATA +1 -1
- {pycoze-0.1.238.dist-info → pycoze-0.1.240.dist-info}/RECORD +7 -10
- pycoze/automation/__init__.py +0 -0
- pycoze/automation/browser/__init__.py +0 -0
- pycoze/automation/browser/edge_driver_manager.py +0 -77
- {pycoze-0.1.238.dist-info → pycoze-0.1.240.dist-info}/LICENSE +0 -0
- {pycoze-0.1.238.dist-info → pycoze-0.1.240.dist-info}/WHEEL +0 -0
- {pycoze-0.1.238.dist-info → pycoze-0.1.240.dist-info}/top_level.txt +0 -0
@@ -34,41 +34,7 @@ def get_tools(last_message):
|
|
34
34
|
if "tool_calls" in last_message.additional_kwargs:
|
35
35
|
return last_message.additional_kwargs["tool_calls"]
|
36
36
|
else:
|
37
|
-
|
38
|
-
# if '"name"' in last_message.content and '"parameters":' in last_message.content:
|
39
|
-
# print("name 和 paremeters 模式")
|
40
|
-
# all_json = get_all_markdown_json(last_message.content)
|
41
|
-
# tool_calls = []
|
42
|
-
# for tool_call in all_json:
|
43
|
-
# if "name" not in tool_call or "parameters" not in tool_call:
|
44
|
-
# return "end"
|
45
|
-
# tool_call["arguments"] = json.dumps(tool_call["parameters"])
|
46
|
-
# tool_call.pop("parameters")
|
47
|
-
# tool_calls.append(
|
48
|
-
# {
|
49
|
-
# "function": tool_call,
|
50
|
-
# "id": random.randint(0, 1000000),
|
51
|
-
# }
|
52
|
-
# )
|
53
|
-
# if "<|tool▁sep|>" in last_message.content:
|
54
|
-
# print("deepseek的bug: <|tool▁sep|> 模式")
|
55
|
-
# name = (
|
56
|
-
# last_message.content.split("<|tool▁sep|>")[1].split("```")[0].strip()
|
57
|
-
# )
|
58
|
-
# all_json = get_all_markdown_json(last_message.content)
|
59
|
-
# tool_calls = []
|
60
|
-
# for argument in all_json:
|
61
|
-
# tool_calls.append(
|
62
|
-
# {
|
63
|
-
# "function": {
|
64
|
-
# "name": name,
|
65
|
-
# "arguments": json.dumps(argument),
|
66
|
-
# },
|
67
|
-
# "id": random.randint(0, 1000000),
|
68
|
-
# }
|
69
|
-
# )
|
70
|
-
|
71
|
-
return tool_calls
|
37
|
+
return None
|
72
38
|
|
73
39
|
|
74
40
|
def create_openai_func_call_agent_executor(
|
@@ -109,8 +75,6 @@ def create_openai_func_call_agent_executor(
|
|
109
75
|
return 'continue'
|
110
76
|
return 'end'
|
111
77
|
|
112
|
-
|
113
|
-
|
114
78
|
# Define the function to execute tools
|
115
79
|
async def call_tool(messages):
|
116
80
|
actions: list[ToolInvocation] = []
|
@@ -120,14 +84,6 @@ def create_openai_func_call_agent_executor(
|
|
120
84
|
for tool_call in get_tools(last_message):
|
121
85
|
function = tool_call["function"]
|
122
86
|
function_name = function["name"]
|
123
|
-
if function_name == "a_delay_function":
|
124
|
-
return [
|
125
|
-
ToolMessage(
|
126
|
-
tool_call_id=tool_call["id"],
|
127
|
-
content="a_delay_function只是一个占位符,请忽略重新调用工具",
|
128
|
-
additional_kwargs={"name": tool_call["function"]["name"]},
|
129
|
-
)
|
130
|
-
]
|
131
87
|
|
132
88
|
_tool_input = json.loads(function["arguments"] or "{}")
|
133
89
|
# We construct an ToolInvocation from the function_call
|
pycoze/bot/agent_chat.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
import json
|
2
2
|
from langchain_openai import ChatOpenAI
|
3
|
-
from .agent import run_agent, Runnable,
|
3
|
+
from .agent import run_agent, Runnable, CHAT_DATA, clear_chat_data
|
4
4
|
import asyncio
|
5
5
|
from pycoze import utils
|
6
6
|
from pycoze.reference.bot import ref_bot
|
7
7
|
from pycoze.reference.tool import ref_tools
|
8
8
|
from pycoze.reference.workflow import ref_workflow
|
9
|
-
from langchain_core.utils.function_calling import convert_to_openai_tool
|
10
9
|
import os
|
11
10
|
|
12
11
|
cfg = utils.read_json_file("llm.json")
|
@@ -75,15 +74,11 @@ async def agent_chat(bot_setting_file, history):
|
|
75
74
|
api_key=cfg["apiKey"],
|
76
75
|
base_url=cfg["baseURL"],
|
77
76
|
model=cfg["model"],
|
78
|
-
temperature=(
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
stop_sequences=[
|
84
|
-
"tool▁calls▁end",
|
85
|
-
"tool▁call▁end",
|
86
|
-
], # 停用deepseek的工具调用标记,不然会虚构工具调用过程和结果
|
77
|
+
temperature=(role_setting["temperature"]),
|
78
|
+
# stop_sequences=[
|
79
|
+
# "tool▁calls▁end",
|
80
|
+
# "tool▁call▁end",
|
81
|
+
# ], # 停用deepseek的工具调用标记,不然会虚构工具调用过程和结果
|
87
82
|
)
|
88
83
|
prompt = role_setting["prompt"]
|
89
84
|
|
@@ -5,11 +5,8 @@ pycoze/ai/llm/__init__.py,sha256=kAXcQ7SefJYysgKeVInlwYZoDk0BPuEnUuixy-quD_A,127
|
|
5
5
|
pycoze/ai/llm/chat.py,sha256=izriC7nCp5qeJRqcUVQBVqTHiH6MJS77ROzGBJufdNI,5133
|
6
6
|
pycoze/ai/llm/text_to_image_prompt.py,sha256=0bx2C_YRvjAo7iphHGp1-pmGKsKqwur7dM0t3SiA8kA,3398
|
7
7
|
pycoze/ai/llm/think.py,sha256=sUgTBdGzcZtL3r-Wx8M3lDuVUmDVz8g3qC0VU8uiKAI,5143
|
8
|
-
pycoze/automation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
pycoze/automation/browser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
pycoze/automation/browser/edge_driver_manager.py,sha256=gpgseunph5owZH6EskSYthuhey2SU3UP204gY0yIcuI,3022
|
11
8
|
pycoze/bot/__init__.py,sha256=6HHMxDQVOyZM9dtSjQm9tjGnhj4h7CixD0JOvEwTi48,41
|
12
|
-
pycoze/bot/agent_chat.py,sha256=
|
9
|
+
pycoze/bot/agent_chat.py,sha256=Lj7YWG0TrCmdyETnV_NlFL6X6HPkRHEjD3wTFKJah9o,3356
|
13
10
|
pycoze/bot/bot.py,sha256=_qmUTZ09FmRLifHrW5stDZWGVK6yuMEMBC3fmeYJnqk,844
|
14
11
|
pycoze/bot/agent/__init__.py,sha256=3wE8_FFQS8j2BY-g9Cr-onV0POEvDRZaw_NCzpqrNus,265
|
15
12
|
pycoze/bot/agent/agent.py,sha256=iZzvem9_NyFyfu1uvnCxS89SNo2O4Qx1n3CxMIrIy0A,3447
|
@@ -17,7 +14,7 @@ pycoze/bot/agent/assistant.py,sha256=s1y_gR_9UK_jzjX6YztXK5JNhnV-_YvUA6vv1lToS-k
|
|
17
14
|
pycoze/bot/agent/chat.py,sha256=mubOCAHvA6VtyE6N40elI6KrP6A69uB_G6ihE3G_Vi4,860
|
18
15
|
pycoze/bot/agent/agent_types/__init__.py,sha256=zmU2Kmrv5mCdfg-QlPn2H6pWxbGeq8s7YTqLhpzJC6k,179
|
19
16
|
pycoze/bot/agent/agent_types/const.py,sha256=BfUKPrhAHREoMLHuFNG2bCIEkC1-f7K0LEqNg4RwiRE,70
|
20
|
-
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=
|
17
|
+
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=_R42UdImIjeOJdiiRghRn9A5Cjse9fX3OQTGFNHPr_E,4575
|
21
18
|
pycoze/reference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
22
19
|
pycoze/reference/bot.py,sha256=BDflTV3zYoZqWnJpD5lMM_1vU_5b20M3XiFt1p-RHWM,2427
|
23
20
|
pycoze/reference/lib.py,sha256=0xQJTLTHedGzQBsjuTFNBVqYc4-8Yl65gGCrAhWyOX8,2155
|
@@ -32,8 +29,8 @@ pycoze/utils/__init__.py,sha256=Gi5EnrWZGMD2JRejgV4c_VLCXyvA2wwBFI_niDF5MUE,110
|
|
32
29
|
pycoze/utils/arg.py,sha256=GtfGbMTMdaK75Fwh6MpUe1pCA5X6Ep4LFG7a72YrzjI,525
|
33
30
|
pycoze/utils/env.py,sha256=W04lhvTHhAAC6EldP6kk2xrctqtu8K6kl1vDLZDNeh8,561
|
34
31
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
35
|
-
pycoze-0.1.
|
36
|
-
pycoze-0.1.
|
37
|
-
pycoze-0.1.
|
38
|
-
pycoze-0.1.
|
39
|
-
pycoze-0.1.
|
32
|
+
pycoze-0.1.240.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
33
|
+
pycoze-0.1.240.dist-info/METADATA,sha256=HUZlCIs52nql_SLc8f5mCsiBNQVzX3rzXR5I8Dy45fo,699
|
34
|
+
pycoze-0.1.240.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
35
|
+
pycoze-0.1.240.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
36
|
+
pycoze-0.1.240.dist-info/RECORD,,
|
pycoze/automation/__init__.py
DELETED
File without changes
|
File without changes
|
@@ -1,77 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import requests
|
3
|
-
from selenium.webdriver.edge.service import Service
|
4
|
-
from webdriver_manager.microsoft import EdgeChromiumDriverManager
|
5
|
-
from selenium import webdriver
|
6
|
-
|
7
|
-
|
8
|
-
# Function to check network availability
|
9
|
-
def is_network_available():
|
10
|
-
try:
|
11
|
-
# Attempt to access the download URL for Edge Chromium driver to check network connection
|
12
|
-
response = requests.get("https://msedgedriver.azureedge.net/", timeout=3)
|
13
|
-
return response.status_code == 200
|
14
|
-
except requests.ConnectionError:
|
15
|
-
return False
|
16
|
-
|
17
|
-
|
18
|
-
# Function to get the default download path for Edge Chromium driver
|
19
|
-
def get_default_driver_path():
|
20
|
-
manager = EdgeChromiumDriverManager()
|
21
|
-
return manager.install()
|
22
|
-
|
23
|
-
|
24
|
-
# Function to get the driver version from cache
|
25
|
-
def get_cached_driver_version(manager):
|
26
|
-
cache_dir = manager._cache_manager._root_dir # Get the root path of the cache directory
|
27
|
-
os_type = manager._os_system_manager.get_os_type() # Get the OS type
|
28
|
-
driver_name = manager.driver.get_name()
|
29
|
-
|
30
|
-
# List all versions in the cache directory
|
31
|
-
versions_dir = os.path.join(cache_dir, "drivers", driver_name, os_type)
|
32
|
-
if os.path.exists(versions_dir):
|
33
|
-
versions = os.listdir(versions_dir)
|
34
|
-
if versions:
|
35
|
-
# Return the latest version found in the cache
|
36
|
-
return max(versions)
|
37
|
-
return None
|
38
|
-
|
39
|
-
|
40
|
-
# Function to check if the driver has already been downloaded
|
41
|
-
def get_driver_path():
|
42
|
-
network_available = is_network_available()
|
43
|
-
print("Network status:", "Available" if network_available else "Unavailable")
|
44
|
-
manager = EdgeChromiumDriverManager()
|
45
|
-
if network_available:
|
46
|
-
return get_default_driver_path()
|
47
|
-
else:
|
48
|
-
# If no network, check the cache directory
|
49
|
-
driver_version = get_cached_driver_version(manager)
|
50
|
-
if driver_version:
|
51
|
-
driver_name = manager.driver.get_name()
|
52
|
-
os_type = manager._os_system_manager.get_os_type()
|
53
|
-
cache_dir = manager._cache_manager._root_dir
|
54
|
-
|
55
|
-
# Determine the correct driver filename based on the OS
|
56
|
-
if os.name == 'nt': # Windows
|
57
|
-
driver_filename = "msedgedriver.exe"
|
58
|
-
else: # macOS and Linux
|
59
|
-
driver_filename = "msedgedriver"
|
60
|
-
|
61
|
-
# Construct the driver path
|
62
|
-
driver_path = os.path.join(cache_dir, "drivers", driver_name, os_type, driver_version, driver_filename)
|
63
|
-
# Check if the driver path exists
|
64
|
-
if os.path.exists(driver_path):
|
65
|
-
return driver_path
|
66
|
-
raise Exception("Network unavailable and no downloaded driver found")
|
67
|
-
|
68
|
-
|
69
|
-
# Function to get the Edge driver service
|
70
|
-
def get_edge_driver_service():
|
71
|
-
driver_path = get_driver_path()
|
72
|
-
print("driver_path", driver_path)
|
73
|
-
# Check if the driver path exists
|
74
|
-
if os.path.exists(driver_path):
|
75
|
-
return Service(driver_path)
|
76
|
-
else:
|
77
|
-
raise Exception("Network unavailable and no downloaded driver found")
|
File without changes
|
File without changes
|
File without changes
|