pycoze 0.1.149__tar.gz → 0.1.150__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. {pycoze-0.1.149 → pycoze-0.1.150}/PKG-INFO +1 -1
  2. pycoze-0.1.149/pycoze/bot/bot.py → pycoze-0.1.150/pycoze/bot/agent_chat.py +78 -97
  3. pycoze-0.1.150/pycoze/bot/bot.py +21 -0
  4. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze.egg-info/PKG-INFO +1 -1
  5. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze.egg-info/SOURCES.txt +1 -0
  6. {pycoze-0.1.149 → pycoze-0.1.150}/setup.py +1 -1
  7. {pycoze-0.1.149 → pycoze-0.1.150}/LICENSE +0 -0
  8. {pycoze-0.1.149 → pycoze-0.1.150}/README.md +0 -0
  9. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/__init__.py +0 -0
  10. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/ai/__init__.py +0 -0
  11. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/ai/vram_reserve.py +0 -0
  12. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/bot/__init__.py +0 -0
  13. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/bot/agent/__init__.py +0 -0
  14. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/bot/agent/agent.py +0 -0
  15. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  16. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/bot/agent/agent_types/const.py +0 -0
  17. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  18. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/bot/agent/assistant.py +0 -0
  19. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/bot/agent/chat.py +0 -0
  20. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/module.py +0 -0
  21. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/reference/__init__.py +0 -0
  22. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/reference/bot.py +0 -0
  23. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/reference/lib.py +0 -0
  24. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/reference/tool.py +0 -0
  25. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/ui/__init__.py +0 -0
  26. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/ui/base.py +0 -0
  27. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/ui/color.py +0 -0
  28. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/ui/typ.py +0 -0
  29. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/ui/ui_def.py +0 -0
  30. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/utils/__init__.py +0 -0
  31. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/utils/arg.py +0 -0
  32. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze/utils/text_or_file.py +0 -0
  33. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze.egg-info/dependency_links.txt +0 -0
  34. {pycoze-0.1.149 → pycoze-0.1.150}/pycoze.egg-info/top_level.txt +0 -0
  35. {pycoze-0.1.149 → pycoze-0.1.150}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.149
3
+ Version: 0.1.150
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -1,97 +1,78 @@
1
- import json
2
- from langchain_openai import ChatOpenAI
3
- from .agent import run_agent, Runnable, INPUT_MESSAGE, output
4
- import asyncio
5
- from langchain_core.messages import HumanMessage
6
- from pycoze import utils
7
- from pycoze.reference.bot import ref_bot
8
- from pycoze.reference.tool import ref_tools
9
- from langchain_core.utils.function_calling import convert_to_openai_tool
10
-
11
- params = utils.arg.read_params_file()
12
- llm_file = params["appPath"] + "/JsonStorage/llm.json"
13
- with open(llm_file, "r", encoding="utf-8") as f:
14
- cfg = json.load(f)
15
-
16
-
17
- def load_role_setting(bot_setting_file: str):
18
- with open(bot_setting_file, "r", encoding="utf-8") as f:
19
- return json.load(f)
20
-
21
-
22
- def load_abilities(bot_setting_file: str):
23
- with open(bot_setting_file, "r", encoding="utf-8") as f:
24
- role_setting = json.load(f)
25
-
26
- abilities = []
27
- for bot_id in role_setting["bots"]:
28
- bot = ref_bot(bot_id, as_agent_tool=True)
29
- if bot:
30
- abilities.append(bot)
31
- for tool_id in role_setting["tools"]:
32
- abilities.extend(ref_tools(tool_id, as_agent_tool=True))
33
- return abilities
34
-
35
-
36
- def agent_chat(bot_setting_file, history):
37
- role_setting = load_role_setting(bot_setting_file)
38
- abilities = load_abilities(bot_setting_file)
39
-
40
- chat = ChatOpenAI(
41
- api_key=cfg["apiKey"],
42
- base_url=cfg["baseURL"],
43
- model=cfg["model"],
44
- temperature=(
45
- role_setting["temperature"] * 2
46
- if cfg["model"].startswith("deepseek")
47
- else role_setting["temperature"]
48
- ),
49
- stop_sequences=[
50
- "tool▁calls▁end",
51
- "tool▁call▁end",
52
- ], # 停用deepseek的工具调用标记,不然会虚构工具调用过程和结果
53
- )
54
- prompt = role_setting["prompt"]
55
- if (
56
- (cfg["model"].startswith("deepseek")
57
- or cfg["toolCompatibilityMode"])
58
- and len(abilities) > 0
59
- ):
60
- prompt += """
61
- 作为一个AI,你如果不确定结果,请务必使用工具查询。
62
- 你可以通过下面的方式使用工具,并耐心等待工具返回结果。
63
- 如果你需要调用工具,请使用以正确markdown中的json代码格式进行结尾(务必保证json格式正确,不要出现反斜杠未转义等问题):
64
- ```json
65
- {"name": 函数名, "parameters": 参数词典}
66
- ```
67
- """
68
- if cfg["model"].startswith("yi-"):
69
- prompt += "\nAvailable functions:\n"
70
- for t in abilities:
71
- prompt += f"\n```json\n{json.dumps(convert_to_openai_tool(t))}\n```"
72
- agent = Runnable(
73
- agent_execution_mode="FuncCall",
74
- tools=abilities,
75
- llm=chat,
76
- assistant_message=prompt,
77
- tool_compatibility_mode=cfg["toolCompatibilityMode"],
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.149
3
+ Version: 0.1.150
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -10,6 +10,7 @@ pycoze.egg-info/top_level.txt
10
10
  pycoze/ai/__init__.py
11
11
  pycoze/ai/vram_reserve.py
12
12
  pycoze/bot/__init__.py
13
+ pycoze/bot/agent_chat.py
13
14
  pycoze/bot/bot.py
14
15
  pycoze/bot/agent/__init__.py
15
16
  pycoze/bot/agent/agent.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.149",
5
+ version="0.1.150",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
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