import Anthropic from "npm:@anthropic-ai/sdk";
const anthropic = new Anthropic({
});
const modelMap = {
opus: "claude-3-opus-20240229",
sonnet: "claude-3-sonnet-20240229",
haiku: "claude-3-haiku-20240307",
};
export async function prompt(
text,
{ mode = "text", model = "opus", max_tokens = 1024, messages = [] } = {},
) {
const modelId = modelMap[model] || model;
console.log('modelId: ', modelId);
messages.push({ role: "user", content: text });
let res = await anthropic.messages.create({
model: modelId,
max_tokens,
messages,
});
if (mode == "text") return res.content?.[0].text;
return {...res, model: modelId};
}