Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop litellm version to prevent windows issue #1878

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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.44.22",
"litellm==1.57.4",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"instructor>=1.3.3",

# Text Processing
Expand Down
4 changes: 0 additions & 4 deletions src/crewai/utilities/llm_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import os
from typing import Any, Dict, List, Optional, Union

from packaging import version

from crewai.cli.constants import DEFAULT_LLM_MODEL, ENV_VARS, LITELLM_PARAMS
from crewai.cli.utils import read_toml
from crewai.cli.version import get_crewai_version
from crewai.llm import LLM


Expand Down
459 changes: 436 additions & 23 deletions tests/cassettes/test_agent_execute_task_with_ollama.yaml

Large diffs are not rendered by default.

867 changes: 847 additions & 20 deletions tests/cassettes/test_agent_with_ollama_llama3.yaml

Large diffs are not rendered by default.

864 changes: 846 additions & 18 deletions tests/cassettes/test_llm_call_with_ollama_llama3.yaml

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions tests/cassettes/test_llm_callback_replacement.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
interactions:
- request:
body: '{"messages": [{"role": "user", "content": "Hello, world!"}], "model": "gpt-4o-mini",
"stream": false}'
body: '{"messages": [{"role": "user", "content": "Hello, world!"}], "model": "gpt-4o-mini"}'
headers:
accept:
- application/json
Expand All @@ -10,13 +9,13 @@ interactions:
connection:
- keep-alive
content-length:
- '101'
- '84'
content-type:
- application/json
host:
- api.openai.com
user-agent:
- OpenAI/Python 1.52.1
- OpenAI/Python 1.59.6
x-stainless-arch:
- arm64
x-stainless-async:
Expand All @@ -26,7 +25,7 @@ interactions:
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.52.1
- 1.59.6
x-stainless-raw-response:
- 'true'
x-stainless-retry-count:
Expand All @@ -38,37 +37,37 @@ interactions:
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
content: "{\n \"id\": \"chatcmpl-AcdBV2knOF2soWLszceiA08K8W8nE\",\n \"object\":
\"chat.completion\",\n \"created\": 1733770453,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n
content: "{\n \"id\": \"chatcmpl-AoEzIjusutsoPh1EmGgeXifkYvbfH\",\n \"object\":
\"chat.completion\",\n \"created\": 1736537376,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n
\ \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\":
\"assistant\",\n \"content\": \"Hello! How can I assist you today?\",\n
\ \"refusal\": null\n },\n \"logprobs\": null,\n \"finish_reason\":
\"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 11,\n \"completion_tokens\":
9,\n \"total_tokens\": 20,\n \"prompt_tokens_details\": {\n \"cached_tokens\":
10,\n \"total_tokens\": 21,\n \"prompt_tokens_details\": {\n \"cached_tokens\":
0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": {\n
\ \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\":
0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"system_fingerprint\":
\"fp_bba3c8e70b\"\n}\n"
0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\":
\"default\",\n \"system_fingerprint\": \"fp_01aeff40ea\"\n}\n"
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 8ef733d51801bada-ATL
- 8fff13aa78db4569-ATL
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Mon, 09 Dec 2024 18:54:13 GMT
- Fri, 10 Jan 2025 19:29:36 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=_fEt57lre0.E_IZaebjaDAcrpBbzGhLWW6KtQ4FjLxo-1733770453-1.0.1.1-ndzEQCfExSp1asSdBXxS0fGYQnKVTivInc1MHN.ZjnmGmkAmEp0EPwiJlcAMvQaMCMZ7a_vKqAEMbz8ZbzTYYg;
path=/; expires=Mon, 09-Dec-24 19:24:13 GMT; domain=.api.openai.com; HttpOnly;
- __cf_bm=PoW0e3SDy04AxLoIfTXlp2oFUuTGjQzesTybc7KXe28-1736537376-1.0.1.1-tznDR3VZpUOrVUyHmDUYYtpSQ2WI3X6ya9EhOwgNEMVIe6KsDgje4tO7z_tk7l0cuRww1jx_ryG3sgT1AETdVw;
path=/; expires=Fri, 10-Jan-25 19:59:36 GMT; domain=.api.openai.com; HttpOnly;
Secure; SameSite=None
- _cfuvid=2gTS3no9rova7t6URcfR30yzeZdKkL.9.lvsZXgmbVw-1733770453657-0.0.1.1-604800000;
- _cfuvid=3UeEmz_rnmsoZxrVUv32u35gJOi766GDWNe5_RTjiPk-1736537376739-0.0.1.1-604800000;
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
Transfer-Encoding:
- chunked
Expand All @@ -81,7 +80,7 @@ interactions:
openai-organization:
- crewai-iuxna1
openai-processing-ms:
- '275'
- '286'
openai-version:
- '2020-10-01'
strict-transport-security:
Expand All @@ -99,12 +98,12 @@ interactions:
x-ratelimit-reset-tokens:
- 0s
x-request-id:
- req_82ef8940a3291813e6a347535ab6bf26
- req_18f5593ddf37824bb9a7690407170dc0
http_version: HTTP/1.1
status_code: 200
- request:
body: '{"messages": [{"role": "user", "content": "Hello, world from another agent!"}],
"model": "gpt-4o-mini", "stream": false}'
"model": "gpt-4o-mini"}'
headers:
accept:
- application/json
Expand All @@ -113,16 +112,16 @@ interactions:
connection:
- keep-alive
content-length:
- '120'
- '103'
content-type:
- application/json
cookie:
- __cf_bm=_fEt57lre0.E_IZaebjaDAcrpBbzGhLWW6KtQ4FjLxo-1733770453-1.0.1.1-ndzEQCfExSp1asSdBXxS0fGYQnKVTivInc1MHN.ZjnmGmkAmEp0EPwiJlcAMvQaMCMZ7a_vKqAEMbz8ZbzTYYg;
_cfuvid=2gTS3no9rova7t6URcfR30yzeZdKkL.9.lvsZXgmbVw-1733770453657-0.0.1.1-604800000
- __cf_bm=PoW0e3SDy04AxLoIfTXlp2oFUuTGjQzesTybc7KXe28-1736537376-1.0.1.1-tznDR3VZpUOrVUyHmDUYYtpSQ2WI3X6ya9EhOwgNEMVIe6KsDgje4tO7z_tk7l0cuRww1jx_ryG3sgT1AETdVw;
_cfuvid=3UeEmz_rnmsoZxrVUv32u35gJOi766GDWNe5_RTjiPk-1736537376739-0.0.1.1-604800000
host:
- api.openai.com
user-agent:
- OpenAI/Python 1.52.1
- OpenAI/Python 1.59.6
x-stainless-arch:
- arm64
x-stainless-async:
Expand All @@ -132,7 +131,7 @@ interactions:
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.52.1
- 1.59.6
x-stainless-raw-response:
- 'true'
x-stainless-retry-count:
Expand All @@ -144,30 +143,31 @@ interactions:
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
content: "{\n \"id\": \"chatcmpl-AcdBWMAembczwWDLdjIRYwtbMLONh\",\n \"object\":
\"chat.completion\",\n \"created\": 1733770454,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n
content: "{\n \"id\": \"chatcmpl-AoEzIOYUDsd7SpYDQeQmbNGS7IBLE\",\n \"object\":
\"chat.completion\",\n \"created\": 1736537376,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n
\ \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\":
\"assistant\",\n \"content\": \"Hello! It\u2019s great to connect with
you. How can I assist you today?\",\n \"refusal\": null\n },\n \"logprobs\":
null,\n \"finish_reason\": \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\":
14,\n \"completion_tokens\": 17,\n \"total_tokens\": 31,\n \"prompt_tokens_details\":
{\n \"cached_tokens\": 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\":
{\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\":
0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"system_fingerprint\":
\"fp_bba3c8e70b\"\n}\n"
\"assistant\",\n \"content\": \"Hello! It's great to connect with another
agent. How can I assist you today?\",\n \"refusal\": null\n },\n
\ \"logprobs\": null,\n \"finish_reason\": \"stop\"\n }\n ],\n
\ \"usage\": {\n \"prompt_tokens\": 14,\n \"completion_tokens\": 18,\n
\ \"total_tokens\": 32,\n \"prompt_tokens_details\": {\n \"cached_tokens\":
0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": {\n
\ \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\":
0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\":
\"default\",\n \"system_fingerprint\": \"fp_01aeff40ea\"\n}\n"
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 8ef733d7bc41bada-ATL
- 8fff13ad8e054569-ATL
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Mon, 09 Dec 2024 18:54:14 GMT
- Fri, 10 Jan 2025 19:29:37 GMT
Server:
- cloudflare
Transfer-Encoding:
Expand All @@ -181,7 +181,7 @@ interactions:
openai-organization:
- crewai-iuxna1
openai-processing-ms:
- '659'
- '422'
openai-version:
- '2020-10-01'
strict-transport-security:
Expand All @@ -199,7 +199,7 @@ interactions:
x-ratelimit-reset-tokens:
- 0s
x-request-id:
- req_da24049df911504f5102825db6b4aea9
- req_366bcd7dfe94e2a2b5640fd9bb1c5a6b
http_version: HTTP/1.1
status_code: 200
version: 1
15 changes: 12 additions & 3 deletions tests/llm_test.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
from time import sleep

import pytest

from crewai.agents.agent_builder.utilities.base_token_process import TokenProcess
from crewai.llm import LLM
from crewai.utilities.token_counter_callback import TokenCalcHandler


# TODO: This test fails without print statement, which makes me think that something is happening asynchronously that we need to eventually fix and dive deeper into at a later date
@pytest.mark.vcr(filter_headers=["authorization"])
def test_llm_callback_replacement():
llm = LLM(model="gpt-4o-mini")
llm1 = LLM(model="gpt-4o-mini")
llm2 = LLM(model="gpt-4o-mini")

calc_handler_1 = TokenCalcHandler(token_cost_process=TokenProcess())
calc_handler_2 = TokenCalcHandler(token_cost_process=TokenProcess())

llm.call(
result1 = llm1.call(
messages=[{"role": "user", "content": "Hello, world!"}],
callbacks=[calc_handler_1],
)
print("result1:", result1)
usage_metrics_1 = calc_handler_1.token_cost_process.get_summary()
print("usage_metrics_1:", usage_metrics_1)

llm.call(
result2 = llm2.call(
messages=[{"role": "user", "content": "Hello, world from another agent!"}],
callbacks=[calc_handler_2],
)
sleep(5)
print("result2:", result2)
usage_metrics_2 = calc_handler_2.token_cost_process.get_summary()
print("usage_metrics_2:", usage_metrics_2)

# The first handler should not have been updated
assert usage_metrics_1.successful_requests == 1
Expand Down
16 changes: 8 additions & 8 deletions uv.lock

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

Loading