Prompting Anthropic's Claude
Make an Anthropic API Key to load into Modelbit. In Modelbit's Settings
, click Integrations
and then click the Anthropic
tile. Add your API key to that form. You're now ready to call Anthropic from Modelbit.
Example deployment calling Anthropic
The following example uses mb.get_secret
to load your Anthropic API key into your env. The remainder of the code is the normal Python syntax to call Anthropic and return a result:
import os
from anthropic import Anthropic
os.environ["ANTHROPIC_API_KEY"] = mb.get_secret("ANTHROPIC_API_KEY")
def call_claude(prompt: str):
message = Anthropic().messages.create(
model="claude-3-opus-20240229",
max_tokens=10,
messages=[
{"role": "user", "content": prompt}
])
return [c.text for c in message.content]
Call the function to test it:
call_claude("Hello, Claude! What color is the sky?")
# Returns: ["The sky is blue."]
Deploy to Modelbit
Use mb.deploy
or Git to deploy call_claude
to Modelbit.
This is a simple example to pass prompts to Claude. You can extend this deployment with more elaborate prompts as well as post-processing of the model's responses.