Skip to content

Commit

Permalink
fix: graph element (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan authored Oct 24, 2024
1 parent 99ba4d6 commit d508eda
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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.2.3
placeholder: E.g., 0.2.4a
validations:
required: true

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ conda create --name camel python=3.10
conda activate camel
# Clone github repo
git clone -b v0.2.3 https://github.com/camel-ai/camel.git
git clone -b v0.2.4a https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
Expand Down
2 changes: 1 addition & 1 deletion camel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========

__version__ = '0.2.3'
__version__ = '0.2.4a'

__all__ = [
'__version__',
Expand Down
6 changes: 4 additions & 2 deletions camel/storages/graph_storages/graph_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from __future__ import annotations

from typing import TYPE_CHECKING, List, Union
from typing import List, Union

from pydantic import BaseModel, ConfigDict, Field

if TYPE_CHECKING:
try:
from unstructured.documents.elements import Element
except ImportError:
Element = None # type:ignore[misc,assignment]


class Node(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
project = 'CAMEL'
copyright = '2024, CAMEL-AI.org'
author = 'CAMEL-AI.org'
release = '0.2.3'
release = '0.2.4a'

html_favicon = (
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'
Expand Down
2 changes: 1 addition & 1 deletion docs/get_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ conda create --name camel python=3.10
conda activate camel
# Clone github repo
git clone -b v0.2.3 https://github.com/camel-ai/camel.git
git clone -b v0.2.4a https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
Expand Down
281 changes: 144 additions & 137 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "camel-ai"
version = "0.2.3"
version = "0.2.4a"
authors = ["CAMEL-AI.org"]
description = "Communicative Agents for AI Society Study"
readme = "README.md"
Expand Down
74 changes: 74 additions & 0 deletions test/storages/graph_storages/test_graph_element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========


import pytest
from unstructured.documents.elements import Element

from camel.loaders import UnstructuredIO
from camel.storages.graph_storages.graph_element import (
GraphElement,
Node,
Relationship,
)

sample_element = UnstructuredIO().create_element_from_text("sample text")


@pytest.fixture
def sample_nodes():
return [
Node(id=1, type="Person", properties={"name": "Alice"}),
Node(id=2, type="Person", properties={"name": "Bob"}),
]


@pytest.fixture
def sample_relationship(sample_nodes):
return Relationship(
subj=sample_nodes[0],
obj=sample_nodes[1],
type="Friend",
properties={"since": "2020"},
)


@pytest.fixture
def sample_graph_element(sample_nodes, sample_relationship):
return GraphElement(
nodes=sample_nodes,
relationships=[sample_relationship],
source=sample_element,
)


def test_graph_element_initialization(sample_nodes, sample_relationship):
graph_element = GraphElement(
nodes=sample_nodes,
relationships=[sample_relationship],
source=sample_element,
)
assert len(graph_element.nodes) == 2
assert len(graph_element.relationships) == 1
assert isinstance(graph_element.source, Element)


def test_graph_element_empty_nodes_relationships():
graph_element = GraphElement(
nodes=[],
relationships=[],
source=sample_element,
)
assert graph_element.nodes == []
assert graph_element.relationships == []

0 comments on commit d508eda

Please sign in to comment.