Skip to content

Commit

Permalink
Clean dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dandansamax committed Jul 24, 2024
1 parent 4dbbf61 commit 0d0684b
Show file tree
Hide file tree
Showing 8 changed files with 749 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .github/actions/crab_install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ runs:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: poetry install -E visual-prompt -E server
run: poetry install -E client -E server
shell: bash
- uses: actions/cache/save@v3
name: Save caches based on poetry.lock
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Crab is a framework for building LLM agent benchmark environments in a Python-ce
- pip

```bash
pip install crab-framework[visual-prompt]
pip install crab-framework[client]
```

## Examples
Expand Down
5 changes: 3 additions & 2 deletions crab-benchmark-v0/docs/environment_local_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Then pull the crab repo and install:
git clone https://github.com/camel-ai/crab

cd crab
poetry install -E visual-prompt
poetry install -E client
```

## Install Ubuntu VM
Expand All @@ -22,7 +22,8 @@ After install Ubuntu, you should install crab-server on it and do necessary init
```bash
git clone https://github.com/camel-ai/crab.git ~/crab/
cd ~/crab/crab-benchmark-v0/scripts
bash ubuntu_env_init.sh
chmod +x ubuntu_env_init.sh
./ubuntu_env_init.sh
```

The VM will reboot after initilization. After rebooting, remember its ip address.
Expand Down
15 changes: 11 additions & 4 deletions crab/agents/backend_models/claude_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
from time import sleep
from typing import Any

import anthropic
from anthropic.types import TextBlock
from anthropic.types.beta.tools import ToolUseBlock

from crab import Action, ActionOutput, BackendModel, BackendOutput, MessageType

try:
import anthropic
from anthropic.types import TextBlock
from anthropic.types.beta.tools import ToolUseBlock

anthropic_model_enable = True
except ImportError:
anthropic_model_enable = False


class ClaudeModel(BackendModel):
def __init__(
Expand All @@ -29,6 +34,8 @@ def __init__(
parameters: dict[str, Any] = dict(),
history_messages_len: int = 0,
) -> None:
if anthropic_model_enable is False:
raise ImportError("Please install anthropic to use ClaudeModel")
super().__init__(
model,
parameters,
Expand Down
20 changes: 13 additions & 7 deletions crab/agents/backend_models/gemini_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
from time import sleep
from typing import Any

import google.generativeai as genai
from google.ai.generativelanguage_v1beta import FunctionDeclaration, Part, Tool
from google.api_core.exceptions import ResourceExhausted
from google.generativeai.types import content_types

from crab import Action, ActionOutput, BackendModel, BackendOutput, MessageType
from crab.utils.common import base64_to_image, json_expand_refs

try:
import google.generativeai as genai
from google.ai.generativelanguage_v1beta import FunctionDeclaration, Part, Tool
from google.api_core.exceptions import ResourceExhausted
from google.generativeai.types import content_types

gemini_model_enable = True
except ImportError:
gemini_model_enable = False


class GeminiModel(BackendModel):
def __init__(
Expand All @@ -31,6 +36,8 @@ def __init__(
parameters: dict[str, Any] = dict(),
history_messages_len: int = 0,
) -> None:
if gemini_model_enable is False:
raise ImportError("Please install google.generativeai to use GeminiModel")
super().__init__(
model,
parameters,
Expand Down Expand Up @@ -162,7 +169,6 @@ def _clear_schema(cls, schema_dict: dict):
if "items" in schema_dict:
cls._clear_schema(schema_dict["items"])


@classmethod
def _action_to_funcdec(cls, action: Action, env: str):
"Converts crab Action to google FunctionDeclaration"
Expand All @@ -174,4 +180,4 @@ def _action_to_funcdec(cls, action: Action, env: str):
name=action.name + "__in__" + env,
description="In {} environment, {}".format(env, action.description),
parameters=p_schema,
)
)
13 changes: 10 additions & 3 deletions crab/agents/backend_models/openai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
import json
from typing import Any

import openai
from openai.types.chat import ChatCompletion

from crab import Action, ActionOutput, BackendModel, BackendOutput, MessageType

try:
import openai
from openai.types.chat import ChatCompletion

openai_model_enable = True
except ImportError:
openai_model_enable = False


class OpenAIModel(BackendModel):
def __init__(
Expand All @@ -27,6 +32,8 @@ def __init__(
parameters: dict[str, Any] = dict(),
history_messages_len: int = 0,
) -> None:
if not openai_model_enable:
raise ImportError("Please install openai to use OpenAIModel")
super().__init__(
model,
parameters,
Expand Down
Loading

0 comments on commit 0d0684b

Please sign in to comment.