Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5698195
fix(anthropic/chat/transformation.py): support anthropic disable_para…
Oct 28, 2024
e7f0674
feat(anthropic/chat/transformation.py): support anthropic computer to…
Oct 28, 2024
c4ee99c
fix(vertex_ai/common_utils.py): parse out '$schema' when calling vert…
Oct 28, 2024
f49ef06
fix(main.py): add 'extra_headers' support for azure on all translatio…
Oct 28, 2024
dda729e
fix: fix linting errors
Oct 29, 2024
d702f62
fix(transformation.py): handle no beta headers for anthropic
Oct 29, 2024
30c83d8
test: cleanup test
Oct 29, 2024
df95f77
fix: fix linting error
Oct 29, 2024
c2a0348
fix: fix linting errors
Oct 29, 2024
5cc16ed
fix: fix linting errors
Oct 29, 2024
6358d71
fix(transformation.py): handle dummy tool call
Oct 29, 2024
3223772
fix(main.py): fix linting error
Oct 29, 2024
69c9c9b
fix(azure.py): pass required param
Oct 29, 2024
0cc883d
LiteLLM Minor Fixes & Improvements (10/24/2024) (#6441)
Oct 28, 2024
1362916
Litellm dev 10 26 2024 (#6472)
Oct 28, 2024
b829310
(Testing) Add unit testing for DualCache - ensure in memory cache is …
ishaan-jaff Oct 29, 2024
143283c
redis otel tracing + async support for latency routing (#6452)
Oct 29, 2024
0bd495a
fix(dual_cache.py): set default value for parent_otel_span
Oct 29, 2024
9aad9e3
fix(transformation.py): support 'response_format' for anthropic calls
Oct 29, 2024
df06f25
fix(transformation.py): check for cache_control inside 'function' block
Oct 29, 2024
fc836cf
fix: fix linting error
Oct 29, 2024
4d405bb
Merge branch 'main' into litellm_dev_10_28_2024
Oct 29, 2024
18e1f0d
fix: fix linting errors
Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/my-website/docs/providers/anthropic.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,37 @@ except Exception as e:

s/o @[Shekhar Patnaik](https://www.linkedin.com/in/patnaikshekhar) for requesting this!

### Computer Tools

```python
from litellm import completion

tools = [
{
"type": "computer_20241022",
"function": {
"name": "computer",
"parameters": {
"display_height_px": 100,
"display_width_px": 100,
"display_number": 1,
},
},
}
]
model = "claude-3-5-sonnet-20241022"
messages = [{"role": "user", "content": "Save a picture of a cat to my desktop."}]

resp = completion(
model=model,
messages=messages,
tools=tools,
# headers={"anthropic-beta": "computer-use-2024-10-22"},
)

print(resp)
```

## Usage - Vision

```python
Expand Down
48 changes: 17 additions & 31 deletions litellm/llms/AzureOpenAI/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ async def make_async_azure_httpx_request(
api_version: str,
api_key: str,
data: dict,
headers: dict,
) -> httpx.Response:
"""
Implemented for azure dall-e-2 image gen calls
Expand Down Expand Up @@ -1002,20 +1003,15 @@ async def make_async_azure_httpx_request(
response = await async_handler.post(
url=api_base,
data=json.dumps(data),
headers={
"Content-Type": "application/json",
"api-key": api_key,
},
headers=headers,
)
if "operation-location" in response.headers:
operation_location_url = response.headers["operation-location"]
else:
raise AzureOpenAIError(status_code=500, message=response.text)
response = await async_handler.get(
url=operation_location_url,
headers={
"api-key": api_key,
},
headers=headers,
)

await response.aread()
Expand All @@ -1036,9 +1032,7 @@ async def make_async_azure_httpx_request(
await asyncio.sleep(int(response.headers.get("retry-after") or 10))
response = await async_handler.get(
url=operation_location_url,
headers={
"api-key": api_key,
},
headers=headers,
)
await response.aread()

Expand All @@ -1056,10 +1050,7 @@ async def make_async_azure_httpx_request(
return await async_handler.post(
url=api_base,
json=data,
headers={
"Content-Type": "application/json;",
"api-key": api_key,
},
headers=headers,
)

def make_sync_azure_httpx_request(
Expand All @@ -1070,6 +1061,7 @@ def make_sync_azure_httpx_request(
api_version: str,
api_key: str,
data: dict,
headers: dict,
) -> httpx.Response:
"""
Implemented for azure dall-e-2 image gen calls
Expand All @@ -1085,7 +1077,7 @@ def make_sync_azure_httpx_request(
else:
_params["timeout"] = httpx.Timeout(timeout=600.0, connect=5.0)

sync_handler = HTTPHandler(**_params) # type: ignore
sync_handler = HTTPHandler(**_params, client=litellm.client_session) # type: ignore
else:
sync_handler = client # type: ignore

Expand All @@ -1111,20 +1103,15 @@ def make_sync_azure_httpx_request(
response = sync_handler.post(
url=api_base,
data=json.dumps(data),
headers={
"Content-Type": "application/json",
"api-key": api_key,
},
headers=headers,
)
if "operation-location" in response.headers:
operation_location_url = response.headers["operation-location"]
else:
raise AzureOpenAIError(status_code=500, message=response.text)
response = sync_handler.get(
url=operation_location_url,
headers={
"api-key": api_key,
},
headers=headers,
)

response.read()
Expand All @@ -1144,9 +1131,7 @@ def make_sync_azure_httpx_request(
time.sleep(int(response.headers.get("retry-after") or 10))
response = sync_handler.get(
url=operation_location_url,
headers={
"api-key": api_key,
},
headers=headers,
)
response.read()

Expand All @@ -1164,10 +1149,7 @@ def make_sync_azure_httpx_request(
return sync_handler.post(
url=api_base,
json=data,
headers={
"Content-Type": "application/json;",
"api-key": api_key,
},
headers=headers,
)

def create_azure_base_url(
Expand Down Expand Up @@ -1201,6 +1183,7 @@ async def aimage_generation(
api_key: str,
input: list,
logging_obj: LiteLLMLoggingObj,
headers: dict,
client=None,
timeout=None,
) -> litellm.ImageResponse:
Expand All @@ -1224,7 +1207,7 @@ async def aimage_generation(
additional_args={
"complete_input_dict": data,
"api_base": img_gen_api_base,
"headers": {"api_key": api_key},
"headers": headers,
},
)
httpx_response: httpx.Response = await self.make_async_azure_httpx_request(
Expand All @@ -1234,6 +1217,7 @@ async def aimage_generation(
api_version=api_version,
api_key=api_key,
data=data,
headers=headers,
)
response = httpx_response.json()

Expand Down Expand Up @@ -1266,6 +1250,7 @@ def image_generation(
timeout: float,
optional_params: dict,
logging_obj: LiteLLMLoggingObj,
headers: dict,
model: Optional[str] = None,
api_key: Optional[str] = None,
api_base: Optional[str] = None,
Expand Down Expand Up @@ -1329,7 +1314,7 @@ def image_generation(
additional_args={
"complete_input_dict": data,
"api_base": img_gen_api_base,
"headers": {"api_key": api_key},
"headers": headers,
},
)
httpx_response: httpx.Response = self.make_sync_azure_httpx_request(
Expand All @@ -1339,6 +1324,7 @@ def image_generation(
api_version=api_version or "",
api_key=api_key or "",
data=data,
headers=headers,
)
response = httpx_response.json()

Expand Down
35 changes: 23 additions & 12 deletions litellm/llms/anthropic/chat/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
get_async_httpx_client,
)
from litellm.types.llms.anthropic import (
AllAnthropicToolsValues,
AnthropicChatCompletionUsageBlock,
ContentBlockDelta,
ContentBlockStart,
Expand All @@ -53,26 +54,30 @@

# makes headers for API call
def validate_environment(
api_key, user_headers, model, messages: List[AllMessageValues]
api_key,
user_headers,
model,
messages: List[AllMessageValues],
tools: Optional[List[AllAnthropicToolsValues]],
anthropic_version: Optional[str] = None,
):
cache_headers = {}

if api_key is None:
raise litellm.AuthenticationError(
message="Missing Anthropic API Key - A call is being made to anthropic but no key is set either in the environment variables or via params. Please set `ANTHROPIC_API_KEY` in your environment vars",
llm_provider="anthropic",
model=model,
)

if AnthropicConfig().is_cache_control_set(messages=messages):
cache_headers = AnthropicConfig().get_cache_control_headers()
headers = {
"accept": "application/json",
"anthropic-version": "2023-06-01",
"content-type": "application/json",
"x-api-key": api_key,
}
prompt_caching_set = AnthropicConfig().is_cache_control_set(messages=messages)
computer_tool_used = AnthropicConfig().is_computer_tool_used(tools=tools)

headers.update(cache_headers)
headers = AnthropicConfig().get_anthropic_headers(
anthropic_version=anthropic_version,
computer_tool_used=computer_tool_used,
prompt_caching_set=prompt_caching_set,
api_key=api_key,
)

if user_headers is not None and isinstance(user_headers, dict):
headers = {**headers, **user_headers}
Expand Down Expand Up @@ -440,7 +445,13 @@ def completion(
headers={},
client=None,
):
headers = validate_environment(api_key, headers, model, messages=messages)
headers = validate_environment(
api_key,
headers,
model,
messages=messages,
tools=optional_params.get("tools"),
)
_is_function_call = False
messages = copy.deepcopy(messages)
optional_params = copy.deepcopy(optional_params)
Expand Down
Loading