mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# Backport This will backport the following commits from `main` to `9.0`: - [[Stack connectors] Fix bedrock `modelId` encoding (#216915)](https://github.com/elastic/kibana/pull/216915) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Steph Milovic","email":"stephanie.milovic@elastic.co"},"sourceCommit":{"committedDate":"2025-04-03T15:56:14Z","message":"[Stack connectors] Fix bedrock `modelId` encoding (#216915)","sha":"1edb366cb984dce3281ed4713f6f564a93bb1c2a","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team: SecuritySolution","sdh-linked","Team:Security Generative AI","backport:version","v9.1.0","v8.19.0","v8.18.1","v9.0.1","v8.17.5"],"title":"[Stack connectors] Fix bedrock `modelId` encoding","number":216915,"url":"https://github.com/elastic/kibana/pull/216915","mergeCommit":{"message":"[Stack connectors] Fix bedrock `modelId` encoding (#216915)","sha":"1edb366cb984dce3281ed4713f6f564a93bb1c2a"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.18","9.0","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216915","number":216915,"mergeCommit":{"message":"[Stack connectors] Fix bedrock `modelId` encoding (#216915)","sha":"1edb366cb984dce3281ed4713f6f564a93bb1c2a"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Steph Milovic <stephanie.milovic@elastic.co>
This commit is contained in:
parent
82a091da5a
commit
3663021e1b
3 changed files with 23 additions and 17 deletions
|
@ -31,6 +31,7 @@ jest.mock('../lib/gen_ai/create_gen_ai_dashboard');
|
|||
// @ts-ignore
|
||||
const mockSigner = jest.spyOn(aws, 'sign').mockReturnValue({ signed: true });
|
||||
const mockSend = jest.fn();
|
||||
const encodedModel = encodeURIComponent(DEFAULT_BEDROCK_MODEL);
|
||||
describe('BedrockConnector', () => {
|
||||
let mockRequest: jest.Mock;
|
||||
let mockError: jest.Mock;
|
||||
|
@ -111,7 +112,7 @@ describe('BedrockConnector', () => {
|
|||
'Content-Type': 'application/json',
|
||||
},
|
||||
host: 'bedrock-runtime.us-east-1.amazonaws.com',
|
||||
path: '/model/anthropic.claude-3-5-sonnet-20240620-v1:0/invoke',
|
||||
path: `/model/${encodedModel}/invoke`,
|
||||
service: 'bedrock',
|
||||
},
|
||||
{ accessKeyId: '123', secretAccessKey: 'secret' }
|
||||
|
@ -124,7 +125,7 @@ describe('BedrockConnector', () => {
|
|||
{
|
||||
signed: true,
|
||||
timeout: DEFAULT_TIMEOUT_MS,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke`,
|
||||
method: 'post',
|
||||
responseSchema: RunApiLatestResponseSchema,
|
||||
data: DEFAULT_BODY,
|
||||
|
@ -154,7 +155,7 @@ describe('BedrockConnector', () => {
|
|||
{
|
||||
signed: true,
|
||||
timeout: DEFAULT_TIMEOUT_MS,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke`,
|
||||
method: 'post',
|
||||
responseSchema: RunActionResponseSchema,
|
||||
data: v2Body,
|
||||
|
@ -212,7 +213,7 @@ describe('BedrockConnector', () => {
|
|||
'x-amzn-bedrock-accept': '*/*',
|
||||
},
|
||||
host: 'bedrock-runtime.us-east-1.amazonaws.com',
|
||||
path: '/model/anthropic.claude-3-5-sonnet-20240620-v1:0/invoke-with-response-stream',
|
||||
path: `/model/${encodedModel}/invoke-with-response-stream`,
|
||||
service: 'bedrock',
|
||||
},
|
||||
{ accessKeyId: '123', secretAccessKey: 'secret' }
|
||||
|
@ -225,7 +226,7 @@ describe('BedrockConnector', () => {
|
|||
expect(mockRequest).toHaveBeenCalledWith(
|
||||
{
|
||||
signed: true,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke-with-response-stream`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke-with-response-stream`,
|
||||
method: 'post',
|
||||
responseSchema: StreamingResponseSchema,
|
||||
responseType: 'stream',
|
||||
|
@ -246,7 +247,7 @@ describe('BedrockConnector', () => {
|
|||
expect(mockRequest).toHaveBeenCalledWith(
|
||||
{
|
||||
signed: true,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke-with-response-stream`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke-with-response-stream`,
|
||||
method: 'post',
|
||||
responseSchema: StreamingResponseSchema,
|
||||
responseType: 'stream',
|
||||
|
@ -286,7 +287,7 @@ describe('BedrockConnector', () => {
|
|||
{
|
||||
signed: true,
|
||||
responseType: 'stream',
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke-with-response-stream`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke-with-response-stream`,
|
||||
method: 'post',
|
||||
responseSchema: StreamingResponseSchema,
|
||||
data: JSON.stringify({
|
||||
|
@ -341,7 +342,7 @@ describe('BedrockConnector', () => {
|
|||
{
|
||||
signed: true,
|
||||
responseType: 'stream',
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke-with-response-stream`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke-with-response-stream`,
|
||||
method: 'post',
|
||||
responseSchema: StreamingResponseSchema,
|
||||
data: JSON.stringify({
|
||||
|
@ -442,7 +443,7 @@ describe('BedrockConnector', () => {
|
|||
{
|
||||
signed: true,
|
||||
timeout: DEFAULT_TIMEOUT_MS,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke`,
|
||||
method: 'post',
|
||||
responseSchema: RunApiLatestResponseSchema,
|
||||
data: JSON.stringify({
|
||||
|
@ -486,7 +487,7 @@ describe('BedrockConnector', () => {
|
|||
{
|
||||
signed: true,
|
||||
timeout: DEFAULT_TIMEOUT_MS,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke`,
|
||||
method: 'post',
|
||||
responseSchema: RunApiLatestResponseSchema,
|
||||
data: JSON.stringify({
|
||||
|
@ -532,7 +533,7 @@ describe('BedrockConnector', () => {
|
|||
{
|
||||
signed: true,
|
||||
timeout: DEFAULT_TIMEOUT_MS,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke`,
|
||||
method: 'post',
|
||||
responseSchema: RunApiLatestResponseSchema,
|
||||
data: JSON.stringify({
|
||||
|
@ -582,7 +583,7 @@ describe('BedrockConnector', () => {
|
|||
{
|
||||
signed: true,
|
||||
timeout: DEFAULT_TIMEOUT_MS,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke`,
|
||||
method: 'post',
|
||||
responseSchema: RunApiLatestResponseSchema,
|
||||
data: JSON.stringify({
|
||||
|
@ -609,7 +610,7 @@ describe('BedrockConnector', () => {
|
|||
expect(mockRequest).toHaveBeenCalledWith(
|
||||
{
|
||||
signed: true,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${DEFAULT_BEDROCK_MODEL}/invoke`,
|
||||
url: `${DEFAULT_BEDROCK_URL}/model/${encodedModel}/invoke`,
|
||||
method: 'post',
|
||||
responseSchema: RunApiLatestResponseSchema,
|
||||
data: JSON.stringify({
|
||||
|
|
|
@ -253,7 +253,9 @@ The Kibana Connector in use may need to be reconfigured with an updated Amazon B
|
|||
connectorUsageCollector: ConnectorUsageCollector
|
||||
): Promise<RunActionResponse | InvokeAIRawActionResponse> {
|
||||
// set model on per request basis
|
||||
const currentModel = reqModel ?? this.model;
|
||||
// Application Inference Profile IDs need to be encoded when using the API
|
||||
// Decode first to ensure an existing encoded value is not double encoded
|
||||
const currentModel = encodeURIComponent(decodeURIComponent(reqModel ?? this.model));
|
||||
const path = `/model/${currentModel}/invoke`;
|
||||
const signed = this.signRequest(body, path, false);
|
||||
const requestArgs = {
|
||||
|
@ -298,7 +300,10 @@ The Kibana Connector in use may need to be reconfigured with an updated Amazon B
|
|||
connectorUsageCollector: ConnectorUsageCollector
|
||||
): Promise<StreamingResponse> {
|
||||
// set model on per request basis
|
||||
const path = `/model/${reqModel ?? this.model}/invoke-with-response-stream`;
|
||||
// Application Inference Profile IDs need to be encoded when using the API
|
||||
// Decode first to ensure an existing encoded value is not double encoded
|
||||
const currentModel = encodeURIComponent(decodeURIComponent(reqModel ?? this.model));
|
||||
const path = `/model/${currentModel}/invoke-with-response-stream`;
|
||||
const signed = this.signRequest(body, path, true);
|
||||
|
||||
const response = await this.request(
|
||||
|
|
|
@ -332,7 +332,7 @@ export default function bedrockTest({ getService }: FtrProviderContext) {
|
|||
|
||||
expect(simulator.requestData).to.eql(DEFAULT_BODY);
|
||||
expect(simulator.requestUrl).to.eql(
|
||||
`${apiUrl}/model/${defaultConfig.defaultModel}/invoke`
|
||||
`${apiUrl}/model/${encodeURIComponent(defaultConfig.defaultModel)}/invoke`
|
||||
);
|
||||
expect(body).to.eql({
|
||||
status: 'ok',
|
||||
|
@ -584,7 +584,7 @@ export default function bedrockTest({ getService }: FtrProviderContext) {
|
|||
|
||||
expect(simulator.requestData).to.eql(DEFAULT_BODY);
|
||||
expect(simulator.requestUrl).to.eql(
|
||||
`${apiUrl}/model/${defaultConfig.defaultModel}/invoke`
|
||||
`${apiUrl}/model/${encodeURIComponent(defaultConfig.defaultModel)}/invoke`
|
||||
);
|
||||
expect(body).to.eql({
|
||||
status: 'ok',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue