Skip to content

Commit

Permalink
Merge pull request #136 from devchat-ai/remove_litellm_package
Browse files Browse the repository at this point in the history
use cl100k_base to count tokens
  • Loading branch information
basicthinker committed Oct 1, 2023
2 parents 3bba86d + df1ae10 commit ad67bbc
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 57 deletions.
1 change: 0 additions & 1 deletion devchat/_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .optimize import *
from .log import log
from .prompt import prompt
from .run import run
Expand Down
14 changes: 0 additions & 14 deletions devchat/_cli/optimize.py

This file was deleted.

8 changes: 4 additions & 4 deletions devchat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Client(str, Enum):
OPENAI = "openai"
ANTHROPIC = "anthropic"
LITELLM = "litellm"
GENERAL = "general"


class ProviderConfig(BaseModel):
Expand Down Expand Up @@ -90,7 +90,7 @@ def _load_and_validate_config(self) -> ChatConfig:
data['providers'][provider] = OpenAIProviderConfig(**config)
elif config['client'] == "anthropic":
data['providers'][provider] = AnthropicProviderConfig(**config)
elif config['client'] == "litellm":
else:
data['providers'][provider] = ProviderConfig(**config)
for model, config in data['models'].items():
if 'provider' not in config:
Expand All @@ -101,7 +101,7 @@ def _load_and_validate_config(self) -> ChatConfig:
data['models'][model] = OpenAIModelConfig(**config)
elif provider.client == Client.ANTHROPIC:
data['models'][model] = AnthropicModelConfig(**config)
elif provider.client == Client.LITELLM:
else:
data['models'][model] = GeneralModelConfig(**config)

return ChatConfig(**data)
Expand Down Expand Up @@ -146,7 +146,7 @@ def _create_sample_file(self):
api_key=""
),
"general": ProviderConfig(
client=Client.LITELLM
client=Client.GENERAL
)
},
models={
Expand Down
7 changes: 2 additions & 5 deletions devchat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import datetime
import hashlib
import tiktoken
from litellm import token_counter


encoding = tiktoken.get_encoding("cl100k_base")
Expand Down Expand Up @@ -207,11 +206,9 @@ def _count_tokens(encoding_tik: tiktoken.Encoding, string: str) -> int:
return int(word_count / 0.75)


def openai_message_tokens(message: dict, model: str) -> int:
def openai_message_tokens(messages: dict, model: str) -> int: # pylint: disable=unused-argument
"""Returns the number of tokens used by a message."""
if "claude" in model:
return token_counter(model=model, text=str(message))
return len(encoding.encode(str(message)))
return len(encoding.encode(str(messages)))


def openai_response_tokens(message: dict, model: str) -> int:
Expand Down
33 changes: 1 addition & 32 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ urllib3 = "<2.0"
importlib-metadata = "^6.8.0"
pyyaml = "^6.0.1"
gitpython = "^3.1.32"
litellm = "^0.1.538"
anthropic = "^0.3.11"

[tool.poetry.scripts]
Expand Down

0 comments on commit ad67bbc

Please sign in to comment.