fix(main.py): check if anthropic api base ends with required url

Fixes https://github.com/BerriAI/litellm/issues/4803
This commit is contained in:
Krrish Dholakia 2024-07-22 20:36:35 -07:00
parent f4a388f217
commit 0b9e93d863

View file

@ -1491,6 +1491,10 @@ def completion(
or get_secret("ANTHROPIC_BASE_URL")
or "https://api.anthropic.com/v1/complete"
)
if api_base is not None and not api_base.endswith("/v1/complete"):
api_base += "/v1/complete"
response = anthropic_text_completions.completion(
model=model,
messages=messages,
@ -1517,6 +1521,10 @@ def completion(
or get_secret("ANTHROPIC_BASE_URL")
or "https://api.anthropic.com/v1/messages"
)
if api_base is not None and not api_base.endswith("/v1/messages"):
api_base += "/v1/messages"
response = anthropic_chat_completions.completion(
model=model,
messages=messages,