Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisTraub committed Mar 19, 2024
1 parent 3c6ecae commit 4d40a20
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ export const invokeModelWithResponseStream = async (prompt, modelId) => {
],
};

// Invoke Claude with the payload and wait for the API to respond.
const command = new InvokeModelWithResponseStreamCommand({
contentType: "application/json",
body: JSON.stringify(payload),
modelId,
});

const apiResponse = await client.send(command);

let role;
let final_message = "";

// Decode and process the response stream
for await (const item of apiResponse.body) {
/** @type Chunk */
const chunk = JSON.parse(new TextDecoder().decode(item.chunk.bytes));
Expand All @@ -134,17 +135,11 @@ export const invokeModelWithResponseStream = async (prompt, modelId) => {
}
}

const final_response = {
// Return the final response
return {
role: role,
content: [
{
type: "text",
text: final_message,
},
],
content: [{ type: "text", text: final_message }],
};

return final_response;
};

// Invoke the function if this file was run directly.
Expand Down

0 comments on commit 4d40a20

Please sign in to comment.