mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
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:
parent
448c9e1328
commit
84c6815a11
4 changed files with 16 additions and 56 deletions
|
@ -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",
|
||||
},
|
||||
],
|
||||
|
|
|
@ -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())),
|
||||
|
|
|
@ -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>;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue