llumpy.providers.AnthropicClient¶
- class AnthropicClient(model)[source]¶
Bases:
ModelClientClient interface for interacting with Anthropic API
- Parameters:
model (str)
- __init__(model)[source]¶
Internal initialize connection to Anthropic
- Parameters:
model (str) – LLM to use
- Raises:
EnvironmentError – If the ‘ANTHROPIC_API_KEY’ env var is not defined
Methods
__init__(model)Internal initialize connection to Anthropic
extract_text(response)Extract LLM response text from Anthropic object
prompt_many(conversation, *[, handler, retries])Prompt a model with a full conversation
prompt_one(message, *[, handler, retries])Prompt a model with a single user message
prompt_stream(conversation, **prompt_kwargs)Prompt a model and stream the response
system([content, file])Init conversation with a system message
user([content, file])Init conversation with a user message
validate()Verify Anthropic key is valid and has access to the requested model
vendor_prompt(conversation, **prompt_kwargs)Prompt a model for Anthropic chat completion
vendor_prompt_stream(conversation, ...)Prompt a model for a streamed Anthropic chat completion
Attributes
modelName of the model
- extract_text(response)[source]¶
Extract LLM response text from Anthropic object
- Parameters:
response (Message | Annotated[RawMessageStartEvent | RawMessageDeltaEvent | RawMessageStopEvent | RawContentBlockStartEvent | RawContentBlockDeltaEvent | RawContentBlockStopEvent, PropertyInfo(alias='None', format=None, format_template='None', discriminator='type')]) – Anthropic chat response or stream chunk
- Returns:
Text message if present, else None
- Return type:
str | None
- validate()[source]¶
Verify Anthropic key is valid and has access to the requested model
- Raises:
InvalidAPIKeyError – If the Anthropic key is invalid
ModelNotFoundError – If requested model does not exist
PermissionDeniedError – If key does not have access to requested model
- Return type:
None
- vendor_prompt(conversation, **prompt_kwargs)[source]¶
Prompt a model for Anthropic chat completion
- Parameters:
conversation (Conversation) – Messages to send to llm
prompt_kwargs (Any) – kwargs for chat
- Returns:
Chat completion
- Return type:
Message
- vendor_prompt_stream(conversation, **prompt_kwargs)[source]¶
Prompt a model for a streamed Anthropic chat completion
- Parameters:
conversation (Conversation) – Messages to send to llm
prompt_kwargs (Any) – kwargs for chat
- Returns:
Chat completion stream
- Return type:
Stream[Annotated[RawMessageStartEvent | RawMessageDeltaEvent | RawMessageStopEvent | RawContentBlockStartEvent | RawContentBlockDeltaEvent | RawContentBlockStopEvent, PropertyInfo(alias=’None’, format=None, format_template=’None’, discriminator=’type’)]]