pycoze 0.1.148__tar.gz → 0.1.150__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {pycoze-0.1.148 → pycoze-0.1.150}/PKG-INFO +1 -1
- pycoze-0.1.148/pycoze/bot/bot.py → pycoze-0.1.150/pycoze/bot/agent_chat.py +78 -97
- pycoze-0.1.150/pycoze/bot/bot.py +21 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/reference/lib.py +3 -1
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze.egg-info/PKG-INFO +1 -1
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze.egg-info/SOURCES.txt +1 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/setup.py +1 -1
- {pycoze-0.1.148 → pycoze-0.1.150}/LICENSE +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/README.md +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/__init__.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/ai/__init__.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/ai/vram_reserve.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/bot/__init__.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/bot/agent/__init__.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/bot/agent/agent.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/bot/agent/agent_types/__init__.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/bot/agent/agent_types/const.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/bot/agent/assistant.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/bot/agent/chat.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/module.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/reference/__init__.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/reference/bot.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/reference/tool.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/ui/__init__.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/ui/base.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/ui/color.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/ui/typ.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/ui/ui_def.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/utils/__init__.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/utils/arg.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze/utils/text_or_file.py +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze.egg-info/dependency_links.txt +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/pycoze.egg-info/top_level.txt +0 -0
- {pycoze-0.1.148 → pycoze-0.1.150}/setup.cfg +0 -0
@@ -1,97 +1,78 @@
|
|
1
|
-
import json
|
2
|
-
from langchain_openai import ChatOpenAI
|
3
|
-
from .agent import run_agent, Runnable
|
4
|
-
import asyncio
|
5
|
-
from
|
6
|
-
from pycoze import
|
7
|
-
from pycoze.reference.
|
8
|
-
from
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
llm_file =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
bot
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
"tool▁
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
"""
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
)
|
79
|
-
return asyncio.run(run_agent(agent, history, cfg["toolCompatibilityMode"]))
|
80
|
-
|
81
|
-
|
82
|
-
def chat(bot_setting_file: str):
|
83
|
-
history = []
|
84
|
-
while True:
|
85
|
-
input_text = input()
|
86
|
-
if not input_text.startswith(INPUT_MESSAGE):
|
87
|
-
raise ValueError("Invalid message")
|
88
|
-
message = json.loads(input_text[len(INPUT_MESSAGE) :])
|
89
|
-
history.append(HumanMessage(message["content"]))
|
90
|
-
result = agent_chat(bot_setting_file, history)
|
91
|
-
history.append(output("assistant", result))
|
92
|
-
|
93
|
-
|
94
|
-
def get_chat_response(bot_setting_file: str, input_text: str):
|
95
|
-
history = [HumanMessage(input_text)]
|
96
|
-
result = agent_chat(bot_setting_file, history)
|
97
|
-
return result
|
1
|
+
import json
|
2
|
+
from langchain_openai import ChatOpenAI
|
3
|
+
from .agent import run_agent, Runnable
|
4
|
+
import asyncio
|
5
|
+
from pycoze import utils
|
6
|
+
from pycoze.reference.bot import ref_bot
|
7
|
+
from pycoze.reference.tool import ref_tools
|
8
|
+
from langchain_core.utils.function_calling import convert_to_openai_tool
|
9
|
+
|
10
|
+
params = utils.arg.read_params_file()
|
11
|
+
llm_file = params["appPath"] + "/JsonStorage/llm.json"
|
12
|
+
with open(llm_file, "r", encoding="utf-8") as f:
|
13
|
+
cfg = json.load(f)
|
14
|
+
|
15
|
+
|
16
|
+
def load_role_setting(bot_setting_file: str):
|
17
|
+
with open(bot_setting_file, "r", encoding="utf-8") as f:
|
18
|
+
return json.load(f)
|
19
|
+
|
20
|
+
|
21
|
+
def load_abilities(bot_setting_file: str):
|
22
|
+
with open(bot_setting_file, "r", encoding="utf-8") as f:
|
23
|
+
role_setting = json.load(f)
|
24
|
+
|
25
|
+
abilities = []
|
26
|
+
for bot_id in role_setting["bots"]:
|
27
|
+
bot = ref_bot(bot_id, as_agent_tool=True)
|
28
|
+
if bot:
|
29
|
+
abilities.append(bot)
|
30
|
+
for tool_id in role_setting["tools"]:
|
31
|
+
abilities.extend(ref_tools(tool_id, as_agent_tool=True))
|
32
|
+
return abilities
|
33
|
+
|
34
|
+
|
35
|
+
def agent_chat(bot_setting_file, history):
|
36
|
+
role_setting = load_role_setting(bot_setting_file)
|
37
|
+
abilities = load_abilities(bot_setting_file)
|
38
|
+
|
39
|
+
chat = ChatOpenAI(
|
40
|
+
api_key=cfg["apiKey"],
|
41
|
+
base_url=cfg["baseURL"],
|
42
|
+
model=cfg["model"],
|
43
|
+
temperature=(
|
44
|
+
role_setting["temperature"] * 2
|
45
|
+
if cfg["model"].startswith("deepseek")
|
46
|
+
else role_setting["temperature"]
|
47
|
+
),
|
48
|
+
stop_sequences=[
|
49
|
+
"tool▁calls▁end",
|
50
|
+
"tool▁call▁end",
|
51
|
+
], # 停用deepseek的工具调用标记,不然会虚构工具调用过程和结果
|
52
|
+
)
|
53
|
+
prompt = role_setting["prompt"]
|
54
|
+
if (
|
55
|
+
(cfg["model"].startswith("deepseek")
|
56
|
+
or cfg["toolCompatibilityMode"])
|
57
|
+
and len(abilities) > 0
|
58
|
+
):
|
59
|
+
prompt += """
|
60
|
+
作为一个AI,你如果不确定结果,请务必使用工具查询。
|
61
|
+
你可以通过下面的方式使用工具,并耐心等待工具返回结果。
|
62
|
+
如果你需要调用工具,请使用以正确markdown中的json代码格式进行结尾(务必保证json格式正确,不要出现反斜杠未转义等问题):
|
63
|
+
```json
|
64
|
+
{"name": 函数名, "parameters": 参数词典}
|
65
|
+
```
|
66
|
+
"""
|
67
|
+
if cfg["model"].startswith("yi-"):
|
68
|
+
prompt += "\nAvailable functions:\n"
|
69
|
+
for t in abilities:
|
70
|
+
prompt += f"\n```json\n{json.dumps(convert_to_openai_tool(t))}\n```"
|
71
|
+
agent = Runnable(
|
72
|
+
agent_execution_mode="FuncCall",
|
73
|
+
tools=abilities,
|
74
|
+
llm=chat,
|
75
|
+
assistant_message=prompt,
|
76
|
+
tool_compatibility_mode=cfg["toolCompatibilityMode"],
|
77
|
+
)
|
78
|
+
return asyncio.run(run_agent(agent, history, cfg["toolCompatibilityMode"]))
|
@@ -0,0 +1,21 @@
|
|
1
|
+
from langchain_core.messages import HumanMessage
|
2
|
+
from .agent import INPUT_MESSAGE, output
|
3
|
+
from .agent_chat import agent_chat
|
4
|
+
|
5
|
+
|
6
|
+
def chat(bot_setting_file: str):
|
7
|
+
history = []
|
8
|
+
while True:
|
9
|
+
input_text = input()
|
10
|
+
if not input_text.startswith(INPUT_MESSAGE):
|
11
|
+
raise ValueError("Invalid message")
|
12
|
+
message = json.loads(input_text[len(INPUT_MESSAGE) :])
|
13
|
+
history.append(HumanMessage(message["content"]))
|
14
|
+
result = agent_chat(bot_setting_file, history)
|
15
|
+
history.append(output("assistant", result))
|
16
|
+
|
17
|
+
|
18
|
+
def get_chat_response(bot_setting_file: str, input_text: str):
|
19
|
+
history = [HumanMessage(input_text)]
|
20
|
+
result = agent_chat(bot_setting_file, history)
|
21
|
+
return result
|
@@ -59,7 +59,9 @@ def wrapped_func(item, module_path):
|
|
59
59
|
with ChangeDirectoryAndPath(module_path):
|
60
60
|
result = original_tool_function(*args, **kwargs)
|
61
61
|
try:
|
62
|
-
|
62
|
+
if isinstance(result, types.GeneratorType):
|
63
|
+
result = list(result)
|
64
|
+
print(f"{item.name} 调用完毕,结果为:", result)
|
63
65
|
except:
|
64
66
|
pass
|
65
67
|
return result
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|