Fix InvokeAIRaw bedrock subaction's schema (#192015)

## Summary

Fix regression on `InvokeAIRaw` bedrock subaction introduced by
https://github.com/elastic/kibana/pull/191434
This commit is contained in:
Pierre Gayvallet 2024-09-03 22:29:56 +02:00 committed by GitHub
parent 448c9e1328
commit 84c6815a11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 56 deletions

View file

@ -1083,51 +1083,14 @@ Object {
"keys": Object {
"content": Object {
"flags": Object {
"default": [Function],
"error": [Function],
"presence": "optional",
},
"metas": Array [
Object {
"x-oas-optional": true,
"x-oas-any-type": true,
},
],
"rules": Array [
Object {
"args": Object {
"method": [Function],
},
"name": "custom",
},
],
"type": "string",
},
"rawContent": Object {
"flags": Object {
"default": [Function],
"error": [Function],
"presence": "optional",
},
"items": Array [
Object {
"flags": Object {
"error": [Function],
"presence": "optional",
},
"metas": Array [
Object {
"x-oas-any-type": true,
},
],
"type": "any",
},
],
"metas": Array [
Object {
"x-oas-optional": true,
},
],
"type": "array",
"type": "any",
},
"role": Object {
"flags": Object {
@ -1144,14 +1107,6 @@ Object {
"type": "string",
},
},
"rules": Array [
Object {
"args": Object {
"method": [Function],
},
"name": "custom",
},
],
"type": "object",
},
],

View file

@ -78,7 +78,12 @@ export const InvokeAIActionResponseSchema = schema.object({
});
export const InvokeAIRawActionParamsSchema = schema.object({
messages: schema.arrayOf(BedrockMessageSchema),
messages: schema.arrayOf(
schema.object({
role: schema.string(),
content: schema.any(),
})
),
model: schema.maybe(schema.string()),
temperature: schema.maybe(schema.number()),
stopSequences: schema.maybe(schema.arrayOf(schema.string())),

View file

@ -35,5 +35,5 @@ export type RunActionResponse = TypeOf<typeof RunActionResponseSchema>;
export type StreamingResponse = TypeOf<typeof StreamingResponseSchema>;
export type DashboardActionParams = TypeOf<typeof DashboardActionParamsSchema>;
export type DashboardActionResponse = TypeOf<typeof DashboardActionResponseSchema>;
export type BedRockMessage = TypeOf<typeof BedrockMessageSchema>;
export type BedrockMessage = TypeOf<typeof BedrockMessageSchema>;
export type BedrockToolChoice = TypeOf<typeof BedrockToolChoiceSchema>;

View file

@ -32,7 +32,7 @@ import type {
InvokeAIRawActionParams,
InvokeAIRawActionResponse,
RunApiLatestResponse,
BedRockMessage,
BedrockMessage,
BedrockToolChoice,
} from '../../../common/bedrock/types';
import {
@ -422,7 +422,7 @@ const formatBedrockBody = ({
tools,
toolChoice,
}: {
messages: BedRockMessage[];
messages: BedrockMessage[];
stopSequences?: string[];
temperature?: number;
maxTokens?: number;
@ -440,9 +440,9 @@ const formatBedrockBody = ({
tool_choice: toolChoice,
});
interface FormattedBedRockMessage {
interface FormattedBedrockMessage {
role: string;
content: string | BedRockMessage['rawContent'];
content: string | BedrockMessage['rawContent'];
}
/**
@ -452,15 +452,15 @@ interface FormattedBedRockMessage {
* @param messages
*/
const ensureMessageFormat = (
messages: BedRockMessage[],
messages: BedrockMessage[],
systemPrompt?: string
): {
messages: FormattedBedRockMessage[];
messages: FormattedBedrockMessage[];
system?: string;
} => {
let system = systemPrompt ? systemPrompt : '';
const newMessages = messages.reduce<FormattedBedRockMessage[]>((acc, m) => {
const newMessages = messages.reduce<FormattedBedrockMessage[]>((acc, m) => {
if (m.role === 'system') {
system = `${system.length ? `${system}\n` : ''}${m.content}`;
return acc;