2024-08-20 23:52:13 +08:00
import os
import sys
2023-11-18 07:51:25 +08:00
import traceback
2024-08-20 23:52:13 +08:00
2023-11-18 07:51:25 +08:00
from dotenv import load_dotenv
load_dotenv ( )
2024-08-20 23:52:13 +08:00
import io
import os
2023-11-18 07:51:25 +08:00
sys . path . insert (
0 , os . path . abspath ( " ../.. " )
) # Adds the parent directory to the system path
import pytest
LiteLLM Minor Fixes & Improvements (11/04/2024) (#6572)
* feat: initial commit for watsonx chat endpoint support
Closes https://github.com/BerriAI/litellm/issues/6562
* feat(watsonx/chat/handler.py): support tool calling for watsonx
Closes https://github.com/BerriAI/litellm/issues/6562
* fix(streaming_utils.py): return empty chunk instead of failing if streaming value is invalid dict
ensures streaming works for ibm watsonx
* fix(openai_like/chat/handler.py): ensure asynchttphandler is passed correctly for openai like calls
* fix: ensure exception mapping works well for watsonx calls
* fix(openai_like/chat/handler.py): handle async streaming correctly
* feat(main.py): Make it clear when a user is passing an invalid message
add validation for user content message
Closes https://github.com/BerriAI/litellm/issues/6565
* fix: cleanup
* fix(utils.py): loosen validation check, to just make sure content types are valid
make litellm robust to future content updates
* fix: fix linting erro
* fix: fix linting errors
* fix(utils.py): make validation check more flexible
* test: handle langfuse list index out of range error
* Litellm dev 11 02 2024 (#6561)
* fix(dual_cache.py): update in-memory check for redis batch get cache
Fixes latency delay for async_batch_redis_cache
* fix(service_logger.py): fix race condition causing otel service logging to be overwritten if service_callbacks set
* feat(user_api_key_auth.py): add parent otel component for auth
allows us to isolate how much latency is added by auth checks
* perf(parallel_request_limiter.py): move async_set_cache_pipeline (from max parallel request limiter) out of execution path (background task)
reduces latency by 200ms
* feat(user_api_key_auth.py): have user api key auth object return user tpm/rpm limits - reduces redis calls in downstream task (parallel_request_limiter)
Reduces latency by 400-800ms
* fix(parallel_request_limiter.py): use batch get cache to reduce user/key/team usage object calls
reduces latency by 50-100ms
* fix: fix linting error
* fix(_service_logger.py): fix import
* fix(user_api_key_auth.py): fix service logging
* fix(dual_cache.py): don't pass 'self'
* fix: fix python3.8 error
* fix: fix init]
* bump: version 1.51.4 → 1.51.5
* build(deps): bump cookie and express in /docs/my-website (#6566)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.
Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)
Updates `express` from 4.20.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.20.0...4.21.1)
---
updated-dependencies:
- dependency-name: cookie
dependency-type: indirect
- dependency-name: express
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* docs(virtual_keys.md): update Dockerfile reference (#6554)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
* (proxy fix) - call connect on prisma client when running setup (#6534)
* critical fix - call connect on prisma client when running setup
* fix test_proxy_server_prisma_setup
* fix test_proxy_server_prisma_setup
* Add 3.5 haiku (#6588)
* feat: add claude-3-5-haiku-20241022 entries
* feat: add claude-3-5-haiku-20241022 and vertex_ai/claude-3-5-haiku@20241022 models
* add missing entries, remove vision
* remove image token costs
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* build: fix map
* build: fix map
* build: fix json for model map
* Litellm dev 11 02 2024 (#6561)
* fix(dual_cache.py): update in-memory check for redis batch get cache
Fixes latency delay for async_batch_redis_cache
* fix(service_logger.py): fix race condition causing otel service logging to be overwritten if service_callbacks set
* feat(user_api_key_auth.py): add parent otel component for auth
allows us to isolate how much latency is added by auth checks
* perf(parallel_request_limiter.py): move async_set_cache_pipeline (from max parallel request limiter) out of execution path (background task)
reduces latency by 200ms
* feat(user_api_key_auth.py): have user api key auth object return user tpm/rpm limits - reduces redis calls in downstream task (parallel_request_limiter)
Reduces latency by 400-800ms
* fix(parallel_request_limiter.py): use batch get cache to reduce user/key/team usage object calls
reduces latency by 50-100ms
* fix: fix linting error
* fix(_service_logger.py): fix import
* fix(user_api_key_auth.py): fix service logging
* fix(dual_cache.py): don't pass 'self'
* fix: fix python3.8 error
* fix: fix init]
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* fix ImageObject conversion (#6584)
* (fix) litellm.text_completion raises a non-blocking error on simple usage (#6546)
* unit test test_huggingface_text_completion_logprobs
* fix return TextCompletionHandler convert_chat_to_text_completion
* fix hf rest api
* fix test_huggingface_text_completion_logprobs
* fix linting errors
* fix importLiteLLMResponseObjectHandler
* fix test for LiteLLMResponseObjectHandler
* fix test text completion
* fix allow using 15 seconds for premium license check
* testing fix bedrock deprecated cohere.command-text-v14
* (feat) add `Predicted Outputs` for OpenAI (#6594)
* bump openai to openai==1.54.0
* add 'prediction' param
* testing fix bedrock deprecated cohere.command-text-v14
* test test_openai_prediction_param.py
* test_openai_prediction_param_with_caching
* doc Predicted Outputs
* doc Predicted Output
* (fix) Vertex Improve Performance when using `image_url` (#6593)
* fix transformation vertex
* test test_process_gemini_image
* test_image_completion_request
* testing fix - bedrock has deprecated cohere.command-text-v14
* fix vertex pdf
* bump: version 1.51.5 → 1.52.0
* fix(lowest_tpm_rpm_routing.py): fix parallel rate limit check (#6577)
* fix(lowest_tpm_rpm_routing.py): fix parallel rate limit check
* fix(lowest_tpm_rpm_v2.py): return headers in correct format
* test: update test
* build(deps): bump cookie and express in /docs/my-website (#6566)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.
Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)
Updates `express` from 4.20.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.20.0...4.21.1)
---
updated-dependencies:
- dependency-name: cookie
dependency-type: indirect
- dependency-name: express
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* docs(virtual_keys.md): update Dockerfile reference (#6554)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
* (proxy fix) - call connect on prisma client when running setup (#6534)
* critical fix - call connect on prisma client when running setup
* fix test_proxy_server_prisma_setup
* fix test_proxy_server_prisma_setup
* Add 3.5 haiku (#6588)
* feat: add claude-3-5-haiku-20241022 entries
* feat: add claude-3-5-haiku-20241022 and vertex_ai/claude-3-5-haiku@20241022 models
* add missing entries, remove vision
* remove image token costs
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* build: fix map
* build: fix map
* build: fix json for model map
* test: remove eol model
* fix(proxy_server.py): fix db config loading logic
* fix(proxy_server.py): fix order of config / db updates, to ensure fields not overwritten
* test: skip test if required env var is missing
* test: fix test
---------
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: paul-gauthier <69695708+paul-gauthier@users.noreply.github.com>
* test: mark flaky test
* test: handle anthropic api instability
* test: update test
* test: bump num retries on langfuse tests - their api is quite bad
---------
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: paul-gauthier <69695708+paul-gauthier@users.noreply.github.com>
2024-11-06 20:23:46 +08:00
from unittest . mock import patch , MagicMock , AsyncMock
2023-11-18 07:51:25 +08:00
import litellm
2024-08-20 23:52:13 +08:00
from litellm import RateLimitError , Timeout , completion , completion_cost , embedding
2023-12-25 16:40:38 +08:00
2023-11-30 02:56:21 +08:00
litellm . num_retries = 0
2023-11-18 07:51:25 +08:00
litellm . cache = None
2023-11-19 07:15:02 +08:00
# litellm.set_verbose=True
2023-11-18 07:51:25 +08:00
import json
2023-11-19 07:15:02 +08:00
# litellm.success_callback = ["langfuse"]
2023-12-25 16:40:38 +08:00
2023-11-18 07:51:25 +08:00
def get_current_weather ( location , unit = " fahrenheit " ) :
""" Get the current weather in a given location """
if " tokyo " in location . lower ( ) :
return json . dumps ( { " location " : " Tokyo " , " temperature " : " 10 " , " unit " : " celsius " } )
elif " san francisco " in location . lower ( ) :
2023-12-25 16:40:38 +08:00
return json . dumps (
{ " location " : " San Francisco " , " temperature " : " 72 " , " unit " : " fahrenheit " }
)
2023-11-18 07:51:25 +08:00
elif " paris " in location . lower ( ) :
return json . dumps ( { " location " : " Paris " , " temperature " : " 22 " , " unit " : " celsius " } )
else :
return json . dumps ( { " location " : location , " temperature " : " unknown " } )
2023-12-25 16:40:38 +08:00
2023-11-18 09:03:24 +08:00
# Example dummy function hard coded to return the same weather
2024-05-14 04:29:43 +08:00
2023-11-18 09:03:24 +08:00
# In production, this could be your backend API or an external API
2024-05-14 04:29:43 +08:00
@pytest.mark.parametrize (
2024-08-20 23:52:13 +08:00
" model " ,
[
2024-09-28 13:52:57 +08:00
" gpt-3.5-turbo-1106 " ,
2024-12-03 13:03:33 +08:00
" mistral/mistral-large-latest " ,
2024-10-03 10:00:28 +08:00
" claude-3-haiku-20240307 " ,
" gemini/gemini-1.5-pro " ,
2024-09-13 14:04:06 +08:00
" anthropic.claude-3-sonnet-20240229-v1:0 " ,
2024-12-03 13:03:33 +08:00
" cohere_chat/command-r " ,
2024-08-20 23:52:13 +08:00
] ,
2024-05-14 04:29:43 +08:00
)
2024-09-10 09:54:17 +08:00
@pytest.mark.flaky ( retries = 3 , delay = 1 )
2024-09-05 07:03:02 +08:00
def test_aaparallel_function_call ( model ) :
2023-11-18 09:03:24 +08:00
try :
2024-08-23 00:59:52 +08:00
litellm . set_verbose = True
2024-10-03 10:00:28 +08:00
litellm . modify_params = True
2023-11-18 09:03:24 +08:00
# Step 1: send the conversation and available functions to the model
2023-12-25 16:40:38 +08:00
messages = [
{
" role " : " user " ,
2024-05-14 04:29:43 +08:00
" content " : " What ' s the weather like in San Francisco, Tokyo, and Paris? - give me 3 responses " ,
2023-12-25 16:40:38 +08:00
}
]
2023-11-18 09:03:24 +08:00
tools = [
{
" type " : " function " ,
" function " : {
" name " : " get_current_weather " ,
" description " : " Get the current weather in a given location " ,
" parameters " : {
" type " : " object " ,
" properties " : {
" location " : {
" type " : " string " ,
2024-05-14 04:29:43 +08:00
" description " : " The city and state " ,
2023-11-18 09:03:24 +08:00
} ,
2023-12-25 16:40:38 +08:00
" unit " : {
" type " : " string " ,
" enum " : [ " celsius " , " fahrenheit " ] ,
} ,
2023-11-18 07:51:25 +08:00
} ,
2023-11-18 09:03:24 +08:00
" required " : [ " location " ] ,
2023-11-18 07:51:25 +08:00
} ,
} ,
2023-11-18 09:03:24 +08:00
}
]
response = litellm . completion (
2024-05-14 04:29:43 +08:00
model = model ,
2023-11-18 07:51:25 +08:00
messages = messages ,
2023-11-18 09:03:24 +08:00
tools = tools ,
tool_choice = " auto " , # auto is default, but we'll be explicit
)
print ( " Response \n " , response )
response_message = response . choices [ 0 ] . message
tool_calls = response_message . tool_calls
print ( " Expecting there to be 3 tool calls " )
2023-12-25 16:40:38 +08:00
assert (
2024-05-14 04:29:43 +08:00
len ( tool_calls ) > 0
) # this has to call the function for SF, Tokyo and paris
2023-11-18 09:03:24 +08:00
# Step 2: check if the model wanted to call a function
2024-09-05 07:03:02 +08:00
print ( f " tool_calls: { tool_calls } " )
2023-11-18 09:03:24 +08:00
if tool_calls :
# Step 3: call the function
# Note: the JSON response may not always be valid; be sure to handle errors
available_functions = {
" get_current_weather " : get_current_weather ,
} # only one function in this example, but you can have multiple
2023-12-25 16:40:38 +08:00
messages . append (
response_message
) # extend conversation with assistant's reply
2023-11-18 09:03:24 +08:00
print ( " Response message \n " , response_message )
# Step 4: send the info for each function call and function response to the model
for tool_call in tool_calls :
function_name = tool_call . function . name
2024-05-16 07:05:17 +08:00
if function_name not in available_functions :
# the model called a function that does not exist in available_functions - don't try calling anything
return
2023-11-18 09:03:24 +08:00
function_to_call = available_functions [ function_name ]
function_args = json . loads ( tool_call . function . arguments )
function_response = function_to_call (
location = function_args . get ( " location " ) ,
unit = function_args . get ( " unit " ) ,
)
messages . append (
{
" tool_call_id " : tool_call . id ,
" role " : " tool " ,
" name " : function_name ,
" content " : function_response ,
}
) # extend conversation with function response
2023-11-30 02:56:21 +08:00
print ( f " messages: { messages } " )
2023-11-18 09:03:24 +08:00
second_response = litellm . completion (
2024-08-20 23:52:13 +08:00
model = model ,
messages = messages ,
temperature = 0.2 ,
seed = 22 ,
2024-10-03 10:00:28 +08:00
# tools=tools,
2024-08-20 23:52:13 +08:00
drop_params = True ,
2023-11-18 09:03:24 +08:00
) # get a new response from the model where it can see the function response
print ( " second response \n " , second_response )
2024-09-05 07:03:02 +08:00
except litellm . InternalServerError as e :
print ( e )
except litellm . RateLimitError as e :
print ( e )
2023-11-18 09:03:24 +08:00
except Exception as e :
pytest . fail ( f " Error occurred: { e } " )
2023-11-19 08:23:28 +08:00
2024-02-27 06:26:58 +08:00
# test_parallel_function_call()
2023-11-19 08:23:28 +08:00
2025-01-08 13:40:33 +08:00
2025-02-25 13:54:30 +08:00
@pytest.mark.parametrize (
" model " ,
[
" anthropic/claude-3-7-sonnet-20250219 " ,
2025-02-27 08:05:33 +08:00
" bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0 " ,
2025-02-25 13:54:30 +08:00
] ,
)
@pytest.mark.flaky ( retries = 3 , delay = 1 )
def test_aaparallel_function_call_with_anthropic_thinking ( model ) :
try :
litellm . _turn_on_debug ( )
litellm . modify_params = True
# Step 1: send the conversation and available functions to the model
messages = [
{
" role " : " user " ,
" content " : " What ' s the weather like in San Francisco, Tokyo, and Paris? - give me 3 responses " ,
}
]
tools = [
{
" type " : " function " ,
" function " : {
" name " : " get_current_weather " ,
" description " : " Get the current weather in a given location " ,
" parameters " : {
" type " : " object " ,
" properties " : {
" location " : {
" type " : " string " ,
" description " : " The city and state " ,
} ,
" unit " : {
" type " : " string " ,
" enum " : [ " celsius " , " fahrenheit " ] ,
} ,
} ,
" required " : [ " location " ] ,
} ,
} ,
}
]
response = litellm . completion (
model = model ,
messages = messages ,
tools = tools ,
tool_choice = " auto " , # auto is default, but we'll be explicit
thinking = { " type " : " enabled " , " budget_tokens " : 1024 } ,
)
print ( " Response \n " , response )
response_message = response . choices [ 0 ] . message
tool_calls = response_message . tool_calls
print ( " Expecting there to be 3 tool calls " )
assert (
len ( tool_calls ) > 0
) # this has to call the function for SF, Tokyo and paris
# Step 2: check if the model wanted to call a function
print ( f " tool_calls: { tool_calls } " )
if tool_calls :
# Step 3: call the function
# Note: the JSON response may not always be valid; be sure to handle errors
available_functions = {
" get_current_weather " : get_current_weather ,
} # only one function in this example, but you can have multiple
messages . append (
response_message
) # extend conversation with assistant's reply
print ( " Response message \n " , response_message )
# Step 4: send the info for each function call and function response to the model
for tool_call in tool_calls :
function_name = tool_call . function . name
if function_name not in available_functions :
# the model called a function that does not exist in available_functions - don't try calling anything
return
function_to_call = available_functions [ function_name ]
function_args = json . loads ( tool_call . function . arguments )
function_response = function_to_call (
location = function_args . get ( " location " ) ,
unit = function_args . get ( " unit " ) ,
)
messages . append (
{
" tool_call_id " : tool_call . id ,
" role " : " tool " ,
" name " : function_name ,
" content " : function_response ,
}
) # extend conversation with function response
print ( f " messages: { messages } " )
second_response = litellm . completion (
model = model ,
messages = messages ,
seed = 22 ,
# tools=tools,
drop_params = True ,
thinking = { " type " : " enabled " , " budget_tokens " : 1024 } ,
) # get a new response from the model where it can see the function response
print ( " second response \n " , second_response )
2025-03-05 13:12:16 +08:00
## THIRD RESPONSE
2025-02-25 13:54:30 +08:00
except litellm . InternalServerError as e :
print ( e )
except litellm . RateLimitError as e :
print ( e )
except Exception as e :
pytest . fail ( f " Error occurred: { e } " )
2024-09-28 13:52:57 +08:00
from litellm . types . utils import ChatCompletionMessageToolCall , Function , Message
@pytest.mark.parametrize (
" model, provider " ,
[
(
" anthropic.claude-3-sonnet-20240229-v1:0 " ,
" bedrock " ,
) ,
( " claude-3-haiku-20240307 " , " anthropic " ) ,
] ,
)
@pytest.mark.parametrize (
" messages, expected_error_msg " ,
[
(
[
{
" role " : " user " ,
" content " : " What ' s the weather like in San Francisco, Tokyo, and Paris? - give me 3 responses " ,
} ,
Message (
content = " Here are the current weather conditions for San Francisco, Tokyo, and Paris: " ,
role = " assistant " ,
tool_calls = [
ChatCompletionMessageToolCall (
index = 1 ,
function = Function (
arguments = ' { " location " : " San Francisco, CA " , " unit " : " fahrenheit " } ' ,
name = " get_current_weather " ,
) ,
id = " tooluse_Jj98qn6xQlOP_PiQr-w9iA " ,
type = " function " ,
)
] ,
function_call = None ,
) ,
{
" tool_call_id " : " tooluse_Jj98qn6xQlOP_PiQr-w9iA " ,
" role " : " tool " ,
" name " : " get_current_weather " ,
" content " : ' { " location " : " San Francisco " , " temperature " : " 72 " , " unit " : " fahrenheit " } ' ,
} ,
] ,
True ,
) ,
(
[
{
" role " : " user " ,
" content " : " What ' s the weather like in San Francisco, Tokyo, and Paris? - give me 3 responses " ,
}
] ,
False ,
) ,
] ,
)
def test_parallel_function_call_anthropic_error_msg (
model , provider , messages , expected_error_msg
) :
"""
Anthropic doesn ' t support tool calling without `tools=` param specified.
Ensure this error is thrown when ` tools = ` param is not specified . But tool call requests are made .
Reference Issue : https : / / github . com / BerriAI / litellm / issues / 5747 , https : / / github . com / BerriAI / litellm / issues / 5388
"""
try :
litellm . set_verbose = True
messages = messages
if expected_error_msg :
with pytest . raises ( litellm . UnsupportedParamsError ) as e :
second_response = litellm . completion (
model = model ,
messages = messages ,
temperature = 0.2 ,
seed = 22 ,
drop_params = True ,
) # get a new response from the model where it can see the function response
print ( " second response \n " , second_response )
else :
second_response = litellm . completion (
model = model ,
messages = messages ,
temperature = 0.2 ,
seed = 22 ,
drop_params = True ,
) # get a new response from the model where it can see the function response
print ( " second response \n " , second_response )
except litellm . InternalServerError as e :
print ( e )
except litellm . RateLimitError as e :
print ( e )
except Exception as e :
pytest . fail ( f " Error occurred: { e } " )
2023-11-19 08:23:28 +08:00
def test_parallel_function_call_stream ( ) :
try :
2024-02-27 06:26:58 +08:00
litellm . set_verbose = True
2023-11-19 08:23:28 +08:00
# Step 1: send the conversation and available functions to the model
2023-12-25 16:40:38 +08:00
messages = [
{
" role " : " user " ,
" content " : " What ' s the weather like in San Francisco, Tokyo, and Paris? " ,
}
]
2023-11-19 08:23:28 +08:00
tools = [
{
" type " : " function " ,
" function " : {
" name " : " get_current_weather " ,
" description " : " Get the current weather in a given location " ,
" parameters " : {
" type " : " object " ,
" properties " : {
" location " : {
" type " : " string " ,
" description " : " The city and state, e.g. San Francisco, CA " ,
} ,
2023-12-25 16:40:38 +08:00
" unit " : {
" type " : " string " ,
" enum " : [ " celsius " , " fahrenheit " ] ,
} ,
2023-11-19 08:23:28 +08:00
} ,
" required " : [ " location " ] ,
} ,
} ,
}
]
response = litellm . completion (
model = " gpt-3.5-turbo-1106 " ,
messages = messages ,
tools = tools ,
stream = True ,
tool_choice = " auto " , # auto is default, but we'll be explicit
2023-12-25 16:40:38 +08:00
complete_response = True ,
2023-11-19 08:23:28 +08:00
)
print ( " Response \n " , response )
2023-11-30 02:56:21 +08:00
# for chunk in response:
# print(chunk)
response_message = response . choices [ 0 ] . message
tool_calls = response_message . tool_calls
2023-11-19 08:23:28 +08:00
2023-11-30 02:56:21 +08:00
print ( " length of tool calls " , len ( tool_calls ) )
print ( " Expecting there to be 3 tool calls " )
2023-12-25 16:40:38 +08:00
assert (
len ( tool_calls ) > 1
) # this has to call the function for SF, Tokyo and parise
2023-11-19 08:23:28 +08:00
2023-11-30 02:56:21 +08:00
# Step 2: check if the model wanted to call a function
if tool_calls :
# Step 3: call the function
# Note: the JSON response may not always be valid; be sure to handle errors
available_functions = {
" get_current_weather " : get_current_weather ,
} # only one function in this example, but you can have multiple
2023-12-25 16:40:38 +08:00
messages . append (
response_message
) # extend conversation with assistant's reply
2023-11-30 02:56:21 +08:00
print ( " Response message \n " , response_message )
# Step 4: send the info for each function call and function response to the model
for tool_call in tool_calls :
function_name = tool_call . function . name
function_to_call = available_functions [ function_name ]
function_args = json . loads ( tool_call . function . arguments )
function_response = function_to_call (
location = function_args . get ( " location " ) ,
unit = function_args . get ( " unit " ) ,
)
messages . append (
{
" tool_call_id " : tool_call . id ,
" role " : " tool " ,
" name " : function_name ,
" content " : function_response ,
}
) # extend conversation with function response
print ( f " messages: { messages } " )
second_response = litellm . completion (
2023-12-25 16:40:38 +08:00
model = " gpt-3.5-turbo-1106 " , messages = messages , temperature = 0.2 , seed = 22
2023-11-30 02:56:21 +08:00
) # get a new response from the model where it can see the function response
print ( " second response \n " , second_response )
return second_response
2023-11-19 08:23:28 +08:00
except Exception as e :
pytest . fail ( f " Error occurred: { e } " )
2023-12-25 16:40:38 +08:00
2024-02-27 06:26:58 +08:00
# test_parallel_function_call_stream()
2024-04-15 23:13:05 +08:00
2024-04-20 07:41:23 +08:00
@pytest.mark.skip (
reason = " Flaky test. Groq function calling is not reliable for ci/cd testing. "
)
2024-04-15 23:13:05 +08:00
def test_groq_parallel_function_call ( ) :
litellm . set_verbose = True
try :
# Step 1: send the conversation and available functions to the model
messages = [
{
" role " : " system " ,
" content " : " You are a function calling LLM that uses the data extracted from get_current_weather to answer questions about the weather in San Francisco. " ,
} ,
{
" role " : " user " ,
" content " : " What ' s the weather like in San Francisco? " ,
} ,
]
tools = [
{
" type " : " function " ,
" function " : {
" name " : " get_current_weather " ,
" description " : " Get the current weather in a given location " ,
" parameters " : {
" type " : " object " ,
" properties " : {
" location " : {
" type " : " string " ,
" description " : " The city and state, e.g. San Francisco, CA " ,
} ,
" unit " : {
" type " : " string " ,
" enum " : [ " celsius " , " fahrenheit " ] ,
} ,
} ,
" required " : [ " location " ] ,
} ,
} ,
}
]
response = litellm . completion (
model = " groq/llama2-70b-4096 " ,
messages = messages ,
tools = tools ,
tool_choice = " auto " , # auto is default, but we'll be explicit
)
print ( " Response \n " , response )
response_message = response . choices [ 0 ] . message
2024-04-18 09:32:34 +08:00
if hasattr ( response_message , " tool_calls " ) :
tool_calls = response_message . tool_calls
2024-04-15 23:13:05 +08:00
2024-04-18 09:32:34 +08:00
assert isinstance (
response . choices [ 0 ] . message . tool_calls [ 0 ] . function . name , str
)
assert isinstance (
response . choices [ 0 ] . message . tool_calls [ 0 ] . function . arguments , str
)
2024-04-15 23:13:05 +08:00
2024-04-18 09:32:34 +08:00
print ( " length of tool calls " , len ( tool_calls ) )
2024-04-15 23:13:05 +08:00
2024-04-18 09:32:34 +08:00
# Step 2: check if the model wanted to call a function
if tool_calls :
# Step 3: call the function
# Note: the JSON response may not always be valid; be sure to handle errors
available_functions = {
" get_current_weather " : get_current_weather ,
} # only one function in this example, but you can have multiple
2024-04-15 23:13:05 +08:00
messages . append (
2024-04-18 09:32:34 +08:00
response_message
) # extend conversation with assistant's reply
print ( " Response message \n " , response_message )
# Step 4: send the info for each function call and function response to the model
for tool_call in tool_calls :
function_name = tool_call . function . name
function_to_call = available_functions [ function_name ]
function_args = json . loads ( tool_call . function . arguments )
function_response = function_to_call (
location = function_args . get ( " location " ) ,
unit = function_args . get ( " unit " ) ,
)
2024-08-22 13:28:35 +08:00
2024-04-18 09:32:34 +08:00
messages . append (
{
" tool_call_id " : tool_call . id ,
" role " : " tool " ,
" name " : function_name ,
" content " : function_response ,
}
) # extend conversation with function response
print ( f " messages: { messages } " )
second_response = litellm . completion (
model = " groq/llama2-70b-4096 " , messages = messages
) # get a new response from the model where it can see the function response
print ( " second response \n " , second_response )
2024-04-15 23:13:05 +08:00
except Exception as e :
pytest . fail ( f " Error occurred: { e } " )
2024-10-03 10:00:28 +08:00
@pytest.mark.parametrize (
" model " ,
[
2025-04-08 12:02:52 +08:00
# "anthropic.claude-3-sonnet-20240229-v1:0",
# "claude-3-haiku-20240307",
" databricks/databricks-claude-3-7-sonnet "
2024-10-03 10:00:28 +08:00
] ,
)
def test_anthropic_function_call_with_no_schema ( model ) :
"""
Relevant Issue : https : / / github . com / BerriAI / litellm / issues / 6012
"""
tools = [
{
" type " : " function " ,
" function " : {
" name " : " get_current_weather " ,
" description " : " Get the current weather in New York " ,
} ,
}
]
messages = [
{ " role " : " user " , " content " : " What is the current temperature in New York? " }
]
completion ( model = model , messages = messages , tools = tools , tool_choice = " auto " )
2024-10-29 06:05:20 +08:00
2024-11-02 03:14:32 +08:00
@pytest.mark.parametrize (
" model " ,
[
" bedrock/anthropic.claude-3-sonnet-20240229-v1:0 " ,
] ,
)
def test_passing_tool_result_as_list ( model ) :
2024-10-29 06:05:20 +08:00
litellm . set_verbose = True
2025-08-16 23:08:25 +08:00
litellm . _turn_on_debug ( )
2024-10-29 06:05:20 +08:00
messages = [
{
" content " : [
{
" type " : " text " ,
" text " : " You are a helpful assistant that have the ability to interact with a computer to solve tasks. " ,
}
] ,
" role " : " system " ,
} ,
{
" content " : [
{
" type " : " text " ,
" text " : " Write a git commit message for the current staging area and commit the changes. " ,
}
] ,
" role " : " user " ,
} ,
{
" content " : [
{
" type " : " text " ,
" text " : " I ' ll help you commit the changes. Let me first check the git status to see what changes are staged. " ,
}
] ,
" role " : " assistant " ,
" tool_calls " : [
{
" index " : 1 ,
" function " : {
" arguments " : ' { " command " : " git status " , " thought " : " Checking git status to see staged changes " } ' ,
" name " : " execute_bash " ,
} ,
" id " : " toolu_01V1paXrun4CVetdAGiQaZG5 " ,
" type " : " function " ,
}
] ,
} ,
{
" content " : [
{
" type " : " text " ,
" text " : ' OBSERVATION: \n On branch master \r \n \r \n No commits yet \r \n \r \n Changes to be committed: \r \n (use " git rm --cached <file>... " to unstage) \r \n \t new file: hello.py \r \n \r \n \r \n [Python Interpreter: /openhands/poetry/openhands-ai-5O4_aCHf-py3.12/bin/python] \n root@openhands-workspace:/workspace # \n [Command finished with exit code 0] ' ,
}
] ,
" role " : " tool " ,
" tool_call_id " : " toolu_01V1paXrun4CVetdAGiQaZG5 " ,
2025-08-16 23:08:25 +08:00
" name " : " execute_bash "
2024-10-29 06:05:20 +08:00
} ,
]
tools = [
{
" type " : " function " ,
" function " : {
" name " : " execute_bash " ,
" description " : ' Execute a bash command in the terminal. \n * Long running commands: For commands that may run indefinitely, it should be run in the background and the output should be redirected to a file, e.g. command = `python3 app.py > server.log 2>&1 &`. \n * Interactive: If a bash command returns exit code `-1`, this means the process is not yet finished. The assistant must then send a second call to terminal with an empty `command` (which will retrieve any additional logs), or it can send additional text (set `command` to the text) to STDIN of the running process, or it can send command=`ctrl+c` to interrupt the process. \n * Timeout: If a command execution result says " Command timed out. Sending SIGINT to the process " , the assistant should retry running the command in the background. \n ' ,
" parameters " : {
" type " : " object " ,
" properties " : {
" thought " : {
" type " : " string " ,
" description " : " Reasoning about the action to take. " ,
} ,
" command " : {
" type " : " string " ,
" description " : " The bash command to execute. Can be empty to view additional logs when previous exit code is `-1`. Can be `ctrl+c` to interrupt the currently running process. " ,
} ,
} ,
" required " : [ " command " ] ,
} ,
} ,
} ,
{
" type " : " function " ,
" function " : {
" name " : " finish " ,
" description " : " Finish the interaction. \n * Do this if the task is complete. \n * Do this if the assistant cannot proceed further with the task. \n " ,
} ,
} ,
{
" type " : " function " ,
" function " : {
" name " : " str_replace_editor " ,
" description " : " Custom editing tool for viewing, creating and editing files \n * State is persistent across command calls and discussions with the user \n * If `path` is a file, `view` displays the result of applying `cat -n`. If `path` is a directory, `view` lists non-hidden files and directories up to 2 levels deep \n * The `create` command cannot be used if the specified `path` already exists as a file \n * If a `command` generates a long output, it will be truncated and marked with `<response clipped>` \n * The `undo_edit` command will revert the last edit made to the file at `path` \n \n Notes for using the `str_replace` command: \n * The `old_str` parameter should match EXACTLY one or more consecutive lines from the original file. Be mindful of whitespaces! \n * If the `old_str` parameter is not unique in the file, the replacement will not be performed. Make sure to include enough context in `old_str` to make it unique \n * The `new_str` parameter should contain the edited lines that should replace the `old_str` \n " ,
" parameters " : {
" type " : " object " ,
" properties " : {
" command " : {
" description " : " The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`. " ,
" enum " : [
" view " ,
" create " ,
" str_replace " ,
" insert " ,
" undo_edit " ,
] ,
" type " : " string " ,
} ,
" path " : {
" description " : " Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`. " ,
" type " : " string " ,
} ,
" file_text " : {
" description " : " Required parameter of `create` command, with the content of the file to be created. " ,
" type " : " string " ,
} ,
" old_str " : {
" description " : " Required parameter of `str_replace` command containing the string in `path` to replace. " ,
" type " : " string " ,
} ,
" new_str " : {
" description " : " Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert. " ,
" type " : " string " ,
} ,
" insert_line " : {
" description " : " Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`. " ,
" type " : " integer " ,
} ,
" view_range " : {
" description " : " Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file. " ,
" items " : { " type " : " integer " } ,
" type " : " array " ,
} ,
} ,
" required " : [ " command " , " path " ] ,
} ,
} ,
} ,
]
for _ in range ( 2 ) :
resp = completion ( model = model , messages = messages , tools = tools )
print ( resp )
2024-11-02 03:14:32 +08:00
if model == " claude-3-5-sonnet-20241022 " :
assert resp . usage . prompt_tokens_details . cached_tokens > 0
LiteLLM Minor Fixes & Improvements (11/04/2024) (#6572)
* feat: initial commit for watsonx chat endpoint support
Closes https://github.com/BerriAI/litellm/issues/6562
* feat(watsonx/chat/handler.py): support tool calling for watsonx
Closes https://github.com/BerriAI/litellm/issues/6562
* fix(streaming_utils.py): return empty chunk instead of failing if streaming value is invalid dict
ensures streaming works for ibm watsonx
* fix(openai_like/chat/handler.py): ensure asynchttphandler is passed correctly for openai like calls
* fix: ensure exception mapping works well for watsonx calls
* fix(openai_like/chat/handler.py): handle async streaming correctly
* feat(main.py): Make it clear when a user is passing an invalid message
add validation for user content message
Closes https://github.com/BerriAI/litellm/issues/6565
* fix: cleanup
* fix(utils.py): loosen validation check, to just make sure content types are valid
make litellm robust to future content updates
* fix: fix linting erro
* fix: fix linting errors
* fix(utils.py): make validation check more flexible
* test: handle langfuse list index out of range error
* Litellm dev 11 02 2024 (#6561)
* fix(dual_cache.py): update in-memory check for redis batch get cache
Fixes latency delay for async_batch_redis_cache
* fix(service_logger.py): fix race condition causing otel service logging to be overwritten if service_callbacks set
* feat(user_api_key_auth.py): add parent otel component for auth
allows us to isolate how much latency is added by auth checks
* perf(parallel_request_limiter.py): move async_set_cache_pipeline (from max parallel request limiter) out of execution path (background task)
reduces latency by 200ms
* feat(user_api_key_auth.py): have user api key auth object return user tpm/rpm limits - reduces redis calls in downstream task (parallel_request_limiter)
Reduces latency by 400-800ms
* fix(parallel_request_limiter.py): use batch get cache to reduce user/key/team usage object calls
reduces latency by 50-100ms
* fix: fix linting error
* fix(_service_logger.py): fix import
* fix(user_api_key_auth.py): fix service logging
* fix(dual_cache.py): don't pass 'self'
* fix: fix python3.8 error
* fix: fix init]
* bump: version 1.51.4 → 1.51.5
* build(deps): bump cookie and express in /docs/my-website (#6566)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.
Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)
Updates `express` from 4.20.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.20.0...4.21.1)
---
updated-dependencies:
- dependency-name: cookie
dependency-type: indirect
- dependency-name: express
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* docs(virtual_keys.md): update Dockerfile reference (#6554)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
* (proxy fix) - call connect on prisma client when running setup (#6534)
* critical fix - call connect on prisma client when running setup
* fix test_proxy_server_prisma_setup
* fix test_proxy_server_prisma_setup
* Add 3.5 haiku (#6588)
* feat: add claude-3-5-haiku-20241022 entries
* feat: add claude-3-5-haiku-20241022 and vertex_ai/claude-3-5-haiku@20241022 models
* add missing entries, remove vision
* remove image token costs
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* build: fix map
* build: fix map
* build: fix json for model map
* Litellm dev 11 02 2024 (#6561)
* fix(dual_cache.py): update in-memory check for redis batch get cache
Fixes latency delay for async_batch_redis_cache
* fix(service_logger.py): fix race condition causing otel service logging to be overwritten if service_callbacks set
* feat(user_api_key_auth.py): add parent otel component for auth
allows us to isolate how much latency is added by auth checks
* perf(parallel_request_limiter.py): move async_set_cache_pipeline (from max parallel request limiter) out of execution path (background task)
reduces latency by 200ms
* feat(user_api_key_auth.py): have user api key auth object return user tpm/rpm limits - reduces redis calls in downstream task (parallel_request_limiter)
Reduces latency by 400-800ms
* fix(parallel_request_limiter.py): use batch get cache to reduce user/key/team usage object calls
reduces latency by 50-100ms
* fix: fix linting error
* fix(_service_logger.py): fix import
* fix(user_api_key_auth.py): fix service logging
* fix(dual_cache.py): don't pass 'self'
* fix: fix python3.8 error
* fix: fix init]
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* fix ImageObject conversion (#6584)
* (fix) litellm.text_completion raises a non-blocking error on simple usage (#6546)
* unit test test_huggingface_text_completion_logprobs
* fix return TextCompletionHandler convert_chat_to_text_completion
* fix hf rest api
* fix test_huggingface_text_completion_logprobs
* fix linting errors
* fix importLiteLLMResponseObjectHandler
* fix test for LiteLLMResponseObjectHandler
* fix test text completion
* fix allow using 15 seconds for premium license check
* testing fix bedrock deprecated cohere.command-text-v14
* (feat) add `Predicted Outputs` for OpenAI (#6594)
* bump openai to openai==1.54.0
* add 'prediction' param
* testing fix bedrock deprecated cohere.command-text-v14
* test test_openai_prediction_param.py
* test_openai_prediction_param_with_caching
* doc Predicted Outputs
* doc Predicted Output
* (fix) Vertex Improve Performance when using `image_url` (#6593)
* fix transformation vertex
* test test_process_gemini_image
* test_image_completion_request
* testing fix - bedrock has deprecated cohere.command-text-v14
* fix vertex pdf
* bump: version 1.51.5 → 1.52.0
* fix(lowest_tpm_rpm_routing.py): fix parallel rate limit check (#6577)
* fix(lowest_tpm_rpm_routing.py): fix parallel rate limit check
* fix(lowest_tpm_rpm_v2.py): return headers in correct format
* test: update test
* build(deps): bump cookie and express in /docs/my-website (#6566)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.
Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)
Updates `express` from 4.20.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.20.0...4.21.1)
---
updated-dependencies:
- dependency-name: cookie
dependency-type: indirect
- dependency-name: express
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* docs(virtual_keys.md): update Dockerfile reference (#6554)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
* (proxy fix) - call connect on prisma client when running setup (#6534)
* critical fix - call connect on prisma client when running setup
* fix test_proxy_server_prisma_setup
* fix test_proxy_server_prisma_setup
* Add 3.5 haiku (#6588)
* feat: add claude-3-5-haiku-20241022 entries
* feat: add claude-3-5-haiku-20241022 and vertex_ai/claude-3-5-haiku@20241022 models
* add missing entries, remove vision
* remove image token costs
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* build: fix map
* build: fix map
* build: fix json for model map
* test: remove eol model
* fix(proxy_server.py): fix db config loading logic
* fix(proxy_server.py): fix order of config / db updates, to ensure fields not overwritten
* test: skip test if required env var is missing
* test: fix test
---------
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: paul-gauthier <69695708+paul-gauthier@users.noreply.github.com>
* test: mark flaky test
* test: handle anthropic api instability
* test: update test
* test: bump num retries on langfuse tests - their api is quite bad
---------
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: paul-gauthier <69695708+paul-gauthier@users.noreply.github.com>
2024-11-06 20:23:46 +08:00
@pytest.mark.parametrize ( " sync_mode " , [ True , False ] )
@pytest.mark.asyncio
2024-12-03 14:00:01 +08:00
@pytest.mark.flaky ( retries = 6 , delay = 1 )
LiteLLM Minor Fixes & Improvements (11/04/2024) (#6572)
* feat: initial commit for watsonx chat endpoint support
Closes https://github.com/BerriAI/litellm/issues/6562
* feat(watsonx/chat/handler.py): support tool calling for watsonx
Closes https://github.com/BerriAI/litellm/issues/6562
* fix(streaming_utils.py): return empty chunk instead of failing if streaming value is invalid dict
ensures streaming works for ibm watsonx
* fix(openai_like/chat/handler.py): ensure asynchttphandler is passed correctly for openai like calls
* fix: ensure exception mapping works well for watsonx calls
* fix(openai_like/chat/handler.py): handle async streaming correctly
* feat(main.py): Make it clear when a user is passing an invalid message
add validation for user content message
Closes https://github.com/BerriAI/litellm/issues/6565
* fix: cleanup
* fix(utils.py): loosen validation check, to just make sure content types are valid
make litellm robust to future content updates
* fix: fix linting erro
* fix: fix linting errors
* fix(utils.py): make validation check more flexible
* test: handle langfuse list index out of range error
* Litellm dev 11 02 2024 (#6561)
* fix(dual_cache.py): update in-memory check for redis batch get cache
Fixes latency delay for async_batch_redis_cache
* fix(service_logger.py): fix race condition causing otel service logging to be overwritten if service_callbacks set
* feat(user_api_key_auth.py): add parent otel component for auth
allows us to isolate how much latency is added by auth checks
* perf(parallel_request_limiter.py): move async_set_cache_pipeline (from max parallel request limiter) out of execution path (background task)
reduces latency by 200ms
* feat(user_api_key_auth.py): have user api key auth object return user tpm/rpm limits - reduces redis calls in downstream task (parallel_request_limiter)
Reduces latency by 400-800ms
* fix(parallel_request_limiter.py): use batch get cache to reduce user/key/team usage object calls
reduces latency by 50-100ms
* fix: fix linting error
* fix(_service_logger.py): fix import
* fix(user_api_key_auth.py): fix service logging
* fix(dual_cache.py): don't pass 'self'
* fix: fix python3.8 error
* fix: fix init]
* bump: version 1.51.4 → 1.51.5
* build(deps): bump cookie and express in /docs/my-website (#6566)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.
Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)
Updates `express` from 4.20.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.20.0...4.21.1)
---
updated-dependencies:
- dependency-name: cookie
dependency-type: indirect
- dependency-name: express
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* docs(virtual_keys.md): update Dockerfile reference (#6554)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
* (proxy fix) - call connect on prisma client when running setup (#6534)
* critical fix - call connect on prisma client when running setup
* fix test_proxy_server_prisma_setup
* fix test_proxy_server_prisma_setup
* Add 3.5 haiku (#6588)
* feat: add claude-3-5-haiku-20241022 entries
* feat: add claude-3-5-haiku-20241022 and vertex_ai/claude-3-5-haiku@20241022 models
* add missing entries, remove vision
* remove image token costs
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* build: fix map
* build: fix map
* build: fix json for model map
* Litellm dev 11 02 2024 (#6561)
* fix(dual_cache.py): update in-memory check for redis batch get cache
Fixes latency delay for async_batch_redis_cache
* fix(service_logger.py): fix race condition causing otel service logging to be overwritten if service_callbacks set
* feat(user_api_key_auth.py): add parent otel component for auth
allows us to isolate how much latency is added by auth checks
* perf(parallel_request_limiter.py): move async_set_cache_pipeline (from max parallel request limiter) out of execution path (background task)
reduces latency by 200ms
* feat(user_api_key_auth.py): have user api key auth object return user tpm/rpm limits - reduces redis calls in downstream task (parallel_request_limiter)
Reduces latency by 400-800ms
* fix(parallel_request_limiter.py): use batch get cache to reduce user/key/team usage object calls
reduces latency by 50-100ms
* fix: fix linting error
* fix(_service_logger.py): fix import
* fix(user_api_key_auth.py): fix service logging
* fix(dual_cache.py): don't pass 'self'
* fix: fix python3.8 error
* fix: fix init]
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* fix ImageObject conversion (#6584)
* (fix) litellm.text_completion raises a non-blocking error on simple usage (#6546)
* unit test test_huggingface_text_completion_logprobs
* fix return TextCompletionHandler convert_chat_to_text_completion
* fix hf rest api
* fix test_huggingface_text_completion_logprobs
* fix linting errors
* fix importLiteLLMResponseObjectHandler
* fix test for LiteLLMResponseObjectHandler
* fix test text completion
* fix allow using 15 seconds for premium license check
* testing fix bedrock deprecated cohere.command-text-v14
* (feat) add `Predicted Outputs` for OpenAI (#6594)
* bump openai to openai==1.54.0
* add 'prediction' param
* testing fix bedrock deprecated cohere.command-text-v14
* test test_openai_prediction_param.py
* test_openai_prediction_param_with_caching
* doc Predicted Outputs
* doc Predicted Output
* (fix) Vertex Improve Performance when using `image_url` (#6593)
* fix transformation vertex
* test test_process_gemini_image
* test_image_completion_request
* testing fix - bedrock has deprecated cohere.command-text-v14
* fix vertex pdf
* bump: version 1.51.5 → 1.52.0
* fix(lowest_tpm_rpm_routing.py): fix parallel rate limit check (#6577)
* fix(lowest_tpm_rpm_routing.py): fix parallel rate limit check
* fix(lowest_tpm_rpm_v2.py): return headers in correct format
* test: update test
* build(deps): bump cookie and express in /docs/my-website (#6566)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.
Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)
Updates `express` from 4.20.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.20.0...4.21.1)
---
updated-dependencies:
- dependency-name: cookie
dependency-type: indirect
- dependency-name: express
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* docs(virtual_keys.md): update Dockerfile reference (#6554)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
* (proxy fix) - call connect on prisma client when running setup (#6534)
* critical fix - call connect on prisma client when running setup
* fix test_proxy_server_prisma_setup
* fix test_proxy_server_prisma_setup
* Add 3.5 haiku (#6588)
* feat: add claude-3-5-haiku-20241022 entries
* feat: add claude-3-5-haiku-20241022 and vertex_ai/claude-3-5-haiku@20241022 models
* add missing entries, remove vision
* remove image token costs
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* build: fix map
* build: fix map
* build: fix json for model map
* test: remove eol model
* fix(proxy_server.py): fix db config loading logic
* fix(proxy_server.py): fix order of config / db updates, to ensure fields not overwritten
* test: skip test if required env var is missing
* test: fix test
---------
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: paul-gauthier <69695708+paul-gauthier@users.noreply.github.com>
* test: mark flaky test
* test: handle anthropic api instability
* test: update test
* test: bump num retries on langfuse tests - their api is quite bad
---------
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: paul-gauthier <69695708+paul-gauthier@users.noreply.github.com>
2024-11-06 20:23:46 +08:00
async def test_watsonx_tool_choice ( sync_mode ) :
from litellm . llms . custom_httpx . http_handler import HTTPHandler , AsyncHTTPHandler
import json
from litellm import acompletion , completion
litellm . set_verbose = True
tools = [
{
" type " : " function " ,
" function " : {
" name " : " get_current_weather " ,
" description " : " Get the current weather in a given location " ,
" parameters " : {
" type " : " object " ,
" properties " : {
" location " : {
" type " : " string " ,
" description " : " The city and state, e.g. San Francisco, CA " ,
} ,
" unit " : { " type " : " string " , " enum " : [ " celsius " , " fahrenheit " ] } ,
} ,
" required " : [ " location " ] ,
} ,
} ,
}
]
messages = [ { " role " : " user " , " content " : " What is the weather in San Francisco? " } ]
client = HTTPHandler ( ) if sync_mode else AsyncHTTPHandler ( )
with patch . object ( client , " post " , return_value = MagicMock ( ) ) as mock_completion :
2024-12-03 14:00:01 +08:00
try :
if sync_mode :
resp = completion (
model = " watsonx/meta-llama/llama-3-1-8b-instruct " ,
messages = messages ,
tools = tools ,
tool_choice = " auto " ,
client = client ,
)
else :
resp = await acompletion (
model = " watsonx/meta-llama/llama-3-1-8b-instruct " ,
messages = messages ,
tools = tools ,
tool_choice = " auto " ,
client = client ,
stream = True ,
)
LiteLLM Minor Fixes & Improvements (11/04/2024) (#6572)
* feat: initial commit for watsonx chat endpoint support
Closes https://github.com/BerriAI/litellm/issues/6562
* feat(watsonx/chat/handler.py): support tool calling for watsonx
Closes https://github.com/BerriAI/litellm/issues/6562
* fix(streaming_utils.py): return empty chunk instead of failing if streaming value is invalid dict
ensures streaming works for ibm watsonx
* fix(openai_like/chat/handler.py): ensure asynchttphandler is passed correctly for openai like calls
* fix: ensure exception mapping works well for watsonx calls
* fix(openai_like/chat/handler.py): handle async streaming correctly
* feat(main.py): Make it clear when a user is passing an invalid message
add validation for user content message
Closes https://github.com/BerriAI/litellm/issues/6565
* fix: cleanup
* fix(utils.py): loosen validation check, to just make sure content types are valid
make litellm robust to future content updates
* fix: fix linting erro
* fix: fix linting errors
* fix(utils.py): make validation check more flexible
* test: handle langfuse list index out of range error
* Litellm dev 11 02 2024 (#6561)
* fix(dual_cache.py): update in-memory check for redis batch get cache
Fixes latency delay for async_batch_redis_cache
* fix(service_logger.py): fix race condition causing otel service logging to be overwritten if service_callbacks set
* feat(user_api_key_auth.py): add parent otel component for auth
allows us to isolate how much latency is added by auth checks
* perf(parallel_request_limiter.py): move async_set_cache_pipeline (from max parallel request limiter) out of execution path (background task)
reduces latency by 200ms
* feat(user_api_key_auth.py): have user api key auth object return user tpm/rpm limits - reduces redis calls in downstream task (parallel_request_limiter)
Reduces latency by 400-800ms
* fix(parallel_request_limiter.py): use batch get cache to reduce user/key/team usage object calls
reduces latency by 50-100ms
* fix: fix linting error
* fix(_service_logger.py): fix import
* fix(user_api_key_auth.py): fix service logging
* fix(dual_cache.py): don't pass 'self'
* fix: fix python3.8 error
* fix: fix init]
* bump: version 1.51.4 → 1.51.5
* build(deps): bump cookie and express in /docs/my-website (#6566)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.
Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)
Updates `express` from 4.20.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.20.0...4.21.1)
---
updated-dependencies:
- dependency-name: cookie
dependency-type: indirect
- dependency-name: express
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* docs(virtual_keys.md): update Dockerfile reference (#6554)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
* (proxy fix) - call connect on prisma client when running setup (#6534)
* critical fix - call connect on prisma client when running setup
* fix test_proxy_server_prisma_setup
* fix test_proxy_server_prisma_setup
* Add 3.5 haiku (#6588)
* feat: add claude-3-5-haiku-20241022 entries
* feat: add claude-3-5-haiku-20241022 and vertex_ai/claude-3-5-haiku@20241022 models
* add missing entries, remove vision
* remove image token costs
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* build: fix map
* build: fix map
* build: fix json for model map
* Litellm dev 11 02 2024 (#6561)
* fix(dual_cache.py): update in-memory check for redis batch get cache
Fixes latency delay for async_batch_redis_cache
* fix(service_logger.py): fix race condition causing otel service logging to be overwritten if service_callbacks set
* feat(user_api_key_auth.py): add parent otel component for auth
allows us to isolate how much latency is added by auth checks
* perf(parallel_request_limiter.py): move async_set_cache_pipeline (from max parallel request limiter) out of execution path (background task)
reduces latency by 200ms
* feat(user_api_key_auth.py): have user api key auth object return user tpm/rpm limits - reduces redis calls in downstream task (parallel_request_limiter)
Reduces latency by 400-800ms
* fix(parallel_request_limiter.py): use batch get cache to reduce user/key/team usage object calls
reduces latency by 50-100ms
* fix: fix linting error
* fix(_service_logger.py): fix import
* fix(user_api_key_auth.py): fix service logging
* fix(dual_cache.py): don't pass 'self'
* fix: fix python3.8 error
* fix: fix init]
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* fix ImageObject conversion (#6584)
* (fix) litellm.text_completion raises a non-blocking error on simple usage (#6546)
* unit test test_huggingface_text_completion_logprobs
* fix return TextCompletionHandler convert_chat_to_text_completion
* fix hf rest api
* fix test_huggingface_text_completion_logprobs
* fix linting errors
* fix importLiteLLMResponseObjectHandler
* fix test for LiteLLMResponseObjectHandler
* fix test text completion
* fix allow using 15 seconds for premium license check
* testing fix bedrock deprecated cohere.command-text-v14
* (feat) add `Predicted Outputs` for OpenAI (#6594)
* bump openai to openai==1.54.0
* add 'prediction' param
* testing fix bedrock deprecated cohere.command-text-v14
* test test_openai_prediction_param.py
* test_openai_prediction_param_with_caching
* doc Predicted Outputs
* doc Predicted Output
* (fix) Vertex Improve Performance when using `image_url` (#6593)
* fix transformation vertex
* test test_process_gemini_image
* test_image_completion_request
* testing fix - bedrock has deprecated cohere.command-text-v14
* fix vertex pdf
* bump: version 1.51.5 → 1.52.0
* fix(lowest_tpm_rpm_routing.py): fix parallel rate limit check (#6577)
* fix(lowest_tpm_rpm_routing.py): fix parallel rate limit check
* fix(lowest_tpm_rpm_v2.py): return headers in correct format
* test: update test
* build(deps): bump cookie and express in /docs/my-website (#6566)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.
Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)
Updates `express` from 4.20.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.20.0...4.21.1)
---
updated-dependencies:
- dependency-name: cookie
dependency-type: indirect
- dependency-name: express
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* docs(virtual_keys.md): update Dockerfile reference (#6554)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
* (proxy fix) - call connect on prisma client when running setup (#6534)
* critical fix - call connect on prisma client when running setup
* fix test_proxy_server_prisma_setup
* fix test_proxy_server_prisma_setup
* Add 3.5 haiku (#6588)
* feat: add claude-3-5-haiku-20241022 entries
* feat: add claude-3-5-haiku-20241022 and vertex_ai/claude-3-5-haiku@20241022 models
* add missing entries, remove vision
* remove image token costs
* Litellm perf improvements 3 (#6573)
* perf: move writing key to cache, to background task
* perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
* fix(litellm_pre_call_utils.py'): rename call_type to actual call used
* perf(proxy_server.py): remove db logic from _get_config_from_file
was causing db calls to occur on every llm request, if team_id was set on key
* fix(auth_checks.py): add check for reducing db calls if user/team id does not exist in db
reduces latency/call by ~100ms
* fix(proxy_server.py): minor fix on existing_settings not incl alerting
* fix(exception_mapping_utils.py): map databricks exception string
* fix(auth_checks.py): fix auth check logic
* test: correctly mark flaky test
* fix(utils.py): handle auth token error for tokenizers.from_pretrained
* build: fix map
* build: fix map
* build: fix json for model map
* test: remove eol model
* fix(proxy_server.py): fix db config loading logic
* fix(proxy_server.py): fix order of config / db updates, to ensure fields not overwritten
* test: skip test if required env var is missing
* test: fix test
---------
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: paul-gauthier <69695708+paul-gauthier@users.noreply.github.com>
* test: mark flaky test
* test: handle anthropic api instability
* test: update test
* test: bump num retries on langfuse tests - their api is quite bad
---------
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: paul-gauthier <69695708+paul-gauthier@users.noreply.github.com>
2024-11-06 20:23:46 +08:00
2024-12-03 14:00:01 +08:00
print ( resp )
mock_completion . assert_called_once ( )
print ( mock_completion . call_args . kwargs )
json_data = json . loads ( mock_completion . call_args . kwargs [ " data " ] )
2025-07-23 09:28:36 +08:00
json_data [ " tool_choice_option " ] == " auto "
2024-12-03 14:00:01 +08:00
except Exception as e :
print ( e )
if " The read operation timed out " in str ( e ) :
pytest . skip ( " Skipping test due to timeout " )
else :
raise e
2025-01-30 13:09:07 +08:00