Skip to content
Merged
Changes from all commits
Commits
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
34 changes: 17 additions & 17 deletions marimo/_ai/llm/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import os
from typing import Callable, Optional, cast
from typing import Any, Callable, Optional, cast

from marimo._ai._convert import (
convert_to_anthropic_messages,
Expand Down Expand Up @@ -211,29 +211,29 @@ def __call__(
DependencyManager.anthropic.require(
"chat model requires anthropic. `pip install anthropic`"
)
from anthropic import ( # type: ignore[import-not-found]
NOT_GIVEN,
Anthropic,
)
from anthropic import Anthropic

client = Anthropic(
api_key=self._require_api_key,
base_url=self.base_url,
)

anthropic_messages = convert_to_anthropic_messages(messages)
response = client.messages.create(
model=self.model,
system=self.system_message,
max_tokens=config.max_tokens or 4096,
messages=anthropic_messages,
top_p=config.top_p if config.top_p is not None else NOT_GIVEN,
top_k=config.top_k if config.top_k is not None else NOT_GIVEN,
stream=False,
temperature=config.temperature
if config.temperature is not None
else NOT_GIVEN,
)
params: dict[str, Any] = {
"model": self.model,
"system": self.system_message,
"max_tokens": config.max_tokens or 4096,
"messages": anthropic_messages,
"stream": False,
}
if config.top_p is not None:
params["top_p"] = config.top_p
if config.top_k is not None:
params["top_k"] = config.top_k
if config.temperature is not None:
params["temperature"] = config.temperature

response = client.messages.create(**params)

content = response.content
if len(content) > 0:
Expand Down
Loading