Bedrock
Access Amazon Bedrock models through LangDB’s API using OpenAI SDK
LangDB provides first class support for Bedrock models.
You can use OpenAI SDK to run the Bedrock models.
from openai import OpenAI
client = OpenAI(
base_url="https://api.us-east-1.langdb.ai" # LangDB API base URL,
api_key=api_key, # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
model="bedrock/command-r-v1:0", # Use the model
messages=[{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}],
extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai"; // LangDB API base URL
const apiKey = "LANGDB_API_KEY"; // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" }; // LangDB Project ID
const client = new OpenAI({
baseURL: apiBase,
apiKey: apiKey,
});
const response = await client.chat.completions.create({
model: "bedrock/command-r-v1:0", // Use the model
messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}],
}, { headers: defaultHeaders });
// Rest of Your Codecurl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LANGDB_API_KEY" \
-X "X-Project-Id: $Project_ID" \
-d '{
"model": "bedrock/command-r-v1:0",
"messages": [
{
"role": "user",
"content": "Write a haiku about recursion in programming."
}
],
}'Last updated
Was this helpful?