import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.PRISM_API_KEY,
baseURL: "https://api.prisminference.com",
});
const first = await client.messages.create({
model: "prism-glm53",
max_tokens: 1024,
messages: [
{ role: "user", content: "What is the weather in San Francisco?" },
],
tools: [
{
name: "get_weather",
description: "Get the current weather for a city",
input_schema: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
},
},
],
});
const call = first.content.find((block) => block.type === "tool_use");
if (call?.type === "tool_use") {
const result = await getWeather((call.input as { city: string }).city);
const final = await client.messages.create({
model: "prism-glm53",
max_tokens: 1024,
messages: [
{ role: "user", content: "What is the weather in San Francisco?" },
{ role: "assistant", content: first.content },
{
role: "user",
content: [
{
type: "tool_result",
tool_use_id: call.id,
content: JSON.stringify(result),
},
],
},
],
tools: [
{
name: "get_weather",
description: "Get the current weather for a city",
input_schema: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
},
},
],
});
}