Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies = [
# Core Dependencies
"pydantic>=2.4.2",
"openai>=1.13.3",
"litellm==1.60.2",
"litellm==1.66.3",
"instructor>=1.3.3",
# Text Processing
"pdfplumber>=0.11.4",
Expand Down
48 changes: 48 additions & 0 deletions tests/litellm_update_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from unittest.mock import MagicMock, patch

import pytest

from crewai.llm import LLM


def test_llm_call_with_litellm_1_66_3():
"""Test that the LLM class works with litellm v1.66.3+"""
llm = LLM(
model="gpt-3.5-turbo",
temperature=0.7,
max_tokens=50,
stop=["STOP"],
presence_penalty=0.1,
frequency_penalty=0.1,
)
messages = [{"role": "user", "content": "Say 'Hello, World!' and then say STOP"}]

with patch("litellm.completion") as mocked_completion:
mock_message = MagicMock()
mock_message.content = "Hello, World! I won't say the stop word."
mock_choice = MagicMock()
mock_choice.message = mock_message
mock_response = MagicMock()
mock_response.choices = [mock_choice]
mock_response.usage = {
"prompt_tokens": 10,
"completion_tokens": 10,
"total_tokens": 20,
}

mocked_completion.return_value = mock_response

response = llm.call(messages)

mocked_completion.assert_called_once()

assert "Hello, World!" in response
assert "STOP" not in response

_, kwargs = mocked_completion.call_args
assert kwargs["model"] == "gpt-3.5-turbo"
assert kwargs["temperature"] == 0.7
assert kwargs["max_tokens"] == 50
assert kwargs["stop"] == ["STOP"]
assert kwargs["presence_penalty"] == 0.1
assert kwargs["frequency_penalty"] == 0.1
12 changes: 6 additions & 6 deletions uv.lock

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

Loading