anthropic
pixeltable.functions.anthropic
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.
invoke_tools
invoke_tools(tools: Tools, response: Expr) -> InlineDict
Converts an Anthropic response dict to Pixeltable tool invocation format and calls tools._invoke()
.
messages
async
messages(
messages: Json,
*,
model: String,
max_tokens: Int = 1024,
metadata: Optional[Json] = None,
stop_sequences: Optional[Json] = None,
system: Optional[String] = None,
temperature: Optional[Float] = None,
tool_choice: Optional[Json] = None,
tools: Optional[Json] = None,
top_k: Optional[Int] = None,
top_p: Optional[Float] = None,
timeout: Optional[Float] = None
) -> Json
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
Parameters:
-
messages
(Json
) –Input messages.
-
model
(String
) –The model that will complete your prompt.
For details on the other parameters, see: https://docs.anthropic.com/en/api/messages
Returns:
-
Json
–A dictionary containing the response and other metadata.
Examples:
Add a computed column that applies the model claude-3-haiku-20240307
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-haiku-20240307'))