Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

chore: drop tiktoken from anthropic async max_tokens test

Greyson LaLonde298fc7b9c027
diff --git a/lib/crewai/tests/llms/anthropic/test_anthropic_async.py b/lib/crewai/tests/llms/anthropic/test_anthropic_async.py
index 3c1d01ea3..431abc6ef 100644
--- a/lib/crewai/tests/llms/anthropic/test_anthropic_async.py
+++ b/lib/crewai/tests/llms/anthropic/test_anthropic_async.py
@@ -3,13 +3,9 @@ import json
import logging
import pytest
-import tiktoken
from pydantic import BaseModel
from crewai.llm import LLM
-
-# Pre-cache tiktoken encoding so VCR doesn't intercept the download request
-tiktoken.get_encoding("cl100k_base")
from crewai.llms.providers.anthropic.completion import AnthropicCompletion
@@ -48,9 +44,7 @@ async def test_anthropic_async_with_max_tokens():
assert result is not None
assert isinstance(result, str)
- encoder = tiktoken.get_encoding("cl100k_base")
- token_count = len(encoder.encode(result))
- assert token_count <= 10
+ assert len(result.split()) <= 10
@pytest.mark.vcr()
diff --git a/lib/crewai/tests/llms/azure/test_azure_async.py b/lib/crewai/tests/llms/azure/test_azure_async.py
index 1bbd9cf4c..2bb1cc7f0 100644
--- a/lib/crewai/tests/llms/azure/test_azure_async.py
+++ b/lib/crewai/tests/llms/azure/test_azure_async.py
@@ -1,7 +1,6 @@
"""Tests for Azure async completion functionality."""
import pytest
-import tiktoken
from crewai import Agent, Task, Crew
from crewai.llm import LLM
@@ -57,9 +56,7 @@ async def test_azure_async_with_max_tokens():
assert result is not None
assert isinstance(result, str)
- encoder = tiktoken.get_encoding("cl100k_base")
- token_count = len(encoder.encode(result))
- assert token_count <= 10
+ assert len(result.split()) <= 10
@pytest.mark.vcr()
diff --git a/lib/crewai/tests/llms/bedrock/test_bedrock_async.py b/lib/crewai/tests/llms/bedrock/test_bedrock_async.py
index 10d6a7d3d..0bf3558b1 100644
--- a/lib/crewai/tests/llms/bedrock/test_bedrock_async.py
+++ b/lib/crewai/tests/llms/bedrock/test_bedrock_async.py
@@ -6,7 +6,6 @@ cannot be played back properly in CI.
"""
import pytest
-import tiktoken
from crewai.llm import LLM
@@ -51,9 +50,7 @@ async def test_bedrock_async_with_max_tokens():
assert result is not None
assert isinstance(result, str)
- encoder = tiktoken.get_encoding("cl100k_base")
- token_count = len(encoder.encode(result))
- assert token_count <= 10
+ assert len(result.split()) <= 10
@pytest.mark.vcr()
diff --git a/lib/crewai/tests/llms/google/test_google_async.py b/lib/crewai/tests/llms/google/test_google_async.py
index 1385ba74e..d524f620a 100644
--- a/lib/crewai/tests/llms/google/test_google_async.py
+++ b/lib/crewai/tests/llms/google/test_google_async.py
@@ -1,7 +1,6 @@
"""Tests for Google (Gemini) async completion functionality."""
import pytest
-import tiktoken
from crewai import Agent, Task, Crew
from crewai.llm import LLM
@@ -43,9 +42,7 @@ async def test_gemini_async_with_max_tokens():
assert result is not None
assert isinstance(result, str)
- encoder = tiktoken.get_encoding("cl100k_base")
- token_count = len(encoder.encode(result))
- assert token_count <= 1000
+ assert len(result.split()) <= 1000
@pytest.mark.vcr()
diff --git a/lib/crewai/tests/llms/litellm/test_litellm_async.py b/lib/crewai/tests/llms/litellm/test_litellm_async.py
index e8d61a6a5..41707f868 100644
--- a/lib/crewai/tests/llms/litellm/test_litellm_async.py
+++ b/lib/crewai/tests/llms/litellm/test_litellm_async.py
@@ -1,7 +1,6 @@
"""Tests for LiteLLM fallback async completion functionality."""
import pytest
-import tiktoken
from crewai.llm import LLM
@@ -44,9 +43,7 @@ async def test_litellm_async_with_max_tokens():
assert result is not None
assert isinstance(result, str)
- encoder = tiktoken.get_encoding("cl100k_base")
- token_count = len(encoder.encode(result))
- assert token_count <= 10
+ assert len(result.split()) <= 10
@pytest.mark.asyncio
diff --git a/lib/crewai/tests/llms/openai/test_openai_async.py b/lib/crewai/tests/llms/openai/test_openai_async.py
index e6bbf11d9..e5dae7ca7 100644
--- a/lib/crewai/tests/llms/openai/test_openai_async.py
+++ b/lib/crewai/tests/llms/openai/test_openai_async.py
@@ -1,7 +1,6 @@
"""Tests for OpenAI async completion functionality."""
import pytest
-import tiktoken
from crewai import Agent, Task, Crew
from crewai.llm import LLM
@@ -42,9 +41,7 @@ async def test_openai_async_with_max_tokens():
assert result is not None
assert isinstance(result, str)
- encoder = tiktoken.get_encoding("cl100k_base")
- token_count = len(encoder.encode(result))
- assert token_count <= 10
+ assert len(result.split()) <= 10
@pytest.mark.vcr()