Features of Anthropic Models
Last updated
Last updated
Text completions: Build advanced chat bots or text processors
Function Calling: Utilize tools for specific tasks and API calling.
Vision Tasks: Process and analyze images.
image/png
image/gif
image/webp
import httpx
import base64
from openai import OpenAI
client = OpenAI(
base_url='https://api.apilaplas.com',
api_key='<YOUR_LAPLASAPI_KEY>'
)
image_url = "https://upload.wikimedia.org/wikipedia/commons/a/a7/Camponotus_flavomarginatus_ant.jpg"
image_media_type = "image/jpeg"
image_data = base64.standard_b64encode(httpx.get(image_url).content).decode("utf-8")
response = client.chat.completions.create(
model="claude-3-5-sonnet-latest",
messages=[
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": image_media_type,
"data": imag1_data,
},
},
{
"type": "text",
"text": "Describe this image."
}
],
}
],
)
print(response)
To process text and use function calling, follow the examples below:
import requests
url = "https://api.apilaplas.com/messages"
headers = {
"Authorization": "Bearer YOUR_LAPLASAPI_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "claude-3-5-sonnet-20240620",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
}
}
}
],
"messages": [
{
"role": "user",
"content": "What is the weather like in San Francisco?"
}
],
"stream": false
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
import requests
url = "https://api.apilaplas.com/messages"
headers = {
"Authorization": "Bearer YOUR_LAPLASAPI_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "claude-3-5-sonnet-20240620",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "How are you?"
}
],
"stream": false
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
{
model="claude-3-5-sonnet-20240620",
max_tokens=2048,
# role prompt:
system="You are a seasoned data scientist at a Fortune 500 company.",
messages=[
{"role": "user", "content": "Analyze this dataset for anomalies: <dataset>{{DATASET}}</dataset>"}
]
}
The responses from the Apilaplas API for Anthropic models will typically include the generated text or results from the tool called. Here is an example response for a weather query:
{
"id": "msg-12345",
"object": "message",
"created": 1627684940,
"model": "claude-3-5-sonnet-20240620",
"choices": [
{
"message": {
"role": "assistant",
"content": "The weather in San Francisco is currently sunny with a temperature of 68°F."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 15,
"total_tokens": 25
}
}
To enable streaming of responses, set stream=True
in your request payload.
import requests
url = "https://api.apilaplas.com/messages"
headers = {
"Authorization": "Bearer YOUR_LAPLASAPI_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "claude-3-5-sonnet-20240620",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
}
}
}
],
"messages": [
{
"role": "user",
"content": "What is the weather like in San Francisco?"
}
]