The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(utils.py): set max_retries = num_retries, if given
Krrish Dholakiaba7b07088345
diff --git a/litellm/main.py b/litellm/main.pyindex 6200d8cb18a..c731eacc625 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -762,8 +762,8 @@ def completion(try:if base_url is not None:api_base = base_url- if max_retries is not None: # openai allows openai.OpenAI(max_retries=3)- num_retries = max_retries+ if num_retries is not None:+ max_retries = num_retrieslogging = litellm_logging_objfallbacks = fallbacks or litellm.model_fallbacksif fallbacks is not None:diff --git a/litellm/tests/test_class.py b/litellm/tests/test_class.pyindex 7f1fc90650d..a15f3623720 100644--- a/litellm/tests/test_class.py+++ b/litellm/tests/test_class.py@@ -1,5 +1,5 @@-# #### What this tests ####-# # This tests the LiteLLM Class+# # #### What this tests ####+# # # This tests the LiteLLM Class# import sys, os# import traceback@@ -11,83 +11,114 @@# import litellm# import asyncio-# litellm.set_verbose = True-# from litellm import Router+# # litellm.set_verbose = True+# # from litellm import Router# import instructor-# from pydantic import BaseModel-# # This enables response_model keyword-# # from client.chat.completions.create-# client = instructor.patch(-# Router(-# model_list=[-# {-# "model_name": "gpt-3.5-turbo", # openai model name-# "litellm_params": { # params for litellm completion/embedding call-# "model": "azure/chatgpt-v-2",-# "api_key": os.getenv("AZURE_API_KEY"),-# "api_version": os.getenv("AZURE_API_VERSION"),-# "api_base": os.getenv("AZURE_API_BASE"),-# },-# }-# ]-# )-# )+# from litellm import completion+# from pydantic import BaseModel-# class UserDetail(BaseModel):+# class User(BaseModel):# name: str# age: int-# user = client.chat.completions.create(+# client = instructor.from_litellm(completion)++# litellm.set_verbose = True++# resp = client.chat.completions.create(# model="gpt-3.5-turbo",-# response_model=UserDetail,+# max_tokens=1024,# messages=[-# {"role": "user", "content": "Extract Jason is 25 years old"},+# {+# "role": "user",+# "content": "Extract Jason is 25 years old.",+# }# ],+# response_model=User,+# num_retries=10,# )-# assert isinstance(user, UserDetail)-# assert user.name == "Jason"-# assert user.age == 25--# print(f"user: {user}")-# # import instructor-# # from openai import AsyncOpenAI--# aclient = instructor.apatch(-# Router(-# model_list=[-# {-# "model_name": "gpt-3.5-turbo", # openai model name-# "litellm_params": { # params for litellm completion/embedding call-# "model": "azure/chatgpt-v-2",-# "api_key": os.getenv("AZURE_API_KEY"),-# "api_version": os.getenv("AZURE_API_VERSION"),-# "api_base": os.getenv("AZURE_API_BASE"),-# },-# }-# ],-# default_litellm_params={"acompletion": True},-# )-# )---# class UserExtract(BaseModel):-# name: str-# age: int---# async def main():-# model = await aclient.chat.completions.create(-# model="gpt-3.5-turbo",-# response_model=UserExtract,-# messages=[-# {"role": "user", "content": "Extract jason is 25 years old"},-# ],-# )-# print(f"model: {model}")---# asyncio.run(main())+# assert isinstance(resp, User)+# assert resp.name == "Jason"+# assert resp.age == 25++# # from pydantic import BaseModel++# # # This enables response_model keyword+# # # from client.chat.completions.create+# # client = instructor.patch(+# # Router(+# # model_list=[+# # {+# # "model_name": "gpt-3.5-turbo", # openai model name+# # "litellm_params": { # params for litellm completion/embedding call+# # "model": "azure/chatgpt-v-2",+# # "api_key": os.getenv("AZURE_API_KEY"),+# # "api_version": os.getenv("AZURE_API_VERSION"),+# # "api_base": os.getenv("AZURE_API_BASE"),+# # },+# # }+# # ]+# # )+# # )+++# # class UserDetail(BaseModel):+# # name: str+# # age: int+++# # user = client.chat.completions.create(+# # model="gpt-3.5-turbo",+# # response_model=UserDetail,+# # messages=[+# # {"role": "user", "content": "Extract Jason is 25 years old"},+# # ],+# # )++# # assert isinstance(user, UserDetail)+# # assert user.name == "Jason"+# # assert user.age == 25++# # print(f"user: {user}")+# # # import instructor+# # # from openai import AsyncOpenAI++# # aclient = instructor.apatch(+# # Router(+# # model_list=[+# # {+# # "model_name": "gpt-3.5-turbo", # openai model name+# # "litellm_params": { # params for litellm completion/embedding call+# # "model": "azure/chatgpt-v-2",+# # "api_key": os.getenv("AZURE_API_KEY"),+# # "api_version": os.getenv("AZURE_API_VERSION"),+# # "api_base": os.getenv("AZURE_API_BASE"),+# # },+# # }+# # ],+# # default_litellm_params={"acompletion": True},+# # )+# # )+++# # class UserExtract(BaseModel):+# # name: str+# # age: int+++# # async def main():+# # model = await aclient.chat.completions.create(+# # model="gpt-3.5-turbo",+# # response_model=UserExtract,+# # messages=[+# # {"role": "user", "content": "Extract jason is 25 years old"},+# # ],+# # )+# # print(f"model: {model}")+++# # asyncio.run(main())