pycoze 0.1.32__tar.gz → 0.1.34__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pycoze-0.1.32 → pycoze-0.1.34}/PKG-INFO +1 -1
- pycoze-0.1.34/pycoze/bot/agent/chat.py +22 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/bot.py +7 -15
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze.egg-info/PKG-INFO +1 -1
- {pycoze-0.1.32 → pycoze-0.1.34}/setup.py +1 -1
- pycoze-0.1.32/pycoze/bot/agent/chat.py +0 -28
- {pycoze-0.1.32 → pycoze-0.1.34}/LICENSE +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/README.md +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/__init__.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/__init__.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/agent/__init__.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/agent/agent.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/agent/agent_types/__init__.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/agent/agent_types/react_agent.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/agent/agent_types/react_prompt.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/agent/assistant.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/bot/base.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/gpu/__init__.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/gpu/gpu_reserve.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/module.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/ui/__init__.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/ui/base.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/ui/color.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/ui/typ.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/ui/ui_def.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/utils/__init__.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/utils/arg.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze/utils/text_or_file.py +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze.egg-info/SOURCES.txt +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze.egg-info/dependency_links.txt +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/pycoze.egg-info/top_level.txt +0 -0
- {pycoze-0.1.32 → pycoze-0.1.34}/setup.cfg +0 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
import json
|
2
|
+
from langchain_core.messages import AIMessage
|
3
|
+
|
4
|
+
|
5
|
+
INPUT_MESSAGE = "INPUT_MESSAGE=>"
|
6
|
+
_OUTPUT_MESSAGE = "OUTPUT_MESSAGE=>"
|
7
|
+
_INFOMATION_MESSAGE = "INFOMATION_MESSAGE=>"
|
8
|
+
_LOG = "LOG=>"
|
9
|
+
|
10
|
+
|
11
|
+
def log(content, *args, end="\n", **kwargs):
|
12
|
+
print(_LOG + content, *args, end=end, **kwargs)
|
13
|
+
|
14
|
+
|
15
|
+
def output(role, content):
|
16
|
+
assert role == "assistant"
|
17
|
+
print(_OUTPUT_MESSAGE + json.dumps({"role": role, "content": content}))
|
18
|
+
return AIMessage(content=content)
|
19
|
+
|
20
|
+
|
21
|
+
def info(role, content):
|
22
|
+
print(_INFOMATION_MESSAGE + json.dumps({"role": role, "content": content}))
|
@@ -3,7 +3,7 @@ from langchain_openai import ChatOpenAI
|
|
3
3
|
from .base import import_tools
|
4
4
|
from .agent import run_agent, Runnable, INPUT_MESSAGE, output
|
5
5
|
import asyncio
|
6
|
-
from langchain_core.messages import
|
6
|
+
from langchain_core.messages import HumanMessage
|
7
7
|
from pycoze import utils
|
8
8
|
|
9
9
|
|
@@ -26,7 +26,7 @@ def load_tools(bot_setting_file: str):
|
|
26
26
|
return tools
|
27
27
|
|
28
28
|
|
29
|
-
def
|
29
|
+
def agent_chat(bot_setting_file, history):
|
30
30
|
role_setting = load_role_setting(bot_setting_file)
|
31
31
|
tools = load_tools(bot_setting_file)
|
32
32
|
with open(llm_file, "r", encoding="utf-8") as f:
|
@@ -48,20 +48,12 @@ def run_agent(bot_setting_file, history):
|
|
48
48
|
|
49
49
|
|
50
50
|
def chat(bot_setting_file: str):
|
51
|
+
history = []
|
51
52
|
while True:
|
52
53
|
input_text = input()
|
53
54
|
if not input_text.startswith(INPUT_MESSAGE):
|
54
55
|
raise ValueError("Invalid message")
|
55
|
-
|
56
|
-
history
|
57
|
-
|
58
|
-
|
59
|
-
history += [AIMessage(content=message["content"])]
|
60
|
-
elif message["role"] == "user":
|
61
|
-
history += [HumanMessage(content=message["content"])]
|
62
|
-
elif message["role"] == "system":
|
63
|
-
history += [SystemMessage(content=message["content"])]
|
64
|
-
else:
|
65
|
-
raise ValueError("Invalid message")
|
66
|
-
result = run_agent(bot_setting_file, history)
|
67
|
-
output("assistant", result, history)
|
56
|
+
message = json.loads(input_text[len(INPUT_MESSAGE) :])
|
57
|
+
history.append(HumanMessage(message["content"]))
|
58
|
+
result = agent_chat(bot_setting_file, history)
|
59
|
+
history.append(output("assistant", result, history))
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
from langchain_core.messages import HumanMessage, AIMessage
|
3
|
-
|
4
|
-
|
5
|
-
INPUT_MESSAGE = "INPUT_MESSAGE=>"
|
6
|
-
_OUTPUT_MESSAGE = "OUTPUT_MESSAGE=>"
|
7
|
-
_INFOMATION_MESSAGE = "INFOMATION_MESSAGE=>"
|
8
|
-
_LOG = "LOG=>"
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def log(content, *args, end='\n', **kwargs):
|
13
|
-
print(_LOG + content, *args, end=end, **kwargs)
|
14
|
-
|
15
|
-
|
16
|
-
def output(role, content, history):
|
17
|
-
print(_OUTPUT_MESSAGE + json.dumps({"role": role, "content": content}))
|
18
|
-
if role == "assistant":
|
19
|
-
history.append(AIMessage(content=content))
|
20
|
-
|
21
|
-
elif role == "user":
|
22
|
-
history.append(HumanMessage(content=content))
|
23
|
-
else:
|
24
|
-
raise ValueError("Invalid role")
|
25
|
-
return history
|
26
|
-
|
27
|
-
def info(role, content):
|
28
|
-
print(_INFOMATION_MESSAGE + json.dumps({"role": role, "content": content}))
|
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
|