Skip to main content
Pixeltable UDFs that wrap various endpoints from the Anthropic API. In order to use them, you must first pip install anthropic and configure your Anthropic credentials, as described in the Working with Anthropic tutorial. View source on GitHub

UDFs


invoke_tools() udf

Converts an Anthropic response dict to Pixeltable tool invocation format and calls tools._invoke(). Signature:
invoke_tools(
    tools: pixeltable.func.tools.Tools,
    response: pixeltable.exprs.expr.Expr
)-> pixeltable.exprs.inline_expr.InlineDict

messages() udf

Create a Message. Equivalent to the Anthropic messages API endpoint. For additional details, see: https://docs.anthropic.com/en/api/messages Request throttling: Uses the rate limit-related headers returned by the API to throttle requests adaptively, based on available request and token capacity. No configuration is necessary. Requirements:
  • pip install anthropic
Signature:
messages(
    messages: Json,
    model: String,
    max_tokens: Int,
    model_kwargs: Optional[Json],
    tools: Optional[Json],
    tool_choice: Optional[Json]
)-> Json
Parameters:
  • messages (Json): Input messages.
  • model (String): The model that will complete your prompt.
  • model_kwargs (Optional[Json]): Additional keyword args for the Anthropic messages API. For details on the available parameters, see: https://docs.anthropic.com/en/api/messages
  • tools (Optional[Json]): An optional list of Pixeltable tools to use for the request.
  • tool_choice (Optional[Json]): An optional tool choice configuration.
Returns:
  • Json: A dictionary containing the response and other metadata.
Example: Add a computed column that applies the model claude-3-5-sonnet-20241022 to an existing Pixeltable column tbl.prompt of the table tbl:
msgs = [{'role': 'user', 'content': tbl.prompt}]
tbl.add_computed_column(response=messages(msgs, model='claude-3-5-sonnet-20241022'))
I