anthropic_client#

Anthropic ModelClient integration.

Functions

get_first_message_content(completion)

When we only need the content of the first message.

Classes

AnthropicAPIClient([api_key, ...])

A component wrapper for the Anthropic API client.

class AnthropicAPIClient(api_key: str | None = None, chat_completion_parser: Callable[[Message], Any] = None)[source]#

Bases: ModelClient

A component wrapper for the Anthropic API client.

Visit https://docs.anthropic.com/en/docs/intro-to-claude for more api details.

Ensure “max_tokens” are set.

Reference: 8/1/2024 - https://docs.anthropic.com/en/docs/about-claude/models

init_sync_client()[source]#
init_async_client()[source]#
parse_chat_completion(completion: Message) GeneratorOutput[source]#

Parse the chat completion to str.

track_completion_usage(completion: Message) CompletionUsage[source]#

Track the completion usage.

convert_inputs_to_api_kwargs(input: Any | None = None, model_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED) dict[source]#

Anthropic API messages separates the system and the user messages.

As we focus on one prompt, we have to use the user message as the input.

api: https://docs.anthropic.com/en/api/messages

call(api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED)[source]#

kwargs is the combined input and model_kwargs

async acall(api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED)[source]#

kwargs is the combined input and model_kwargs

get_first_message_content(completion: Message) str[source]#

When we only need the content of the first message. It is the default parser for chat completion.