Skip to content

Commit 69a3a84

Browse files
authored
fix: anthropic typing breaks (#6543)
1 parent 151d45e commit 69a3a84

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

marimo/_ai/llm/_impl.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
import os
5-
from typing import Callable, Optional, cast
5+
from typing import Any, Callable, Optional, cast
66

77
from marimo._ai._convert import (
88
convert_to_anthropic_messages,
@@ -211,29 +211,29 @@ def __call__(
211211
DependencyManager.anthropic.require(
212212
"chat model requires anthropic. `pip install anthropic`"
213213
)
214-
from anthropic import ( # type: ignore[import-not-found]
215-
NOT_GIVEN,
216-
Anthropic,
217-
)
214+
from anthropic import Anthropic
218215

219216
client = Anthropic(
220217
api_key=self._require_api_key,
221218
base_url=self.base_url,
222219
)
223220

224221
anthropic_messages = convert_to_anthropic_messages(messages)
225-
response = client.messages.create(
226-
model=self.model,
227-
system=self.system_message,
228-
max_tokens=config.max_tokens or 4096,
229-
messages=anthropic_messages,
230-
top_p=config.top_p if config.top_p is not None else NOT_GIVEN,
231-
top_k=config.top_k if config.top_k is not None else NOT_GIVEN,
232-
stream=False,
233-
temperature=config.temperature
234-
if config.temperature is not None
235-
else NOT_GIVEN,
236-
)
222+
params: dict[str, Any] = {
223+
"model": self.model,
224+
"system": self.system_message,
225+
"max_tokens": config.max_tokens or 4096,
226+
"messages": anthropic_messages,
227+
"stream": False,
228+
}
229+
if config.top_p is not None:
230+
params["top_p"] = config.top_p
231+
if config.top_k is not None:
232+
params["top_k"] = config.top_k
233+
if config.temperature is not None:
234+
params["temperature"] = config.temperature
235+
236+
response = client.messages.create(**params)
237237

238238
content = response.content
239239
if len(content) > 0:

0 commit comments

Comments
 (0)