Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat: Update knowledge graph agent for tutorial (#712)

Wendong-Fanbc729fb09112
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index 3e66a54d7..f270778e7 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -27,7 +27,7 @@ body:
attributes:
label: What version of camel are you using?
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
- placeholder: E.g., 0.1.5.5
+ placeholder: E.g., 0.1.5.6
validations:
required: true
diff --git a/README.md b/README.md
index 97c0f8d0a..4a36e3766 100644
--- a/README.md
+++ b/README.md
@@ -110,7 +110,7 @@ conda create --name camel python=3.9
conda activate camel
# Clone github repo
-git clone -b v0.1.5.5 https://github.com/camel-ai/camel.git
+git clone -b v0.1.5.6 https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
diff --git a/camel/__init__.py b/camel/__init__.py
index 4129cce6b..ea2b8ceea 100644
--- a/camel/__init__.py
+++ b/camel/__init__.py
@@ -12,7 +12,7 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
-__version__ = '0.1.5.5'
+__version__ = '0.1.5.6'
__all__ = [
'__version__',
diff --git a/camel/agents/knowledge_graph_agent.py b/camel/agents/knowledge_graph_agent.py
index 0615b148c..8a081fbe9 100644
--- a/camel/agents/knowledge_graph_agent.py
+++ b/camel/agents/knowledge_graph_agent.py
@@ -78,17 +78,16 @@ Expected Output:
Nodes:
-Node(id='John', type='Person', properties={'agent_generated'})
-Node(id='XYZ Corporation', type='Organization', properties={'agent_generated'})
-Node(id='New York City', type='Location', properties={'agent_generated'})
+Node(id='John', type='Person')
+Node(id='XYZ Corporation', type='Organization')
+Node(id='New York City', type='Location')
Relationships:
Relationship(subj=Node(id='John', type='Person'), obj=Node(id='XYZ
-Corporation', type='Organization'), type='WorksAt', properties=
-{'agent_generated'})
+Corporation', type='Organization'), type='WorksAt')
Relationship(subj=Node(id='John', type='Person'), obj=Node(id='New York City',
-type='Location'), type='ResidesIn', properties={'agent_generated'})
+type='Location'), type='ResidesIn')
===== TASK =====
Please extracts nodes and relationships from given content and structures them
@@ -211,11 +210,10 @@ class KnowledgeGraphAgent(ChatAgent):
import re
# Regular expressions to extract nodes and relationships
- node_pattern = r"Node\(id='(.*?)', type='(.*?)', properties=(.*?)\)"
+ node_pattern = r"Node\(id='(.*?)', type='(.*?)'\)"
rel_pattern = (
r"Relationship\(subj=Node\(id='(.*?)', type='(.*?)'\), "
- r"obj=Node\(id='(.*?)', type='(.*?)'\), type='(.*?)', "
- r"properties=\{(.*?)\}\)"
+ r"obj=Node\(id='(.*?)', type='(.*?)'\), type='(.*?)'\)"
)
nodes = {}
@@ -223,8 +221,8 @@ class KnowledgeGraphAgent(ChatAgent):
# Extract nodes
for match in re.finditer(node_pattern, input_string):
- id, type, properties = match.groups()
- properties = eval(properties)
+ id, type = match.groups()
+ properties = {'source': 'agent_created'}
if id not in nodes:
node = Node(id, type, properties)
if self._validate_node(node):
@@ -232,10 +230,8 @@ class KnowledgeGraphAgent(ChatAgent):
# Extract relationships
for match in re.finditer(rel_pattern, input_string):
- subj_id, subj_type, obj_id, obj_type, rel_type, properties_str = (
- match.groups()
- )
- properties = eval(properties_str)
+ subj_id, subj_type, obj_id, obj_type, rel_type = match.groups()
+ properties = {'source': 'agent_created'}
if subj_id in nodes and obj_id in nodes:
subj = nodes[subj_id]
obj = nodes[obj_id]
diff --git a/docs/conf.py b/docs/conf.py
index 95a8532f7..3e186e48c 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -27,7 +27,7 @@ sys.path.insert(0, os.path.abspath('..'))
project = 'CAMEL'
copyright = '2023, CAMEL-AI.org'
author = 'CAMEL-AI.org'
-release = '0.1.5.5'
+release = '0.1.5.6'
html_favicon = (
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'
diff --git a/docs/get_started/setup.md b/docs/get_started/setup.md
index 9b898163b..5aeea5598 100644
--- a/docs/get_started/setup.md
+++ b/docs/get_started/setup.md
@@ -61,7 +61,7 @@ conda create --name camel python=3.10
conda activate camel
# Clone github repo
-git clone -b v0.1.5.5 https://github.com/camel-ai/camel.git
+git clone -b v0.1.5.6 https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
diff --git a/pyproject.toml b/pyproject.toml
index 14e77c130..c198e8cb1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "camel-ai"
-version = "0.1.5.5"
+version = "0.1.5.6"
authors = ["CAMEL-AI.org"]
description = "Communicative Agents for AI Society Study"
readme = "README.md"
diff --git a/test/agents/test_knowledge_agent.py b/test/agents/test_knowledge_agent.py
index 25c09be9f..305e15175 100644
--- a/test/agents/test_knowledge_agent.py
+++ b/test/agents/test_knowledge_agent.py
@@ -47,15 +47,26 @@ def test_validate_relationship_invalid():
def test_parse_graph_elements():
agent.element = Mock()
input_string = """
- Node(id='node_id', type='node_type', properties={})
- Relationship(subj=Node(id='subj_id', type='subj_type', properties={}),
- obj=Node(id='obj_id', type='obj_type', properties={}), type='test_type',
- properties={})
+ Node(id='node_id', type='node_type')
+ Relationship(subj=Node(id='subj_id', type='subj_type'),
+ obj=Node(id='obj_id', type='obj_type'), type='test_type')
"""
expected_nodes = [
- Node(id='node_id', type='node_type', properties={}),
- Node(id='subj_id', type='subj_type', properties={}),
- Node(id='obj_id', type='obj_type', properties={}),
+ Node(
+ id='node_id',
+ type='node_type',
+ properties={'source': 'agent_created'},
+ ),
+ Node(
+ id='subj_id',
+ type='subj_type',
+ properties={'source': 'agent_created'},
+ ),
+ Node(
+ id='obj_id',
+ type='obj_type',
+ properties={'source': 'agent_created'},
+ ),
]
result = agent._parse_graph_elements(input_string)