mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
fix(utils.py): set max_retries = num_retries, if given
This commit is contained in:
parent
83180c50f7
commit
abda7e37ec
2 changed files with 94 additions and 63 deletions
|
@ -762,8 +762,8 @@ def completion(
|
||||||
try:
|
try:
|
||||||
if base_url is not None:
|
if base_url is not None:
|
||||||
api_base = base_url
|
api_base = base_url
|
||||||
if max_retries is not None: # openai allows openai.OpenAI(max_retries=3)
|
if num_retries is not None:
|
||||||
num_retries = max_retries
|
max_retries = num_retries
|
||||||
logging = litellm_logging_obj
|
logging = litellm_logging_obj
|
||||||
fallbacks = fallbacks or litellm.model_fallbacks
|
fallbacks = fallbacks or litellm.model_fallbacks
|
||||||
if fallbacks is not None:
|
if fallbacks is not None:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# #### What this tests ####
|
# # #### What this tests ####
|
||||||
# # This tests the LiteLLM Class
|
# # # This tests the LiteLLM Class
|
||||||
|
|
||||||
# import sys, os
|
# import sys, os
|
||||||
# import traceback
|
# import traceback
|
||||||
|
@ -11,83 +11,114 @@
|
||||||
# import litellm
|
# import litellm
|
||||||
# import asyncio
|
# import asyncio
|
||||||
|
|
||||||
# litellm.set_verbose = True
|
# # litellm.set_verbose = True
|
||||||
# from litellm import Router
|
# # from litellm import Router
|
||||||
# import instructor
|
# import instructor
|
||||||
|
|
||||||
|
# from litellm import completion
|
||||||
# from pydantic import BaseModel
|
# 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 User(BaseModel):
|
||||||
# class UserDetail(BaseModel):
|
|
||||||
# name: str
|
# name: str
|
||||||
# age: int
|
# 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",
|
# model="gpt-3.5-turbo",
|
||||||
# response_model=UserDetail,
|
# max_tokens=1024,
|
||||||
# messages=[
|
# 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 isinstance(resp, User)
|
||||||
# assert user.name == "Jason"
|
# assert resp.name == "Jason"
|
||||||
# assert user.age == 25
|
# assert resp.age == 25
|
||||||
|
|
||||||
# print(f"user: {user}")
|
# # from pydantic import BaseModel
|
||||||
# # import instructor
|
|
||||||
# # from openai import AsyncOpenAI
|
|
||||||
|
|
||||||
# aclient = instructor.apatch(
|
# # # This enables response_model keyword
|
||||||
# Router(
|
# # # from client.chat.completions.create
|
||||||
# model_list=[
|
# # client = instructor.patch(
|
||||||
# {
|
# # Router(
|
||||||
# "model_name": "gpt-3.5-turbo", # openai model name
|
# # model_list=[
|
||||||
# "litellm_params": { # params for litellm completion/embedding call
|
# # {
|
||||||
# "model": "azure/chatgpt-v-2",
|
# # "model_name": "gpt-3.5-turbo", # openai model name
|
||||||
# "api_key": os.getenv("AZURE_API_KEY"),
|
# # "litellm_params": { # params for litellm completion/embedding call
|
||||||
# "api_version": os.getenv("AZURE_API_VERSION"),
|
# # "model": "azure/chatgpt-v-2",
|
||||||
# "api_base": os.getenv("AZURE_API_BASE"),
|
# # "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):
|
# # class UserDetail(BaseModel):
|
||||||
# name: str
|
# # name: str
|
||||||
# age: int
|
# # age: int
|
||||||
|
|
||||||
|
|
||||||
# async def main():
|
# # user = client.chat.completions.create(
|
||||||
# model = await aclient.chat.completions.create(
|
# # model="gpt-3.5-turbo",
|
||||||
# model="gpt-3.5-turbo",
|
# # response_model=UserDetail,
|
||||||
# response_model=UserExtract,
|
# # messages=[
|
||||||
# messages=[
|
# # {"role": "user", "content": "Extract Jason is 25 years old"},
|
||||||
# {"role": "user", "content": "Extract jason is 25 years old"},
|
# # ],
|
||||||
# ],
|
# # )
|
||||||
# )
|
|
||||||
# print(f"model: {model}")
|
# # 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},
|
||||||
|
# # )
|
||||||
|
# # )
|
||||||
|
|
||||||
|
|
||||||
# asyncio.run(main())
|
# # 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())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue