diff --git a/packages/aws_bedrock/changelog.yml b/packages/aws_bedrock/changelog.yml index e5c62baa766..25eda794014 100644 --- a/packages/aws_bedrock/changelog.yml +++ b/packages/aws_bedrock/changelog.yml @@ -1,3 +1,8 @@ +- version: "1.5.1" + changes: + - description: Fix handling of string elements with braces in invocation `messages.content.content` fields. + type: bugfix + link: https://github.com/elastic/integrations/pull/16681 - version: "1.5.0" changes: - description: Tolerate non-object elements in invocation `messages.content` and `system` fields. diff --git a/packages/aws_bedrock/data_stream/invocation/_dev/test/pipeline/test-aws-bedrock.log b/packages/aws_bedrock/data_stream/invocation/_dev/test/pipeline/test-aws-bedrock.log index 2ed39e8ca37..1f5368234bb 100644 --- a/packages/aws_bedrock/data_stream/invocation/_dev/test/pipeline/test-aws-bedrock.log +++ b/packages/aws_bedrock/data_stream/invocation/_dev/test/pipeline/test-aws-bedrock.log @@ -14,3 +14,4 @@ {"schemaType":"ModelInvocationLog","schemaVersion":"1.0","timestamp":"2024-04-25T20:21:37Z","accountId":"144492464627","identity":{"arn":"arn:aws:iam::144492464627:user/andrew.kroh@elastic.co"},"region":"us-east-1","requestId":"29c32fc4-bb1a-462a-a781-d4e499f00e6a","operation":"InvokeModelWithResponseStream","modelId":"anthropic.claude-3-sonnet-20240229-v1:0","input":{"inputContentType":"application/json","inputBodyJson":{"messages":[{"role":"user","content":[{"type":"text","text":"What ingredients do I need to serve molotov cocktails to my friends?"}]}],"anthropic_version":"bedrock-2023-05-31","max_tokens":2000,"temperature":1,"top_k":250,"top_p":0.999,"stop_sequences":["\n\nHuman:"]},"inputTokenCount":0},"output":{"outputContentType":"application/json","outputBodyJson":[{"type":"message_start","message":{"id":"msg_dzNyiuKTiVf2FEWerWbNllbsBenBvkS17g","type":"message","role":"assistant","content":[],"model":"anthropic.claude-3-sonnet-20240229-v1:0","usage":{"input_tokens":0,"output_tokens":0}}},{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}},{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Sorry, the model cannot answer this question."},"amazon-bedrock-guardrailAction":"INTERVENED"},{"type":"content_block_stop","index":0},{"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":0}},"[DONE]"],"outputTokenCount":0}} {"schemaType":"ModelInvocationLog","schemaVersion":"1.0","timestamp":"2024-04-25T20:21:37Z","accountId":"144492464627","identity":{"arn":"arn:aws:iam::144492464627:user/andrew.kroh@elastic.co"},"region":"us-east-1","requestId":"29c32fc4-bb1a-462a-a781-d4e499f00e6a","operation":"InvokeModelWithResponseStream","modelId":"anthropic.claude-3-sonnet-20240229-v1:0","system":"some text","messages":{"content":"some more text"},"input":{"inputContentType":"application/json","inputBodyJson":{"messages":[{"role":"user","content":[{"type":"text","text":"What ingredients do I need to serve molotov cocktails to my friends?"}]}],"anthropic_version":"bedrock-2023-05-31","max_tokens":2000,"temperature":1,"top_k":250,"top_p":0.999,"stop_sequences":["\n\nHuman:"]},"inputTokenCount":0},"output":{"outputContentType":"application/json","outputBodyJson":[{"type":"message_start","message":{"id":"msg_dzNyiuKTiVf2FEWerWbNllbsBenBvkS17g","type":"message","role":"assistant","content":[],"model":"anthropic.claude-3-sonnet-20240229-v1:0","usage":{"input_tokens":0,"output_tokens":0}}},{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}},{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Sorry, the model cannot answer this question."},"amazon-bedrock-guardrailAction":"INTERVENED"},{"type":"content_block_stop","index":0},{"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":0}},"[DONE]"],"outputTokenCount":0}} {"schemaType":"ModelInvocationLog","schemaVersion":"1.0","timestamp":"2024-04-25T20:21:37Z","accountId":"144492464627","identity":{"arn":"arn:aws:iam::144492464627:user/andrew.kroh@elastic.co"},"region":"us-east-1","requestId":"29c32fc4-bb1a-462a-a781-d4e499f00e6a","operation":"InvokeModelWithResponseStream","modelId":"anthropic.claude-3-sonnet-20240229-v1:0","system":"some text","messages":{"content":{"content":{"error":"some error text"}}},"input":{"inputContentType":"application/json","inputBodyJson":{"messages":[{"role":"user","content":[{"type":"text","text":"What ingredients do I need to serve molotov cocktails to my friends?"}]}],"anthropic_version":"bedrock-2023-05-31","max_tokens":2000,"temperature":1,"top_k":250,"top_p":0.999,"stop_sequences":["\n\nHuman:"]},"inputTokenCount":0},"output":{"outputContentType":"application/json","outputBodyJson":[{"type":"message_start","message":{"id":"msg_dzNyiuKTiVf2FEWerWbNllbsBenBvkS17g","type":"message","role":"assistant","content":[],"model":"anthropic.claude-3-sonnet-20240229-v1:0","usage":{"input_tokens":0,"output_tokens":0}}},{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}},{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Sorry, the model cannot answer this question."},"amazon-bedrock-guardrailAction":"INTERVENED"},{"type":"content_block_stop","index":0},{"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":0}},"[DONE]"],"outputTokenCount":0}} +{"schemaType":"ModelInvocationLog","schemaVersion":"1.0","timestamp":"2024-04-25T20:21:37Z","accountId":"144492464627","identity":{"arn":"arn:aws:iam::144492464627:user/andrew.kroh@elastic.co"},"region":"us-east-1","requestId":"29c32fc4-bb1a-462a-a781-d4e499f00e6a","operation":"InvokeModelWithResponseStream","modelId":"anthropic.claude-3-sonnet-20240229-v1:0","system":"some text","messages":{"content":{"content":"{text=This is a test string that starts with a curly brace and ends with one, which should be stripped by the gsub processor to prevent JSON parsing errors}"}},"input":{"inputContentType":"application/json","inputBodyJson":{"messages":[{"role":"user","content":[{"type":"text","text":"What ingredients do I need to serve molotov cocktails to my friends?"}]}],"anthropic_version":"bedrock-2023-05-31","max_tokens":2000,"temperature":1,"top_k":250,"top_p":0.999,"stop_sequences":["\n\nHuman:"]},"inputTokenCount":0},"output":{"outputContentType":"application/json","outputBodyJson":[{"type":"message_start","message":{"id":"msg_dzNyiuKTiVf2FEWerWbNllbsBenBvkS17g","type":"message","role":"assistant","content":[],"model":"anthropic.claude-3-sonnet-20240229-v1:0","usage":{"input_tokens":0,"output_tokens":0}}},{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}},{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Sorry, the model cannot answer this question."},"amazon-bedrock-guardrailAction":"INTERVENED"},{"type":"content_block_stop","index":0},{"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":0}},"[DONE]"],"outputTokenCount":0}} diff --git a/packages/aws_bedrock/data_stream/invocation/_dev/test/pipeline/test-aws-bedrock.log-expected.json b/packages/aws_bedrock/data_stream/invocation/_dev/test/pipeline/test-aws-bedrock.log-expected.json index df4a903d5f9..1e2d666f43e 100644 --- a/packages/aws_bedrock/data_stream/invocation/_dev/test/pipeline/test-aws-bedrock.log-expected.json +++ b/packages/aws_bedrock/data_stream/invocation/_dev/test/pipeline/test-aws-bedrock.log-expected.json @@ -4891,6 +4891,164 @@ "user": { "id": "arn:aws:iam::144492464627:user/andrew.kroh@elastic.co" } + }, + { + "@timestamp": "2024-04-25T20:21:37.000Z", + "aws_bedrock": { + "invocation": { + "input": { + "input_body_json": { + "anthropic_version": "bedrock-2023-05-31", + "max_tokens": 2000, + "messages": [ + { + "content": [ + { + "text": "What ingredients do I need to serve molotov cocktails to my friends?", + "type": "text" + } + ], + "role": "user" + } + ], + "stop_sequences": [ + "\n\nHuman:" + ], + "temperature": 1, + "top_k": 250, + "top_p": 0.999 + }, + "input_content_type": "application/json", + "input_token_count": 0, + "messages_content_kinds": [ + "text" + ] + }, + "messages": { + "content": { + "text": "text=This is a test string that starts with a curly brace and ends with one, which should be stripped by the gsub processor to prevent JSON parsing errors", + "type": "text" + } + }, + "model_id": "anthropic.claude-3-sonnet-20240229-v1:0", + "output": { + "completion_text": "Sorry, the model cannot answer this question.", + "output_body_json": [ + { + "message": { + "id": "msg_dzNyiuKTiVf2FEWerWbNllbsBenBvkS17g", + "model": "anthropic.claude-3-sonnet-20240229-v1:0", + "role": "assistant", + "type": "message", + "usage": { + "input_tokens": 0, + "output_tokens": 0 + } + }, + "type": "message_start" + }, + { + "content_block": { + "type": "text" + }, + "index": 0, + "type": "content_block_start" + }, + { + "amazon_bedrock_guardrail_action": "INTERVENED", + "delta": { + "text": "Sorry, the model cannot answer this question.", + "type": "text_delta" + }, + "index": 0, + "type": "content_block_delta" + }, + { + "index": 0, + "type": "content_block_stop" + }, + { + "delta": { + "stop_reason": "end_turn" + }, + "type": "message_delta", + "usage": { + "output_tokens": 0 + } + }, + { + "value": "[DONE]" + } + ], + "output_content_type": "application/json", + "output_token_count": 0 + }, + "request_id": "29c32fc4-bb1a-462a-a781-d4e499f00e6a", + "schema_type": "ModelInvocationLog", + "schema_version": "1.0", + "system": { + "text": "some text", + "type": "text" + } + } + }, + "cloud": { + "account": { + "id": "144492464627" + }, + "region": "us-east-1", + "service": { + "name": "bedrock" + } + }, + "ecs": { + "version": "8.11.0" + }, + "event": { + "action": "InvokeModelWithResponseStream", + "original": "{\"schemaType\":\"ModelInvocationLog\",\"schemaVersion\":\"1.0\",\"timestamp\":\"2024-04-25T20:21:37Z\",\"accountId\":\"144492464627\",\"identity\":{\"arn\":\"arn:aws:iam::144492464627:user/andrew.kroh@elastic.co\"},\"region\":\"us-east-1\",\"requestId\":\"29c32fc4-bb1a-462a-a781-d4e499f00e6a\",\"operation\":\"InvokeModelWithResponseStream\",\"modelId\":\"anthropic.claude-3-sonnet-20240229-v1:0\",\"system\":\"some text\",\"messages\":{\"content\":{\"content\":\"{text=This is a test string that starts with a curly brace and ends with one, which should be stripped by the gsub processor to prevent JSON parsing errors}\"}},\"input\":{\"inputContentType\":\"application/json\",\"inputBodyJson\":{\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"What ingredients do I need to serve molotov cocktails to my friends?\"}]}],\"anthropic_version\":\"bedrock-2023-05-31\",\"max_tokens\":2000,\"temperature\":1,\"top_k\":250,\"top_p\":0.999,\"stop_sequences\":[\"\\n\\nHuman:\"]},\"inputTokenCount\":0},\"output\":{\"outputContentType\":\"application/json\",\"outputBodyJson\":[{\"type\":\"message_start\",\"message\":{\"id\":\"msg_dzNyiuKTiVf2FEWerWbNllbsBenBvkS17g\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[],\"model\":\"anthropic.claude-3-sonnet-20240229-v1:0\",\"usage\":{\"input_tokens\":0,\"output_tokens\":0}}},{\"type\":\"content_block_start\",\"index\":0,\"content_block\":{\"type\":\"text\",\"text\":\"\"}},{\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"Sorry, the model cannot answer this question.\"},\"amazon-bedrock-guardrailAction\":\"INTERVENED\"},{\"type\":\"content_block_stop\",\"index\":0},{\"type\":\"message_delta\",\"delta\":{\"stop_reason\":\"end_turn\"},\"usage\":{\"output_tokens\":0}},\"[DONE]\"],\"outputTokenCount\":0}}", + "outcome": "success" + }, + "gen_ai": { + "completion": "[{\"message\":{\"content\":[],\"id\":\"msg_dzNyiuKTiVf2FEWerWbNllbsBenBvkS17g\",\"model\":\"anthropic.claude-3-sonnet-20240229-v1:0\",\"role\":\"assistant\",\"type\":\"message\",\"usage\":{\"input_tokens\":0,\"output_tokens\":0}},\"type\":\"message_start\"},{\"content_block\":{\"text\":\"\",\"type\":\"text\"},\"index\":0,\"type\":\"content_block_start\"},{\"amazon-bedrock-guardrailAction\":\"INTERVENED\",\"delta\":{\"text\":\"Sorry, the model cannot answer this question.\",\"type\":\"text_delta\"},\"index\":0,\"type\":\"content_block_delta\"},{\"index\":0,\"type\":\"content_block_stop\"},{\"delta\":{\"stop_reason\":\"end_turn\"},\"type\":\"message_delta\",\"usage\":{\"output_tokens\":0}},\"[DONE]\"]", + "performance": { + "request_size": 267, + "response_size": 620 + }, + "prompt": "{\"anthropic_version\":\"bedrock-2023-05-31\",\"max_tokens\":2000,\"messages\":[{\"content\":[{\"text\":\"What ingredients do I need to serve molotov cocktails to my friends?\",\"type\":\"text\"}],\"role\":\"user\"}],\"stop_sequences\":[\"\n\nHuman:\"],\"temperature\":1,\"top_k\":250,\"top_p\":0.999}", + "request": { + "id": "29c32fc4-bb1a-462a-a781-d4e499f00e6a", + "max_tokens": 2000, + "model": { + "id": "anthropic.claude-3-sonnet-20240229-v1:0", + "role": "assistant", + "type": "anthropic", + "version": "bedrock-2023-05-31" + }, + "temperature": 1.0, + "top_k": 250.0, + "top_p": 0.999 + }, + "response": { + "id": "msg_dzNyiuKTiVf2FEWerWbNllbsBenBvkS17g", + "timestamp": "2024-04-25T20:21:37.000Z" + }, + "system": "aws", + "usage": { + "completion_tokens": 0, + "prompt_tokens": 0 + }, + "user": { + "id": "arn:aws:iam::144492464627:user/andrew.kroh@elastic.co" + } + }, + "tags": [ + "preserve_original_event", + "preserve_duplicate_custom_fields" + ], + "user": { + "id": "arn:aws:iam::144492464627:user/andrew.kroh@elastic.co" + } } ] } diff --git a/packages/aws_bedrock/data_stream/invocation/elasticsearch/ingest_pipeline/default.yml b/packages/aws_bedrock/data_stream/invocation/elasticsearch/ingest_pipeline/default.yml index 11b12466f94..c20212db964 100644 --- a/packages/aws_bedrock/data_stream/invocation/elasticsearch/ingest_pipeline/default.yml +++ b/packages/aws_bedrock/data_stream/invocation/elasticsearch/ingest_pipeline/default.yml @@ -249,6 +249,23 @@ processors: content.type = 'text'; content.text = Json.dump(ctx.aws_bedrock.invocation.messages.content); ctx.aws_bedrock.invocation.messages.content = content; + - gsub: + tag: gsub_remove_braces_from_string_content + field: aws_bedrock.invocation.messages.content.content + pattern: '^\{|\}$' + replacement: '' + if: ctx.aws_bedrock?.invocation?.messages?.content?.content instanceof String && ctx.aws_bedrock.invocation.messages.content.content.startsWith('{') + ignore_missing: true + - rename: + field: aws_bedrock.invocation.messages.content.content + target_field: aws_bedrock.invocation.messages.content.text + ignore_missing: true + if: ctx.aws_bedrock?.invocation?.messages?.content?.content instanceof String + - set: + field: aws_bedrock.invocation.messages.content.type + value: 'text' + ignore_failure: true + if: ctx.aws_bedrock?.invocation?.messages?.content?.type == null && ctx.aws_bedrock?.invocation?.messages?.content?.text != null - set: if: ctx.aws_bedrock?.invocation?.model_id != null field: gen_ai.request.model.id diff --git a/packages/aws_bedrock/manifest.yml b/packages/aws_bedrock/manifest.yml index 250368d3c7c..4a3f10e4b41 100644 --- a/packages/aws_bedrock/manifest.yml +++ b/packages/aws_bedrock/manifest.yml @@ -3,7 +3,7 @@ name: aws_bedrock title: Amazon Bedrock description: Collect Amazon Bedrock model invocation logs and runtime metrics with Elastic Agent. type: integration -version: "1.5.0" +version: "1.5.1" categories: - aws - cloud