Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
WHALEEYE committed Aug 9, 2024
1 parent 36b99e8 commit 14dd23b
Show file tree
Hide file tree
Showing 11 changed files with 1,277 additions and 756 deletions.
2 changes: 1 addition & 1 deletion crab/agents/backend_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.
# =========== Copyright 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
# ruff: noqa: F401
from .camel_model import CamelModel
from .claude_model import ClaudeModel
from .gemini_model import GeminiModel
from .openai_model import OpenAIModel

52 changes: 52 additions & 0 deletions crab/agents/backend_models/camel_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# =========== Copyright 2024 @ 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 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
from typing import Any, Dict, Optional

from crab import BackendModel

try:
from camel.agents import ChatAgent
from camel.models import ModelFactory

CAMEL_ENABLED = True
except ImportError:
CAMEL_ENABLED = False


class CamelModel(BackendModel):
def __init__(
self,
model: str,
parameters: Optional[Dict[str, Any]] = None,
history_messages_len: int = 0,
) -> None:
if not CAMEL_ENABLED:
raise ImportError("Please install camel-ai to use CamelModel")
parameters = parameters or {}
super().__init__(
model,
parameters,
history_messages_len,
)
# model = ModelFactory.create(model, **parameters)
# self._client = ChatAgent(model)

def get_token_usage(self):
pass

def reset(self, system_message, action_space):
pass

def chat(self, message):
pass
11 changes: 4 additions & 7 deletions crab/core/backend_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@ def __init__(

assert self.history_messages_len >= 0

self.reset("You are a helpfu assistant.", None)
self.reset("You are a helpful assistant.", None)

@abstractmethod
def chat(self, contents: list[tuple[str, MessageType]]) -> BackendOutput:
...
def chat(self, contents: list[tuple[str, MessageType]]) -> BackendOutput: ...

@abstractmethod
def reset(
self,
system_message: str,
action_space: list[Action] | None,
):
...
): ...

@abstractmethod
def get_token_usage(self):
...
def get_token_usage(self): ...
1,880 changes: 1,134 additions & 746 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ license = "Apache License 2.0"
repository = "https://github.com/camel-ai/crab"

[tool.poetry.dependencies]
python = "^3.10"
python = "^3.10, <3.12"

# core
docstring-parser = "^0"
Expand Down Expand Up @@ -49,9 +49,10 @@ httpx = { version = "*", optional = true }

# agent
google-generativeai = { version = "^0.5.2", optional = true }
anthropic = { version = "^0.26.0", optional = true }
anthropic = { version = "^0.29.0", optional = true }
groq = { version = "^0.5.0", optional = true }
ollama = { version = "^0.2.0", optional = true }
camel-ai = { version = "^0.1.6.2", optional = true }

# text ocr
easyocr = { version = "^1.7.1", optional = true }
Expand Down Expand Up @@ -89,6 +90,7 @@ client = [
"anthropic",
"groq",
"ollama",
"camel-ai",
"easyocr",
"plotly",
"torch",
Expand Down
15 changes: 15 additions & 0 deletions test/agents/backend_models/test_claude_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# =========== Copyright 2024 @ 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 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
import pytest

from crab import MessageType, action
from crab.agents.backend_models.claude_model import ClaudeModel

# TODO: Add mock data


@pytest.fixture
def claude_model_text():
return ClaudeModel(
Expand All @@ -24,6 +38,7 @@ def add(a: int, b: int):
"""
return a + b


@pytest.mark.skip(reason="Mock data to be added")
def test_text_chat(claude_model_text):
message = ("Hello!", MessageType.TEXT)
Expand Down
15 changes: 15 additions & 0 deletions test/agents/backend_models/test_gemini_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# =========== Copyright 2024 @ 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 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
import pytest

from crab import MessageType, action
from crab.agents.backend_models.gemini_model import GeminiModel

# TODO: Add mock data


@pytest.fixture
def gemini_model_text():
return GeminiModel(
Expand All @@ -24,6 +38,7 @@ def add(a: int, b: int):
"""
return a + b


@pytest.mark.skip(reason="Mock data to be added")
def test_text_chat(gemini_model_text):
message = ("Hello!", MessageType.TEXT)
Expand Down
13 changes: 13 additions & 0 deletions test/agents/backend_models/test_openai_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# =========== Copyright 2024 @ 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 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
import os
from unittest.mock import MagicMock, patch

Expand Down
13 changes: 13 additions & 0 deletions test/agents/policies/test_multi_agent_by_func.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# =========== Copyright 2024 @ 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 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
import pytest

from crab import create_benchmark
Expand Down
13 changes: 13 additions & 0 deletions test/agents/policies/test_mutli_agent_by_env.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# =========== Copyright 2024 @ 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 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
import pytest

from crab import create_benchmark
Expand Down
13 changes: 13 additions & 0 deletions test/agents/policies/test_single_agent.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# =========== Copyright 2024 @ 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 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
import os
from unittest.mock import MagicMock, patch

Expand Down

0 comments on commit 14dd23b

Please sign in to comment.