import fs from "fs-extra";
const baseUrl = "https://api.assemblyai.com";
const headers = { authorization: "<YOUR_API_KEY>" };
// Step 1: Transcribe the sales call
const audioData = await fs.readFile("./sales-call.mp3");
let res = await fetch(`${baseUrl}/v2/upload`, {
method: "POST",
headers,
body: audioData,
});
if (!res.ok) throw new Error(`Error: ${res.status}`);
const uploadResponse = await res.json();
const uploadUrl = uploadResponse.upload_url;
const data = { audio_url: uploadUrl, speech_models: ["universal-3-pro"] };
res = await fetch(`${baseUrl}/v2/transcript`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!res.ok) throw new Error(`Error: ${res.status}`);
const transcriptResponse = await res.json();
const transcriptId = transcriptResponse.id;
const pollingEndpoint = `${baseUrl}/v2/transcript/${transcriptId}`;
let transcriptionResult;
while (true) {
res = await fetch(pollingEndpoint, { headers });
if (!res.ok) throw new Error(`Error: ${res.status}`);
transcriptionResult = await res.json();
if (transcriptionResult.status === "completed") {
break;
} else if (transcriptionResult.status === "error") {
throw new Error(`Transcription failed: ${transcriptionResult.error}`);
} else {
await new Promise((resolve) => setTimeout(resolve, 3000));
}
}
// Step 2: Evaluate with LLM Gateway
const context = "There are sales interactions between a salesperson who is selling an internet plan to customers who are warm leads.";
const answerFormat = `
Answer with JSON in the following format:
{
"Answer": "<answer_options>",
"Reason": "<justification for the answer in one sentence including quotes>"
}
`;
const questions = [
{
question: "Did the salesperson start the conversation with a professional greeting?",
answerOptions: ["Poor", "Satisfactory", "Excellent"]
},
{
question: "How well did the salesperson answer questions during the call?",
answerOptions: ["Poor", "Good", "Excellent"]
},
{
question: "Did the salesperson discuss next steps clearly?",
answerOptions: ["Yes", "No"]
}
];
for (const q of questions) {
const prompt = `
${q.question}
Context: ${context}
Answer Options: ${q.answerOptions.join(", ")}
${answerFormat}
`;
const llmGatewayData = {
model: "claude-sonnet-4-5-20250929",
messages: [
{ role: "user", content: `${prompt}\n\n{{ transcript }}` }
],
transcript_id: transcriptId,
max_tokens: 500
};
res = await fetch("https://llm-gateway.assemblyai.com/v1/chat/completions", {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify(llmGatewayData),
});
if (!res.ok) throw new Error(`Error: ${res.status}`);
const response = await res.json();
const result = response.choices[0].message.content;
console.log(`Question: ${q.question}`);
console.log(`Answer: ${result}`);
console.log();
}