Skip to content

Commit ebc8c3f

Browse files
authored
Merge pull request #101 from codefuse-ai/muagent_dev
[muagent v0.1.1] add reasoning logger and shutdown nbclient kernel
2 parents 6c51c98 + adbb1d3 commit ebc8c3f

29 files changed

+63
-39
lines changed

examples/test_config.py.example

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os, openai, base64
22
from loguru import logger
3+
import json
34

45
os.environ["DM_llm_name"] = 'Qwen2_72B_Instruct_OpsGPT' #or gpt_4
56

@@ -123,7 +124,7 @@ DB_CONFIGS = {
123124
"gb_config": {
124125
"gb_type": "NebulaHandler",
125126
"extra_kwargs": {
126-
'host':'graphd',
127+
'host': os.environ['nb_host'],
127128
'port': '9669',
128129
'username': os.environ['nb_username'],
129130
'password': os.environ['nb_password'],
@@ -133,7 +134,7 @@ DB_CONFIGS = {
133134
"tb_config": {
134135
"tb_type": 'TBaseHandler',
135136
"index_name": "opsgptkg",
136-
"host": 'redis-stack',
137+
"host": os.environ['tb_host'],
137138
"port": '6379',
138139
"username": os.environ['tb_username'],
139140
"password": os.environ['tb_password'],
@@ -146,6 +147,7 @@ DB_CONFIGS = {
146147
os.environ["DB_CONFIGS"] = json.dumps(DB_CONFIGS)
147148

148149

150+
os.environ["clear_history_data"] = "False" # 'True'
149151

150152
########################################
151153
########## 以下参数暂不涉及无需配置 ########

muagent/db_handler/graph_db_handler/geabase_handler.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from gdbc2.geabase_client import GeaBaseClient, Node, Edge, MutateBatchOperation, GeaBaseUtil
88
from gdbc2.geabase_env import GeaBaseEnv
99
except:
10-
logger.error("ignore this sdk")
10+
pass
11+
# logger.error("ignore this sdk")
1112

1213
from .base_gb_handler import GBHandler
1314
from muagent.db_handler.utils import deduplicate_dict

muagent/db_handler/graph_db_handler/nebula_handler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def is_nodeid_exist(self, nodeid: str) -> bool:
10211021
def check_edge_exist(self, src_id: str, dst_id: str) -> bool:
10221022
try:
10231023
if self.get_current_edge(src_id, dst_id):
1024-
print('Edge already exists!')
1024+
# print('Edge already exists!')
10251025
return True
10261026
except Exception as e:
10271027
print('Edge not exists!')
@@ -1041,7 +1041,7 @@ def check_node_before_execute(self, nodeid: str, action: str = ""):
10411041
)
10421042
# 节点是否存在: 1.删除时节点存在不报错 2.添加时节点存在报错 3.update时节点存在不报错
10431043
if self.is_nodeid_exist(nodeid) and action == "add":
1044-
logger.info('Node already exits!')
1044+
# logger.info('Node already exits!')
10451045
return GbaseExecStatus(
10461046
errorMessage='GDB_ENGINE_PRIMARY_KEY_DUPLICATE',
10471047
errorCode=1,

muagent/ekg_project.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import time
1616
import random
1717

18+
os.environ["operation_mode"] = "open_source"
19+
os.environ["intention_url"] = ""
20+
1821
from .llm_models import LLMConfig, EmbedConfig
1922
from .schemas.db import TBConfig, GBConfig
2023
from .schemas.models import ModelConfig
@@ -228,7 +231,6 @@ def get_ekg_project_config_from_env(
228231
model_type = random.choice(embedding_list)
229232
default_model_config = project_configs["model_configs"][model_type]
230233
project_configs["model_configs"]["default_embed"] = default_model_config
231-
project_configs[k] = v
232234

233235
# init embedding configs
234236
if embed_configs:
@@ -286,7 +288,7 @@ def get_ekg_project_config_from_env(
286288
project_configs["prompt_configs"] = prompt_configs
287289
else:
288290
logger.warning(
289-
f"Cant't init any AGENT_CONFIGS in this env."
291+
f"Cant't init any PROMPT_CONFIGS in this env."
290292
)
291293

292294

muagent/prompt_manager/language/__init__.py

Whitespace-only changes.

muagent/sandbox/nbclient.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ def reset_notebook(self) -> str:
179179
asyncio.run(self._restart_client())
180180
return "Reset notebook"
181181

182-
182+
async def close_client(self):
183+
await self.nb_client.km.shutdown_kernel(now=True)
183184

184185

185186

@@ -291,7 +292,7 @@ def restart(self, ) -> CodeBoxStatus:
291292
return CodeBoxStatus(status="restared")
292293

293294
def stop(self, ) -> CodeBoxStatus:
294-
pass
295+
asyncio.run(self.nbe.close_client())
295296

296297
def __del__(self):
297298
self.stop()

muagent/schemas/kb/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/src/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/src/geabase_handler/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/src/geabase_handler/geabase_handlerplus.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525

2626

27-
28-
import logging
29-
logging.basicConfig(level=logging.INFO)
27+
from ..utils.logger import logging
28+
# import logging
29+
# logging.basicConfig(level=logging.INFO)
3030

3131

3232

muagent/service/ekg_reasoning/src/graph_search/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/src/graph_search/call_old_fuction.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# lingsi 游走推理服务 old
22
import json
33
import requests
4-
import logging
4+
# import logging
5+
from ..utils.logger import logging
56
import copy
67
import sys
78
import os
89

9-
logger = logging.getLogger()
10-
logging.basicConfig(level=logging.DEBUG)
10+
# logger = logging.getLogger()
11+
# logging.basicConfig(level=logging.DEBUG)
1112

1213
#step 1 retriver
1314

muagent/service/ekg_reasoning/src/graph_search/geabase_search_plus.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import json
2929
import requests
3030
import time
31-
import logging
31+
# import logging
32+
from ..utils.logger import logging
3233
import copy
3334
import sys
3435
import os, base64

muagent/service/ekg_reasoning/src/graph_search/graph_search_main.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import json
2525
import requests
2626
import time
27-
import logging
27+
# import logging
28+
from ..utils.logger import logging
2829
import copy
2930
import sys
3031
import os, base64
@@ -66,8 +67,8 @@
6667

6768

6869

69-
# 配置logging模块
70-
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s - %(lineno)d', level=logging.INFO)
70+
# # 配置logging模块
71+
# logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s - %(lineno)d', level=logging.INFO)
7172

7273

7374

muagent/service/ekg_reasoning/src/graph_search/task_node_agent.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import json
3030
import requests
3131
import time
32-
import logging
32+
# import logging
33+
from ..utils.logger import logging
3334
import copy
3435
import sys
3536
import os, base64

muagent/service/ekg_reasoning/src/graphstructure/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/src/graphstructure/graphstrcturesearchfun.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import json
2727
import requests
2828
import time
29-
import logging
29+
# import logging
30+
from ..utils.logger import logging
3031
import copy
3132
import sys
3233
import os, base64
@@ -63,8 +64,8 @@
6364

6465

6566

66-
# 配置logging模块
67-
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s - %(lineno)d', level=logging.INFO)
67+
# # 配置logging模块
68+
# logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s - %(lineno)d', level=logging.INFO)
6869

6970

7071

muagent/service/ekg_reasoning/src/intention_recognition/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/src/intention_recognition/intention_recognition_tool.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import logging
55
import copy
66
import os
7-
8-
logger = logging.getLogger()
9-
logging.basicConfig(level=logging.DEBUG)
7+
from ..utils.logger import logging
8+
# logger = logging.getLogger()
9+
# logging.basicConfig(level=logging.DEBUG)
1010
RETRY_MAX_NUM = 3
1111
def intention_recognition_ekgfunc( root_node_id, rule, query, memory, start_from_root = True,
1212
url= os.environ['intention_url'] ):

muagent/service/ekg_reasoning/src/memory_handler/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/src/memory_handler/ekg_memory_handler.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222

2323
from muagent.connector.schema import Message
2424
from src.utils.call_llm import call_llm,extract_final_result
25-
import logging
26-
logging.basicConfig(level=logging.INFO)
25+
from ..utils.logger import logging
26+
# import logging
27+
# logging.basicConfig(level=logging.INFO)
2728

2829
# from loguru import logger as logging
2930
from src.geabase_handler.geabase_handlerplus import GB_handler

muagent/service/ekg_reasoning/src/question_answer/__init__.py

Whitespace-only changes.

muagent/service/ekg_reasoning/src/question_answer/qa_function.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
from muagent.connector.schema import Message
1818
from src.utils.call_llm import call_llm, extract_final_result, robust_call_llm
1919

20-
import logging
21-
logging.basicConfig(level=logging.INFO)
20+
from ..utils.logger import logging
21+
# import logging
22+
# logging.basicConfig(level=logging.INFO)
2223

2324
from src.geabase_handler.geabase_handlerplus import GB_handler
2425
from src.utils.normalize import hash_id

muagent/service/ekg_reasoning/src/utils/call_llm.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from colorama import Fore
2222
from Crypto.Cipher import AES
2323
from loguru import logger
24-
import logging
25-
24+
# import logging
25+
from loguru import logger as logging
2626

2727

2828
MOST_RETRY_TIMES = 5

muagent/service/ekg_reasoning/src/utils/logger.py

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ def get_logger():
1010
logger_loggering = logging.getLogger()
1111
return logger_loggering
1212

13+
import os
14+
if os.environ.get("operation_mode")=="antcode":
15+
import logging
16+
FORMAT = '[%(asctime)s %(filename)s->%(funcName)s():%(lineno)s]%(levelname)s: %(message)s'
17+
logging.basicConfig(level=logging.DEBUG, format=FORMAT)
18+
else:
19+
from loguru import logger as logging
20+
1321

1422
if __name__ == '__main__':
1523
logger = get_logger()

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
setuptools.setup(
77
name="codefuse-muagent",
8-
version="0.1.0",
8+
version="0.1.1",
99
author="shanshi",
1010
author_email="wyp311395@antgroup.com",
11-
description="A multi-agent framework that facilitates the rapid construction of collaborative teams of agents.",
11+
description="An Innovative Agent Framework Driven by KG Engine",
1212
# long_description=long_description,
1313
long_description_content_type="text/markdown",
1414
url="https://github.com/codefuse-ai/CodeFuse-muAgent",
@@ -40,7 +40,7 @@
4040
"ollama",
4141
"colorama",
4242
"pycryptodome",
43-
"dashscope"
43+
"dashscope",
4444
#
4545
"chromadb==0.4.17",
4646
"javalang==0.13.0",

tests/service/ekg_project_test.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
)
2020
sys.path.append(src_dir)
2121

22-
import logging
22+
# import logging
23+
from loguru import logger as logging
2324
# Set the logging level to WARNING, which will suppress INFO and DEBUG messages
24-
logging.basicConfig(level=logging.ERROR)
25+
# logging.basicConfig(level=logging.ERROR)
2526

2627

2728
from muagent import EKG, get_ekg_project_config_from_env

tests/test_config.py.example

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os, openai, base64
22
from loguru import logger
3+
import json
34

45
os.environ["DM_llm_name"] = 'Qwen2_72B_Instruct_OpsGPT' #or gpt_4
56

@@ -123,7 +124,7 @@ DB_CONFIGS = {
123124
"gb_config": {
124125
"gb_type": "NebulaHandler",
125126
"extra_kwargs": {
126-
'host':'graphd',
127+
'host': os.environ['nb_host'],
127128
'port': '9669',
128129
'username': os.environ['nb_username'],
129130
'password': os.environ['nb_password'],
@@ -133,7 +134,7 @@ DB_CONFIGS = {
133134
"tb_config": {
134135
"tb_type": 'TBaseHandler',
135136
"index_name": "opsgptkg",
136-
"host": 'redis-stack',
137+
"host": os.environ['tb_host'],
137138
"port": '6379',
138139
"username": os.environ['tb_username'],
139140
"password": os.environ['tb_password'],
@@ -146,6 +147,7 @@ DB_CONFIGS = {
146147
os.environ["DB_CONFIGS"] = json.dumps(DB_CONFIGS)
147148

148149

150+
os.environ["clear_history_data"] = "False" # 'True'
149151

150152
########################################
151153
########## 以下参数暂不涉及无需配置 ########

0 commit comments

Comments
 (0)