mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
* fix: remove aws params from bedrock embedding request body (#8618) * fix: remove aws params from bedrock embedding request body * fix-7548: handle aws params in base class * test: load request data from mock call * (Infra/DB) - Allow running older litellm version when out of sync with current state of DB (#8695) * fix check migration * clean up should_update_prisma_schema * update test * db_migration_disable_update_check * Check container logs for expected message * db_migration_disable_update_check * test_check_migration_out_of_sync * test_should_update_prisma_schema * db_migration_disable_update_check * pip install aiohttp * ui new build * delete deprecated code test * bump: version 1.61.12 → 1.61.13 * Add cost tracking for rerank via bedrock (#8691) * feat(bedrock/rerank): infer model region if model given as arn * test: add unit testing to ensure bedrock region name inferred from arn on rerank * feat(bedrock/rerank/transformation.py): include search units for bedrock rerank result Resolves https://github.com/BerriAI/litellm/issues/7258#issuecomment-2671557137 * test(test_bedrock_completion.py): add testing for bedrock cohere rerank * feat(cost_calculator.py): refactor rerank cost tracking to support bedrock cost tracking * build(model_prices_and_context_window.json): add amazon.rerank model to model cost map * fix(cost_calculator.py): bedrock/common_utils.py get base model from model w/ arn -> handles rerank model * build(model_prices_and_context_window.json): add bedrock cohere rerank pricing * feat(bedrock/rerank): migrate bedrock config to basererank config * Revert "feat(bedrock/rerank): migrate bedrock config to basererank config" This reverts commit84fae1f167
. * test: add testing to ensure large doc / queries are correctly counted * Revert "test: add testing to ensure large doc / queries are correctly counted" This reverts commit4337f1657e
. * fix(migrate-jina-ai-to-rerank-config): enables cost tracking * refactor(jina_ai/): finish migrating jina ai to base rerank config enables cost tracking * fix(jina_ai/rerank): e2e jina ai rerank cost tracking * fix: cleanup dead code * fix: fix python3.8 compatibility error * test: fix test * test: add e2e testing for azure ai rerank * fix: fix linting error * test: mark cohere as flaky * add bedrock llama vision support + cohere / infinity rerank - 'return_documents' support (#8684) * build(model_prices_and_context_window.json): mark bedrock llama as supporting vision based on docs * Add price for Cerebras llama3.3-70b (#8676) * docs(readme.md): fix contributing docs point people to new mock directory testing structure s/o @vibhavbhat * build: update contributing readme * docs(readme.md): improve docs * docs(readme.md): cleanup readme on tests/ * docs(README.md): cleanup doc * feat(infinity/): support returning documents when return_documents=True * test(test_rerank.py): add e2e testing for cohere rerank * fix: fix linting errors * fix(together_ai/): fix together ai transformation * fix: fix linting error * fix: fix linting errors * fix: fix linting errors * test: mark cohere as flaky * build: fix model supports check * test: fix test * test: mark flaky test * fix: fix test * test: fix test --------- Co-authored-by: Yury Koleda <fut.wrk@gmail.com> * test: fix test * fix: remove unused import * bump: version 1.61.13 → 1.61.14 * Correct spelling in user_management_heirarchy.md (#8716) Fixing irritating typo -- page and image names would also need to be updated * (Feat) - UI, Allow sorting models by Created_At and all other columns on the UI (#8725) * order models by created at * use existing table component on models page * sorting for created at * ui clean up models page * remove provider filter * fix columns sorting * decent switching * ui fix models page * (UI) Edit Model flow improvements (#8729) * order models by created at * use existing table component on models page * sorting for created at * ui clean up models page * remove provider filter * fix columns sorting * decent switching * ui fix models page * show edit / delete button on root of table * clean up columns * working edit model flow * decent working model edit page * fix edit model * show created at and created by * ui easy model edit flow * clean up columns * ui clean up updated at * fix model datatable * ui new build * bump: version 1.61.14 → 1.61.15 * Support arize phoenix on litellm proxy (#7756) (#8715) * Update opentelemetry.py wip * Update test_opentelemetry_unit_tests.py * fix a few paths and tests * fix path * Update litellm_logging.py * accidentally removed code * Add type for protocol * Add and update tests * minor changes * update and add additional arize phoenix test * update existing test * address feedback * use standard_logging_object * address feedback Co-authored-by: Nate Mar <67926244+nate-mar@users.noreply.github.com> * fix(amazon_deepseek_transformation.py): remove </think> from stream o… (#8717) * fix(amazon_deepseek_transformation.py): remove </think> from stream output - cleanup user facing stream * fix(key_managenet_endpoints.py): return `/key/list` sorted by created_at makes it easier to see created key * style: cleanup team table * feat(key_edit_view.tsx): support setting model specific tpm/rpm limits on keys * Add cohere v2/rerank support (#8421) (#8605) * Add cohere v2/rerank support (#8421) * Support v2 endpoint cohere rerank * Add tests and docs * Make v1 default if old params used * Update docs * Update docs pt 2 * Update tests * Add e2e test * Clean up code * Use inheritence for new config * Fix linting issues (#8608) * Fix cohere v2 failing test + linting (#8672) * Fix test and unused imports * Fix tests * fix: fix linting errors * test: handle tgai instability * fix: skip service unavailable err * test: print logs for unstable test * test: skip unreliable tests --------- Co-authored-by: vibhavbhat <vibhavb00@gmail.com> * fix(proxy/_types.py): fixes issue where internal user able to escalat… (#8740) * fix(proxy/_types.py): fixes issue where internal user able to escalate their role with ui key Fixes https://github.com/BerriAI/litellm/issues/8029 * style: cleanup * test: handle bedrock instability --------- Co-authored-by: Madhukar Holla <mholla8@gmail.com> Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com> Co-authored-by: Yury Koleda <fut.wrk@gmail.com> Co-authored-by: Oskar Austegard <oskar@austegard.com> Co-authored-by: Nate Mar <67926244+nate-mar@users.noreply.github.com> Co-authored-by: vibhavbhat <vibhavb00@gmail.com>
78 lines
3.3 KiB
Python
78 lines
3.3 KiB
Python
import json
|
|
import os
|
|
import sys
|
|
from datetime import datetime
|
|
from unittest.mock import AsyncMock, Mock, patch
|
|
import pytest
|
|
import base64
|
|
import httpx
|
|
|
|
sys.path.insert(
|
|
0, os.path.abspath("../..")
|
|
) # Adds the parent directory to the system path
|
|
|
|
import litellm
|
|
from litellm.llms.custom_httpx.http_handler import HTTPHandler, AsyncHTTPHandler
|
|
|
|
titan_embedding_response = {
|
|
"embedding": [0.1, 0.2, 0.3],
|
|
"inputTextTokenCount": 10
|
|
}
|
|
|
|
cohere_embedding_response = {
|
|
"embeddings": [[0.1, 0.2, 0.3]],
|
|
"inputTextTokenCount": 10
|
|
}
|
|
|
|
img_base_64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkBAMAAACCzIhnAAAAG1BMVEURAAD///+ln5/h39/Dv79qX18uHx+If39MPz9oMSdmAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABB0lEQVRYhe2SzWrEIBCAh2A0jxEs4j6GLDS9hqWmV5Flt0cJS+lRwv742DXpEjY1kOZW6HwHFZnPmVEBEARBEARB/jd0KYA/bcUYbPrRLh6amXHJ/K+ypMoyUaGthILzw0l+xI0jsO7ZcmCcm4ILd+QuVYgpHOmDmz6jBeJImdcUCmeBqQpuqRIbVmQsLCrAalrGpfoEqEogqbLTWuXCPCo+Ki1XGqgQ+jVVuhB8bOaHkvmYuzm/b0KYLWwoK58oFqi6XfxQ4Uz7d6WeKpna6ytUs5e8betMcqAv5YPC5EZB2Lm9FIn0/VP6R58+/GEY1X1egVoZ/3bt/EqF6malgSAIgiDIH+QL41409QMY0LMAAAAASUVORK5CYII="
|
|
|
|
@pytest.mark.parametrize(
|
|
"model,input_type,embed_response",
|
|
[
|
|
("bedrock/amazon.titan-embed-text-v1", "text", titan_embedding_response), # V1 text model
|
|
("bedrock/amazon.titan-embed-text-v2:0", "text", titan_embedding_response), # V2 text model
|
|
("bedrock/amazon.titan-embed-image-v1", "image", titan_embedding_response), # Image model
|
|
("bedrock/cohere.embed-english-v3", "text", cohere_embedding_response), # Cohere English
|
|
("bedrock/cohere.embed-multilingual-v3", "text", cohere_embedding_response), # Cohere Multilingual
|
|
],
|
|
)
|
|
def test_bedrock_embedding_models(model, input_type, embed_response):
|
|
"""Test embedding functionality for all Bedrock models with different input types"""
|
|
litellm.set_verbose = True
|
|
client = HTTPHandler()
|
|
|
|
with patch.object(client, "post") as mock_post:
|
|
mock_response = Mock()
|
|
mock_response.status_code = 200
|
|
mock_response.text = json.dumps(embed_response)
|
|
mock_response.json = lambda: json.loads(mock_response.text)
|
|
mock_post.return_value = mock_response
|
|
|
|
# Prepare input based on type
|
|
input_data = img_base_64 if input_type == "image" else "Hello world from litellm"
|
|
|
|
try:
|
|
response = litellm.embedding(
|
|
model=model,
|
|
input=input_data,
|
|
client=client,
|
|
aws_region_name="us-west-2",
|
|
aws_bedrock_runtime_endpoint="https://bedrock-runtime.us-west-2.amazonaws.com",
|
|
)
|
|
|
|
# Verify response structure
|
|
assert isinstance(response, litellm.EmbeddingResponse)
|
|
print(response.data)
|
|
assert isinstance(response.data[0]['embedding'], list)
|
|
assert len(response.data[0]['embedding']) == 3 # Based on mock response
|
|
|
|
# Fetch request body
|
|
request_data = json.loads(mock_post.call_args.kwargs["data"])
|
|
|
|
# Verify AWS params are not in request body
|
|
aws_params = ["aws_region_name", "aws_bedrock_runtime_endpoint"]
|
|
for param in aws_params:
|
|
assert param not in request_data, f"AWS param {param} should not be in request body"
|
|
|
|
except Exception as e:
|
|
pytest.fail(f"Error occurred: {e}")
|