Skip to content

Commit

Permalink
chore: move anthropic as optional (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan authored Oct 17, 2024
1 parent 523ebae commit 2466015
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion camel/configs/anthropic_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from typing import List, Union

from anthropic import NOT_GIVEN, NotGiven
from openai._types import NOT_GIVEN, NotGiven

from camel.configs.base_config import BaseConfig

Expand Down
4 changes: 3 additions & 1 deletion camel/models/anthropic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
from typing import Any, Dict, List, Optional, Union

from anthropic import NOT_GIVEN, Anthropic
from openai import NOT_GIVEN

from camel.configs import ANTHROPIC_API_PARAMS, AnthropicConfig
from camel.messages import OpenAIMessage
Expand Down Expand Up @@ -54,6 +54,8 @@ def __init__(
url: Optional[str] = None,
token_counter: Optional[BaseTokenCounter] = None,
) -> None:
from anthropic import Anthropic

if model_config_dict is None:
model_config_dict = AnthropicConfig().as_dict()
api_key = api_key or os.environ.get("ANTHROPIC_API_KEY")
Expand Down
2 changes: 1 addition & 1 deletion camel/utils/token_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from math import ceil
from typing import TYPE_CHECKING, List, Optional

from anthropic import Anthropic
from PIL import Image

from camel.types import (
Expand Down Expand Up @@ -220,6 +219,7 @@ def _count_tokens_from_image(
class AnthropicTokenCounter(BaseTokenCounter):
def __init__(self):
r"""Constructor for the token counter for Anthropic models."""
from anthropic import Anthropic

self.client = Anthropic()
self.tokenizer = self.client.get_tokenizer()
Expand Down

0 comments on commit 2466015

Please sign in to comment.