mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
* test: drop the cwd-relative sys.path.insert calls from the test suite
TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.
Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.
Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.
* test: drop the duplicate imports the sys.path sweep exposed to F811
* test(pre-call-utils): restore the os import the new bedrock tests need
86 lines
2.4 KiB
Python
86 lines
2.4 KiB
Python
import traceback
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
import litellm.types
|
|
|
|
load_dotenv()
|
|
import io
|
|
import json
|
|
|
|
from unittest.mock import AsyncMock, Mock, patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.skip(reason="Skipping bedrock agents test - arn not working")
|
|
async def test_bedrock_agents():
|
|
litellm._turn_on_debug()
|
|
response = litellm.completion(
|
|
model="bedrock/agent/L1RT58GYRW/MFPSBCXYTW",
|
|
messages=[{"role": "user", "content": "Hi just respond with a ping message"}],
|
|
)
|
|
|
|
#########################################################
|
|
#########################################################
|
|
print("response from agent=", response.model_dump_json(indent=4))
|
|
|
|
# assert that the message content has a response with some length
|
|
assert len(response.choices[0].message.content) > 0
|
|
|
|
# assert we were able to get the response cost
|
|
assert (
|
|
response._hidden_params["response_cost"] is not None
|
|
and response._hidden_params["response_cost"] > 0
|
|
)
|
|
|
|
pass
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.skip(reason="Skipping bedrock agents test - arn not working")
|
|
async def test_bedrock_agents_with_streaming():
|
|
# litellm._turn_on_debug()
|
|
response = litellm.completion(
|
|
model="bedrock/agent/L1RT58GYRW/MFPSBCXYTW",
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": "Hi who is ishaan cto of litellm, tell me 10 things about him",
|
|
}
|
|
],
|
|
stream=True,
|
|
)
|
|
|
|
for chunk in response:
|
|
print("final chunk=", chunk)
|
|
|
|
pass
|
|
|
|
|
|
def test_bedrock_agents_with_custom_params():
|
|
litellm._turn_on_debug()
|
|
from unittest.mock import MagicMock
|
|
from litellm.llms.custom_httpx.http_handler import HTTPHandler
|
|
|
|
client = HTTPHandler()
|
|
|
|
with patch.object(client, "post", return_value=MagicMock()) as mock_post:
|
|
try:
|
|
response = litellm.completion(
|
|
model="bedrock/agent/L1RT58GYRW/MFPSBCXYTW",
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": "Hi who is ishaan cto of litellm, tell me 10 things about him",
|
|
}
|
|
],
|
|
invocationId="my-test-invocation-id",
|
|
client=client,
|
|
)
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
mock_post.assert_called_once()
|
|
print(f"mock_post.call_args.kwargs: {mock_post.call_args.kwargs}")
|