@ai-sdk/amazon-bedrock 4.0.28 → 4.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +9 -5
- package/src/__fixtures__/bedrock-json-only-text-first.1.chunks.txt +0 -7
- package/src/__fixtures__/bedrock-json-other-tool.1.chunks.txt +0 -6
- package/src/__fixtures__/bedrock-json-other-tool.1.json +0 -24
- package/src/__fixtures__/bedrock-json-tool-text-then-weather-then-json.1.chunks.txt +0 -12
- package/src/__fixtures__/bedrock-json-tool-with-answer.1.json +0 -29
- package/src/__fixtures__/bedrock-json-tool.1.chunks.txt +0 -4
- package/src/__fixtures__/bedrock-json-tool.1.json +0 -35
- package/src/__fixtures__/bedrock-json-tool.2.chunks.txt +0 -6
- package/src/__fixtures__/bedrock-json-tool.2.json +0 -28
- package/src/__fixtures__/bedrock-json-tool.3.chunks.txt +0 -7
- package/src/__fixtures__/bedrock-json-tool.3.json +0 -36
- package/src/__fixtures__/bedrock-json-with-tool.1.chunks.txt +0 -9
- package/src/__fixtures__/bedrock-json-with-tool.1.json +0 -41
- package/src/__fixtures__/bedrock-json-with-tools.1.chunks.txt +0 -12
- package/src/__fixtures__/bedrock-json-with-tools.1.json +0 -50
- package/src/__fixtures__/bedrock-tool-call.1.chunks.txt +0 -6
- package/src/__fixtures__/bedrock-tool-call.1.json +0 -24
- package/src/__fixtures__/bedrock-tool-no-args.chunks.txt +0 -8
- package/src/__fixtures__/bedrock-tool-no-args.json +0 -25
- package/src/anthropic/bedrock-anthropic-fetch.test.ts +0 -344
- package/src/anthropic/bedrock-anthropic-provider.test.ts +0 -456
- package/src/bedrock-chat-language-model.test.ts +0 -4569
- package/src/bedrock-embedding-model.test.ts +0 -148
- package/src/bedrock-event-stream-response-handler.test.ts +0 -233
- package/src/bedrock-image-model.test.ts +0 -866
- package/src/bedrock-provider.test.ts +0 -457
- package/src/bedrock-sigv4-fetch.test.ts +0 -675
- package/src/convert-bedrock-usage.test.ts +0 -207
- package/src/convert-to-bedrock-chat-messages.test.ts +0 -1175
- package/src/inject-fetch-headers.test.ts +0 -135
- package/src/normalize-tool-call-id.test.ts +0 -72
- package/src/reranking/__fixtures__/bedrock-reranking.1.json +0 -12
- package/src/reranking/bedrock-reranking-model.test.ts +0 -299
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { injectFetchHeaders } from './inject-fetch-headers';
|
|
2
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
3
|
-
|
|
4
|
-
// Mock the version module
|
|
5
|
-
vi.mock('./version', () => ({
|
|
6
|
-
VERSION: '0.0.0-test',
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
// // Mock provider-utils to control runtime environment detection
|
|
10
|
-
vi.mock('@ai-sdk/provider-utils', async () => {
|
|
11
|
-
const actual = await vi.importActual('@ai-sdk/provider-utils');
|
|
12
|
-
return {
|
|
13
|
-
...actual,
|
|
14
|
-
getRuntimeEnvironmentUserAgent: vi.fn(() => 'runtime/testenv'),
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('injectFetchHeaders', () => {
|
|
19
|
-
const originalFetch = globalThis.fetch;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
globalThis.fetch = vi.fn();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
globalThis.fetch = originalFetch;
|
|
27
|
-
vi.clearAllMocks();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should inject custom headers into fetch request', async () => {
|
|
31
|
-
const mockFetch = vi.fn().mockResolvedValue('response');
|
|
32
|
-
globalThis.fetch = mockFetch;
|
|
33
|
-
|
|
34
|
-
const customHeaders = {
|
|
35
|
-
'x-custom-header': 'custom-value',
|
|
36
|
-
authorization: 'Bearer token',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const enhancedFetch = injectFetchHeaders(customHeaders);
|
|
40
|
-
await enhancedFetch('https://api.example.com');
|
|
41
|
-
|
|
42
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
43
|
-
'https://api.example.com',
|
|
44
|
-
expect.objectContaining({
|
|
45
|
-
headers: expect.objectContaining({
|
|
46
|
-
'x-custom-header': 'custom-value',
|
|
47
|
-
authorization: 'Bearer token',
|
|
48
|
-
'user-agent': 'ai-sdk/amazon-bedrock/0.0.0-test runtime/testenv',
|
|
49
|
-
}),
|
|
50
|
-
}),
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should merge custom headers with existing headers', async () => {
|
|
55
|
-
const mockFetch = vi.fn().mockResolvedValue('response');
|
|
56
|
-
globalThis.fetch = mockFetch;
|
|
57
|
-
|
|
58
|
-
const customHeaders = {
|
|
59
|
-
'x-custom-header': 'custom-value',
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const existingHeaders = {
|
|
63
|
-
'Content-Type': 'application/json',
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const enhancedFetch = injectFetchHeaders(customHeaders);
|
|
67
|
-
await enhancedFetch('https://api.example.com', {
|
|
68
|
-
headers: existingHeaders,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
72
|
-
'https://api.example.com',
|
|
73
|
-
expect.objectContaining({
|
|
74
|
-
headers: expect.objectContaining({
|
|
75
|
-
'content-type': 'application/json',
|
|
76
|
-
'x-custom-header': 'custom-value',
|
|
77
|
-
'user-agent': 'ai-sdk/amazon-bedrock/0.0.0-test runtime/testenv',
|
|
78
|
-
}),
|
|
79
|
-
}),
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should handle undefined headers in init', async () => {
|
|
84
|
-
const mockFetch = vi.fn().mockResolvedValue('response');
|
|
85
|
-
globalThis.fetch = mockFetch;
|
|
86
|
-
|
|
87
|
-
const customHeaders = {
|
|
88
|
-
'x-custom-header': 'custom-value',
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const enhancedFetch = injectFetchHeaders(customHeaders);
|
|
92
|
-
await enhancedFetch('https://api.example.com', {
|
|
93
|
-
headers: undefined,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
97
|
-
'https://api.example.com',
|
|
98
|
-
expect.objectContaining({
|
|
99
|
-
headers: expect.objectContaining({
|
|
100
|
-
'x-custom-header': 'custom-value',
|
|
101
|
-
'user-agent': 'ai-sdk/amazon-bedrock/0.0.0-test runtime/testenv',
|
|
102
|
-
}),
|
|
103
|
-
}),
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should handle Headers instance in init', async () => {
|
|
108
|
-
const mockFetch = vi.fn().mockResolvedValue('response');
|
|
109
|
-
globalThis.fetch = mockFetch;
|
|
110
|
-
|
|
111
|
-
const customHeaders = {
|
|
112
|
-
'x-custom-header': 'custom-value',
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const existingHeaders = new Headers({
|
|
116
|
-
'Content-Type': 'application/json',
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const enhancedFetch = injectFetchHeaders(customHeaders);
|
|
120
|
-
await enhancedFetch('https://api.example.com', {
|
|
121
|
-
headers: existingHeaders,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
125
|
-
'https://api.example.com',
|
|
126
|
-
expect.objectContaining({
|
|
127
|
-
headers: expect.objectContaining({
|
|
128
|
-
'content-type': 'application/json',
|
|
129
|
-
'x-custom-header': 'custom-value',
|
|
130
|
-
'user-agent': 'ai-sdk/amazon-bedrock/0.0.0-test runtime/testenv',
|
|
131
|
-
}),
|
|
132
|
-
}),
|
|
133
|
-
);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { isMistralModel, normalizeToolCallId } from './normalize-tool-call-id';
|
|
3
|
-
|
|
4
|
-
describe('isMistralModel', () => {
|
|
5
|
-
it('should return true for mistral models', () => {
|
|
6
|
-
expect(isMistralModel('mistral.mistral-7b-instruct-v0:2')).toBe(true);
|
|
7
|
-
expect(isMistralModel('mistral.mixtral-8x7b-instruct-v0:1')).toBe(true);
|
|
8
|
-
expect(isMistralModel('mistral.mistral-large-2402-v1:0')).toBe(true);
|
|
9
|
-
expect(isMistralModel('mistral.mistral-small-2402-v1:0')).toBe(true);
|
|
10
|
-
expect(isMistralModel('mistral.mistral-large-2407-v1:0')).toBe(true);
|
|
11
|
-
expect(isMistralModel('mistral.ministral-3-14b-instruct')).toBe(true);
|
|
12
|
-
expect(isMistralModel('mistral.ministral-3-8b-instruct')).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return true for region-prefixed mistral models', () => {
|
|
16
|
-
expect(isMistralModel('us.mistral.pixtral-large-2502-v1:0')).toBe(true);
|
|
17
|
-
expect(isMistralModel('eu.mistral.mistral-large-2407-v1:0')).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should return false for non-mistral models', () => {
|
|
21
|
-
expect(isMistralModel('anthropic.claude-3-5-sonnet-20241022-v2:0')).toBe(
|
|
22
|
-
false,
|
|
23
|
-
);
|
|
24
|
-
expect(isMistralModel('amazon.nova-pro-v1:0')).toBe(false);
|
|
25
|
-
expect(isMistralModel('openai.gpt-4o')).toBe(false);
|
|
26
|
-
expect(isMistralModel('meta.llama3-70b-instruct-v1:0')).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('normalizeToolCallId', () => {
|
|
31
|
-
it('should return the original ID when not a Mistral model', () => {
|
|
32
|
-
const originalId = 'tooluse_bpe71yCfRu2b5i-nKGDr5g';
|
|
33
|
-
expect(normalizeToolCallId(originalId, false)).toBe(originalId);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should extract first 9 alphanumeric characters for Mistral models', () => {
|
|
37
|
-
// Bedrock format: tooluse_bpe71yCfRu2b5i-nKGDr5g
|
|
38
|
-
// After removing non-alphanumeric: toolusebpe71yCfRu2b5inKGDr5g
|
|
39
|
-
// First 9 chars: toolusebp
|
|
40
|
-
expect(normalizeToolCallId('tooluse_bpe71yCfRu2b5i-nKGDr5g', true)).toBe(
|
|
41
|
-
'toolusebp',
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should handle IDs with various special characters', () => {
|
|
46
|
-
expect(normalizeToolCallId('tool-use_123ABC456', true)).toBe('tooluse12');
|
|
47
|
-
expect(normalizeToolCallId('___abc123DEF___', true)).toBe('abc123DEF');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should handle IDs that are already alphanumeric', () => {
|
|
51
|
-
expect(normalizeToolCallId('abcdefghi', true)).toBe('abcdefghi');
|
|
52
|
-
expect(normalizeToolCallId('abc123XYZ', true)).toBe('abc123XYZ');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should handle short IDs', () => {
|
|
56
|
-
expect(normalizeToolCallId('abc', true)).toBe('abc');
|
|
57
|
-
expect(normalizeToolCallId('12345', true)).toBe('12345');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should handle IDs with only special characters', () => {
|
|
61
|
-
expect(normalizeToolCallId('___---___', true)).toBe('');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should produce valid Mistral tool call IDs (9 alphanumeric chars)', () => {
|
|
65
|
-
const normalizedId = normalizeToolCallId(
|
|
66
|
-
'tooluse_bpe71yCfRu2b5i-nKGDr5g',
|
|
67
|
-
true,
|
|
68
|
-
);
|
|
69
|
-
// Verify the ID matches Mistral's requirements: ^[a-zA-Z0-9]{1,9}$
|
|
70
|
-
expect(normalizedId).toMatch(/^[a-zA-Z0-9]{1,9}$/);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import { createTestServer } from '@ai-sdk/test-server/with-vitest';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
-
import { injectFetchHeaders } from '../inject-fetch-headers';
|
|
5
|
-
import { BedrockRerankingModel } from './bedrock-reranking-model';
|
|
6
|
-
import { BedrockRerankingOptions } from './bedrock-reranking-options';
|
|
7
|
-
|
|
8
|
-
const fakeFetchWithAuth = injectFetchHeaders({ 'x-amz-auth': 'test-auth' });
|
|
9
|
-
|
|
10
|
-
const model = new BedrockRerankingModel('cohere.rerank-v3-5:0', {
|
|
11
|
-
baseUrl: () => 'https://bedrock-agent-runtime.us-east-1.amazonaws.com',
|
|
12
|
-
region: 'us-west-2',
|
|
13
|
-
headers: {
|
|
14
|
-
'config-header': 'config-value',
|
|
15
|
-
'shared-header': 'config-shared',
|
|
16
|
-
},
|
|
17
|
-
fetch: fakeFetchWithAuth,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('doRerank', () => {
|
|
21
|
-
const server = createTestServer({
|
|
22
|
-
'https://bedrock-agent-runtime.us-east-1.amazonaws.com/rerank': {},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
function prepareJsonFixtureResponse(filename: string) {
|
|
26
|
-
server.urls[
|
|
27
|
-
'https://bedrock-agent-runtime.us-east-1.amazonaws.com/rerank'
|
|
28
|
-
].response = {
|
|
29
|
-
type: 'binary',
|
|
30
|
-
headers: { 'content-type': 'application/json' },
|
|
31
|
-
body: Buffer.from(
|
|
32
|
-
fs.readFileSync(`src/reranking/__fixtures__/${filename}.json`, 'utf8'),
|
|
33
|
-
),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe('json documents', () => {
|
|
38
|
-
let result: Awaited<ReturnType<typeof model.doRerank>>;
|
|
39
|
-
|
|
40
|
-
beforeEach(async () => {
|
|
41
|
-
prepareJsonFixtureResponse('bedrock-reranking.1');
|
|
42
|
-
|
|
43
|
-
result = await model.doRerank({
|
|
44
|
-
documents: {
|
|
45
|
-
type: 'object',
|
|
46
|
-
values: [
|
|
47
|
-
{ example: 'sunny day at the beach' },
|
|
48
|
-
{ example: 'rainy day in the city' },
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
query: 'rainy day',
|
|
52
|
-
topN: 2,
|
|
53
|
-
providerOptions: {
|
|
54
|
-
bedrock: {
|
|
55
|
-
nextToken: 'test-token',
|
|
56
|
-
additionalModelRequestFields: {
|
|
57
|
-
test: 'test-value',
|
|
58
|
-
},
|
|
59
|
-
} satisfies BedrockRerankingOptions,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should send request with stringified json documents', async () => {
|
|
65
|
-
expect(await server.calls[0].requestBodyJson).toMatchInlineSnapshot(`
|
|
66
|
-
{
|
|
67
|
-
"nextToken": "test-token",
|
|
68
|
-
"queries": [
|
|
69
|
-
{
|
|
70
|
-
"textQuery": {
|
|
71
|
-
"text": "rainy day",
|
|
72
|
-
},
|
|
73
|
-
"type": "TEXT",
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
"rerankingConfiguration": {
|
|
77
|
-
"bedrockRerankingConfiguration": {
|
|
78
|
-
"modelConfiguration": {
|
|
79
|
-
"additionalModelRequestFields": {
|
|
80
|
-
"test": "test-value",
|
|
81
|
-
},
|
|
82
|
-
"modelArn": "arn:aws:bedrock:us-west-2::foundation-model/cohere.rerank-v3-5:0",
|
|
83
|
-
},
|
|
84
|
-
"numberOfResults": 2,
|
|
85
|
-
},
|
|
86
|
-
"type": "BEDROCK_RERANKING_MODEL",
|
|
87
|
-
},
|
|
88
|
-
"sources": [
|
|
89
|
-
{
|
|
90
|
-
"inlineDocumentSource": {
|
|
91
|
-
"jsonDocument": {
|
|
92
|
-
"example": "sunny day at the beach",
|
|
93
|
-
},
|
|
94
|
-
"type": "JSON",
|
|
95
|
-
},
|
|
96
|
-
"type": "INLINE",
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"inlineDocumentSource": {
|
|
100
|
-
"jsonDocument": {
|
|
101
|
-
"example": "rainy day in the city",
|
|
102
|
-
},
|
|
103
|
-
"type": "JSON",
|
|
104
|
-
},
|
|
105
|
-
"type": "INLINE",
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
}
|
|
109
|
-
`);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should send request with the correct headers', async () => {
|
|
113
|
-
expect(server.calls[0].requestHeaders).toMatchInlineSnapshot(`
|
|
114
|
-
{
|
|
115
|
-
"config-header": "config-value",
|
|
116
|
-
"content-type": "application/json",
|
|
117
|
-
"shared-header": "config-shared",
|
|
118
|
-
"x-amz-auth": "test-auth",
|
|
119
|
-
}
|
|
120
|
-
`);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should return result with warnings', async () => {
|
|
124
|
-
expect(result.warnings).toMatchInlineSnapshot(`undefined`);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should return result with the correct ranking', async () => {
|
|
128
|
-
expect(result.ranking).toMatchInlineSnapshot(`
|
|
129
|
-
[
|
|
130
|
-
{
|
|
131
|
-
"index": 0,
|
|
132
|
-
"relevanceScore": 0.5110583305358887,
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
"index": 5,
|
|
136
|
-
"relevanceScore": 0.30241215229034424,
|
|
137
|
-
},
|
|
138
|
-
]
|
|
139
|
-
`);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should not return provider metadata (use response body instead)', async () => {
|
|
143
|
-
expect(result.providerMetadata).toMatchInlineSnapshot(`undefined`);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('should return result with the correct response', async () => {
|
|
147
|
-
expect(result.response).toMatchInlineSnapshot(`
|
|
148
|
-
{
|
|
149
|
-
"body": {
|
|
150
|
-
"results": [
|
|
151
|
-
{
|
|
152
|
-
"index": 0,
|
|
153
|
-
"relevanceScore": 0.5110583305358887,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
"index": 5,
|
|
157
|
-
"relevanceScore": 0.30241215229034424,
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
},
|
|
161
|
-
"headers": {
|
|
162
|
-
"content-length": "171",
|
|
163
|
-
"content-type": "application/json",
|
|
164
|
-
},
|
|
165
|
-
}
|
|
166
|
-
`);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe('text documents', () => {
|
|
171
|
-
let result: Awaited<ReturnType<typeof model.doRerank>>;
|
|
172
|
-
|
|
173
|
-
beforeEach(async () => {
|
|
174
|
-
prepareJsonFixtureResponse('bedrock-reranking.1');
|
|
175
|
-
|
|
176
|
-
result = await model.doRerank({
|
|
177
|
-
documents: {
|
|
178
|
-
type: 'text',
|
|
179
|
-
values: ['sunny day at the beach', 'rainy day in the city'],
|
|
180
|
-
},
|
|
181
|
-
query: 'rainy day',
|
|
182
|
-
topN: 2,
|
|
183
|
-
providerOptions: {
|
|
184
|
-
bedrock: {
|
|
185
|
-
nextToken: 'test-token',
|
|
186
|
-
additionalModelRequestFields: {
|
|
187
|
-
test: 'test-value',
|
|
188
|
-
},
|
|
189
|
-
} satisfies BedrockRerankingOptions,
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('should send request with text documents', async () => {
|
|
195
|
-
expect(await server.calls[0].requestBodyJson).toMatchInlineSnapshot(`
|
|
196
|
-
{
|
|
197
|
-
"nextToken": "test-token",
|
|
198
|
-
"queries": [
|
|
199
|
-
{
|
|
200
|
-
"textQuery": {
|
|
201
|
-
"text": "rainy day",
|
|
202
|
-
},
|
|
203
|
-
"type": "TEXT",
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
"rerankingConfiguration": {
|
|
207
|
-
"bedrockRerankingConfiguration": {
|
|
208
|
-
"modelConfiguration": {
|
|
209
|
-
"additionalModelRequestFields": {
|
|
210
|
-
"test": "test-value",
|
|
211
|
-
},
|
|
212
|
-
"modelArn": "arn:aws:bedrock:us-west-2::foundation-model/cohere.rerank-v3-5:0",
|
|
213
|
-
},
|
|
214
|
-
"numberOfResults": 2,
|
|
215
|
-
},
|
|
216
|
-
"type": "BEDROCK_RERANKING_MODEL",
|
|
217
|
-
},
|
|
218
|
-
"sources": [
|
|
219
|
-
{
|
|
220
|
-
"inlineDocumentSource": {
|
|
221
|
-
"textDocument": {
|
|
222
|
-
"text": "sunny day at the beach",
|
|
223
|
-
},
|
|
224
|
-
"type": "TEXT",
|
|
225
|
-
},
|
|
226
|
-
"type": "INLINE",
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
"inlineDocumentSource": {
|
|
230
|
-
"textDocument": {
|
|
231
|
-
"text": "rainy day in the city",
|
|
232
|
-
},
|
|
233
|
-
"type": "TEXT",
|
|
234
|
-
},
|
|
235
|
-
"type": "INLINE",
|
|
236
|
-
},
|
|
237
|
-
],
|
|
238
|
-
}
|
|
239
|
-
`);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('should send request with the correct headers', async () => {
|
|
243
|
-
expect(server.calls[0].requestHeaders).toMatchInlineSnapshot(`
|
|
244
|
-
{
|
|
245
|
-
"config-header": "config-value",
|
|
246
|
-
"content-type": "application/json",
|
|
247
|
-
"shared-header": "config-shared",
|
|
248
|
-
"x-amz-auth": "test-auth",
|
|
249
|
-
}
|
|
250
|
-
`);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('should return result without warnings', async () => {
|
|
254
|
-
expect(result.warnings).toMatchInlineSnapshot(`undefined`);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('should return result with the correct ranking', async () => {
|
|
258
|
-
expect(result.ranking).toMatchInlineSnapshot(`
|
|
259
|
-
[
|
|
260
|
-
{
|
|
261
|
-
"index": 0,
|
|
262
|
-
"relevanceScore": 0.5110583305358887,
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
"index": 5,
|
|
266
|
-
"relevanceScore": 0.30241215229034424,
|
|
267
|
-
},
|
|
268
|
-
]
|
|
269
|
-
`);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('should not return provider metadata (use response body instead)', async () => {
|
|
273
|
-
expect(result.providerMetadata).toMatchInlineSnapshot(`undefined`);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it('should return result with the correct response', async () => {
|
|
277
|
-
expect(result.response).toMatchInlineSnapshot(`
|
|
278
|
-
{
|
|
279
|
-
"body": {
|
|
280
|
-
"results": [
|
|
281
|
-
{
|
|
282
|
-
"index": 0,
|
|
283
|
-
"relevanceScore": 0.5110583305358887,
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
"index": 5,
|
|
287
|
-
"relevanceScore": 0.30241215229034424,
|
|
288
|
-
},
|
|
289
|
-
],
|
|
290
|
-
},
|
|
291
|
-
"headers": {
|
|
292
|
-
"content-length": "171",
|
|
293
|
-
"content-type": "application/json",
|
|
294
|
-
},
|
|
295
|
-
}
|
|
296
|
-
`);
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
});
|