Skip to content

Commit

Permalink
chore: lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Oct 13, 2023
1 parent af3c98b commit 50a27e1
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions langchain/src/embeddings/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,40 @@ export class BedrockEmbeddings

/** @deprecated */
protected async _embedText(text: string): Promise<number[]> {
// replace newlines, which can negatively affect performance.
const cleanedText = text.replace(/\n/g, " ");

const res = await this.client.send(
new InvokeModelCommand({
modelId: this.model,
body: JSON.stringify({
inputText: cleanedText,
}),
contentType: "application/json",
accept: "application/json",
})
);
return this.caller.call(async () => {
try {
// replace newlines, which can negatively affect performance.
const cleanedText = inputText.replace(/\n/g, " ");

try {
const body = new TextDecoder().decode(res.body);
const res = await this.client.send(
new InvokeModelCommand({
modelId: this.model,
body: JSON.stringify({
inputText: cleanedText,
}),
contentType: "application/json",
accept: "application/json",
})
);

return JSON.parse(body).embedding;
} catch (e) {
throw new Error("An invalid response was returned by Bedrock.");
}
const body = new TextDecoder().decode(res.body);
return JSON.parse(body).embedding;
} catch (e) {
console.error({
error: e,
});
// eslint-disable-next-line no-instanceof/no-instanceof
if (e instanceof Error) {
throw new Error(
`An error occurred while embedding documents with Bedrock: ${e.message}`
);
}

throw new Error(
"An error occurred while embedding documents with Bedrock"
);
}
});
}

/**
Expand Down

0 comments on commit 50a27e1

Please sign in to comment.