@ai-sdk/amazon-bedrock
Advanced tools
Comparing version 0.0.29 to 0.0.30
@@ -29,5 +29,4 @@ "use strict"; | ||
// src/bedrock-provider.ts | ||
var import_provider3 = require("@ai-sdk/provider"); | ||
var import_provider_utils = require("@ai-sdk/provider-utils"); | ||
var import_client_bedrock_runtime2 = require("@aws-sdk/client-bedrock-runtime"); | ||
var import_client_bedrock_runtime3 = require("@aws-sdk/client-bedrock-runtime"); | ||
@@ -542,2 +541,45 @@ // src/bedrock-chat-language-model.ts | ||
// src/bedrock-embedding-model.ts | ||
var import_client_bedrock_runtime2 = require("@aws-sdk/client-bedrock-runtime"); | ||
var BedrockEmbeddingModel = class { | ||
constructor(modelId, settings, config) { | ||
this.specificationVersion = "v1"; | ||
this.provider = "amazon-bedrock"; | ||
this.maxEmbeddingsPerCall = void 0; | ||
this.supportsParallelCalls = true; | ||
this.modelId = modelId; | ||
this.config = config; | ||
this.settings = settings; | ||
} | ||
async doEmbed({ | ||
values | ||
}) { | ||
const fn = async (inputText) => { | ||
const payload = { | ||
inputText, | ||
dimensions: this.settings.dimensions, | ||
normalize: this.settings.normalize | ||
}; | ||
const command = new import_client_bedrock_runtime2.InvokeModelCommand({ | ||
contentType: "application/json", | ||
body: JSON.stringify(payload), | ||
modelId: this.modelId | ||
}); | ||
const rawResponse = await this.config.client.send(command); | ||
const parsed = JSON.parse(new TextDecoder().decode(rawResponse.body)); | ||
return parsed; | ||
}; | ||
const responses = await Promise.all(values.map(fn)); | ||
const response = responses.reduce( | ||
(acc, r) => { | ||
acc.embeddings.push(r.embedding); | ||
acc.usage.tokens += r.inputTextTokenCount; | ||
return acc; | ||
}, | ||
{ embeddings: [], usage: { tokens: 0 } } | ||
); | ||
return response; | ||
} | ||
}; | ||
// src/bedrock-provider.ts | ||
@@ -547,3 +589,3 @@ function createAmazonBedrock(options = {}) { | ||
var _a; | ||
return new import_client_bedrock_runtime2.BedrockRuntimeClient( | ||
return new import_client_bedrock_runtime3.BedrockRuntimeClient( | ||
(_a = options.bedrockOptions) != null ? _a : { | ||
@@ -589,6 +631,9 @@ region: (0, import_provider_utils.loadSetting)({ | ||
}; | ||
const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, settings, { | ||
client: createBedrockRuntimeClient() | ||
}); | ||
provider.languageModel = createChatModel; | ||
provider.textEmbeddingModel = (modelId) => { | ||
throw new import_provider3.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" }); | ||
}; | ||
provider.embedding = createEmbeddingModel; | ||
provider.textEmbedding = createEmbeddingModel; | ||
provider.textEmbeddingModel = createEmbeddingModel; | ||
return provider; | ||
@@ -595,0 +640,0 @@ } |
# @ai-sdk/amazon-bedrock | ||
## 0.0.30 | ||
### Patch Changes | ||
- 59d1abf: feat (provider/bedrock): support Bedrock amazon.titan-embed-text-v1 and amazon.titan-embed-text-v2:0 embeddings | ||
## 0.0.29 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { ProviderV1, LanguageModelV1 } from '@ai-sdk/provider'; | ||
import { ProviderV1, LanguageModelV1, EmbeddingModelV1 } from '@ai-sdk/provider'; | ||
import { BedrockRuntimeClientConfig } from '@aws-sdk/client-bedrock-runtime'; | ||
@@ -14,2 +14,16 @@ | ||
type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | (string & {}); | ||
interface BedrockEmbeddingSettings { | ||
/** | ||
The number of dimensions the resulting output embeddings should have (defaults to 1024). | ||
Only supported in amazon.titan-embed-text-v2:0. | ||
*/ | ||
dimensions?: 1024 | 512 | 256; | ||
/** | ||
Flag indicating whether or not to normalize the output embeddings. Defaults to true | ||
Only supported in amazon.titan-embed-text-v2:0. | ||
*/ | ||
normalize?: boolean; | ||
} | ||
interface AmazonBedrockProviderSettings { | ||
@@ -31,2 +45,3 @@ region?: string; | ||
languageModel(modelId: BedrockChatModelId, settings?: BedrockChatSettings): LanguageModelV1; | ||
embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings): EmbeddingModelV1<string>; | ||
} | ||
@@ -33,0 +48,0 @@ /** |
@@ -29,5 +29,4 @@ "use strict"; | ||
// src/bedrock-provider.ts | ||
var import_provider3 = require("@ai-sdk/provider"); | ||
var import_provider_utils = require("@ai-sdk/provider-utils"); | ||
var import_client_bedrock_runtime2 = require("@aws-sdk/client-bedrock-runtime"); | ||
var import_client_bedrock_runtime3 = require("@aws-sdk/client-bedrock-runtime"); | ||
@@ -542,2 +541,45 @@ // src/bedrock-chat-language-model.ts | ||
// src/bedrock-embedding-model.ts | ||
var import_client_bedrock_runtime2 = require("@aws-sdk/client-bedrock-runtime"); | ||
var BedrockEmbeddingModel = class { | ||
constructor(modelId, settings, config) { | ||
this.specificationVersion = "v1"; | ||
this.provider = "amazon-bedrock"; | ||
this.maxEmbeddingsPerCall = void 0; | ||
this.supportsParallelCalls = true; | ||
this.modelId = modelId; | ||
this.config = config; | ||
this.settings = settings; | ||
} | ||
async doEmbed({ | ||
values | ||
}) { | ||
const fn = async (inputText) => { | ||
const payload = { | ||
inputText, | ||
dimensions: this.settings.dimensions, | ||
normalize: this.settings.normalize | ||
}; | ||
const command = new import_client_bedrock_runtime2.InvokeModelCommand({ | ||
contentType: "application/json", | ||
body: JSON.stringify(payload), | ||
modelId: this.modelId | ||
}); | ||
const rawResponse = await this.config.client.send(command); | ||
const parsed = JSON.parse(new TextDecoder().decode(rawResponse.body)); | ||
return parsed; | ||
}; | ||
const responses = await Promise.all(values.map(fn)); | ||
const response = responses.reduce( | ||
(acc, r) => { | ||
acc.embeddings.push(r.embedding); | ||
acc.usage.tokens += r.inputTextTokenCount; | ||
return acc; | ||
}, | ||
{ embeddings: [], usage: { tokens: 0 } } | ||
); | ||
return response; | ||
} | ||
}; | ||
// src/bedrock-provider.ts | ||
@@ -547,3 +589,3 @@ function createAmazonBedrock(options = {}) { | ||
var _a; | ||
return new import_client_bedrock_runtime2.BedrockRuntimeClient( | ||
return new import_client_bedrock_runtime3.BedrockRuntimeClient( | ||
(_a = options.bedrockOptions) != null ? _a : { | ||
@@ -589,6 +631,9 @@ region: (0, import_provider_utils.loadSetting)({ | ||
}; | ||
const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, settings, { | ||
client: createBedrockRuntimeClient() | ||
}); | ||
provider.languageModel = createChatModel; | ||
provider.textEmbeddingModel = (modelId) => { | ||
throw new import_provider3.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" }); | ||
}; | ||
provider.embedding = createEmbeddingModel; | ||
provider.textEmbedding = createEmbeddingModel; | ||
provider.textEmbeddingModel = createEmbeddingModel; | ||
return provider; | ||
@@ -595,0 +640,0 @@ } |
{ | ||
"name": "@ai-sdk/amazon-bedrock", | ||
"version": "0.0.29", | ||
"version": "0.0.30", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
154251
1944