From 292b1ff5d6d66137ea8069ebb34cc638c99bd468 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 15 May 2024 15:56:12 -0700 Subject: [PATCH] Add support for mistral bedrock model --- newrelic/hooks/external_botocore.py | 38 +++ .../_mock_external_bedrock_server.py | 130 ++++++++ .../_test_bedrock_chat_completion.py | 277 ++++++++++++++++++ tests/external_botocore/conftest.py | 2 +- .../test_bedrock_chat_completion.py | 1 + 5 files changed, 447 insertions(+), 1 deletion(-) diff --git a/newrelic/hooks/external_botocore.py b/newrelic/hooks/external_botocore.py index c6f17bfd86..ad13a2809a 100644 --- a/newrelic/hooks/external_botocore.py +++ b/newrelic/hooks/external_botocore.py @@ -189,6 +189,14 @@ def extract_bedrock_titan_text_model_request(request_body, bedrock_attrs): return bedrock_attrs +def extract_bedrock_mistral_text_model_request(request_body, bedrock_attrs): + request_body = json.loads(request_body) + bedrock_attrs["input_message_list"] = [{"role": "user", "content": request_body.get("prompt")}] + bedrock_attrs["request.max_tokens"] = request_body.get("max_tokens") + bedrock_attrs["request.temperature"] = request_body.get("temperature") + return bedrock_attrs + + def extract_bedrock_titan_text_model_response(response_body, bedrock_attrs): if response_body: response_body = json.loads(response_body) @@ -203,6 +211,18 @@ def extract_bedrock_titan_text_model_response(response_body, bedrock_attrs): return bedrock_attrs +def extract_bedrock_mistral_text_model_response(response_body, bedrock_attrs): + if response_body: + response_body = json.loads(response_body) + outputs = response_body.get("outputs") + if outputs: + bedrock_attrs["response.choices.finish_reason"] = outputs[0]["stop_reason"] + bedrock_attrs["output_message_list"] = [ + {"role": "assistant", "content": result["text"]} for result in outputs + ] + return bedrock_attrs + + def extract_bedrock_titan_text_model_streaming_response(response_body, bedrock_attrs): if response_body: if "outputText" in response_body: @@ -214,6 +234,18 @@ def extract_bedrock_titan_text_model_streaming_response(response_body, bedrock_a return bedrock_attrs +def extract_bedrock_mistral_text_model_streaming_response(response_body, bedrock_attrs): + if response_body: + outputs = response_body.get("outputs") + if outputs: + bedrock_attrs["output_message_list"] = bedrock_attrs.get( + "output_message_list", [{"role": "assistant", "content": ""}] + ) + bedrock_attrs["output_message_list"][0]["content"] += outputs[0].get("text", "") + bedrock_attrs["response.choices.finish_reason"] = outputs[0].get("stop_reason", None) + return bedrock_attrs + + def extract_bedrock_titan_embedding_model_request(request_body, bedrock_attrs): request_body = json.loads(request_body) @@ -407,6 +439,12 @@ def extract_bedrock_cohere_model_streaming_response(response_body, bedrock_attrs extract_bedrock_llama_model_response, extract_bedrock_llama_model_streaming_response, ), + ( + "mistral", + extract_bedrock_mistral_text_model_request, + extract_bedrock_mistral_text_model_response, + extract_bedrock_mistral_text_model_streaming_response, + ), ] diff --git a/tests/external_botocore/_mock_external_bedrock_server.py b/tests/external_botocore/_mock_external_bedrock_server.py index 9f28a6f11f..e140d80c8e 100644 --- a/tests/external_botocore/_mock_external_bedrock_server.py +++ b/tests/external_botocore/_mock_external_bedrock_server.py @@ -30,6 +30,115 @@ # 3) This app runs on a separate thread meaning it won't block the test app. STREAMED_RESPONSES = { + "mistral.mistral-7b-instruct-v0%3A2::[INST] What is 212 degrees Fahrenheit converted to Celsius? [/INST]": [ + { + "Content-Type": "application/vnd.amazon.eventstream", + "x-amzn-RequestId": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + }, + 200, + [ + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494652764969776963335276634639795a57467a623234694f6d3531624778395858303d227d30693c02", + "000000af0000004b765b4f360b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949474e76626e5a6c636e51694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227dd3bacdba", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494745694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d7e1af014", + "000000b30000004bd34b35b50b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694948526c6258426c636d463064584a6c4969776963335276634639795a57467a623234694f6d3531624778395858303d227d1ac96f27", + "000000ab0000004b83dbe9f60b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949475a79623230694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d79a7bac3", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494559694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d0d3a538e", + "000000ab0000004b83dbe9f60b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69595768795a5734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d800cf6a1", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f696147567064434973496e4e3062334266636d566863323975496a70756457787366563139227d9261e38d", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494852764969776963335276634639795a57467a623234694f6d3531624778395858303d227d580defbc", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949454d694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227dd42b6945", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f695a57787a4969776963335276634639795a57467a623234694f6d3531624778395858303d227df0e3aab1", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f696158567a4969776963335276634639795a57467a623234694f6d3531624778395858303d227d47cb033c", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694c434973496e4e3062334266636d566863323975496a70756457787366563139227db86ac617", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949486c7664534973496e4e3062334266636d566863323975496a70756457787366563139227d111efa00", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949474e6862694973496e4e3062334266636d566863323975496a70756457787366563139227d33a08812", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694948567a5a534973496e4e3062334266636d566863323975496a70756457787366563139227d60f7f5e7", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694948526f5a534973496e4e3062334266636d566863323975496a70756457787366563139227d5059ad51", + "000000af0000004b765b4f360b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949475a766247787664326c755a794973496e4e3062334266636d566863323975496a70756457787366563139227da7af16c9", + "000000af0000004b765b4f360b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949475a76636d3131624745694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d76a80396", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694f694973496e4e3062334266636d566863323975496a70756457787366563139227dbc0b9457", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949454d694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227dd42b6945", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f695a57787a4969776963335276634639795a57467a623234694f6d3531624778395858303d227df0e3aab1", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f696158567a4969776963335276634639795a57467a623234694f6d3531624778395858303d227d47cb033c", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494430694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d420e6621", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494367694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227df82acb39", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6952694973496e4e3062334266636d566863323975496a70756457787366563139227dd05517eb", + "000000ab0000004b83dbe9f60b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69595768795a5734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d800cf6a1", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f696147567064434973496e4e3062334266636d566863323975496a70756457787366563139227d9261e38d", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494330694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d763c0ffe", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949434973496e4e3062334266636d566863323975496a70756457787366563139227d0ee1d3f9", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d794973496e4e3062334266636d566863323975496a70756457787366563139227d2cc43589", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694b534973496e4e3062334266636d566863323975496a70756457787366563139227d9e2e7227", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494d4f584969776963335276634639795a57467a623234694f6d3531624778395858303d227d1309a28c", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949434973496e4e3062334266636d566863323975496a70756457787366563139227d0ee1d3f9", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694e534973496e4e3062334266636d566863323975496a70756457787366563139227d28a567c9", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694c794973496e4e3062334266636d566863323975496a70756457787366563139227d084664bf", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694f534973496e4e3062334266636d566863323975496a70756457787366563139227d0c2736ff", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694c694973496e4e3062334266636d566863323975496a70756457787366563139227dd18d670d", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69584734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d18050f59", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69584734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d18050f59", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69553238694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d2acbcc0d", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694c434973496e4e3062334266636d566863323975496a70756457787366563139227db86ac617", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494852764969776963335276634639795a57467a623234694f6d3531624778395858303d227d580defbc", + "000000af0000004b765b4f360b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949474e76626e5a6c636e51694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227dd3bacdba", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949434973496e4e3062334266636d566863323975496a70756457787366563139227d0ee1d3f9", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d534973496e4e3062334266636d566863323975496a70756457787366563139227d45239493", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000000af0000004b765b4f360b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694947526c5a334a6c5a584d694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d3ac15b52", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494559694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d0d3a538e", + "000000ab0000004b83dbe9f60b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69595768795a5734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d800cf6a1", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f696147567064434973496e4e3062334266636d566863323975496a70756457787366563139227d9261e38d", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494852764969776963335276634639795a57467a623234694f6d3531624778395858303d227d580defbc", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949454d694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227dd42b6945", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f695a57787a4969776963335276634639795a57467a623234694f6d3531624778395858303d227df0e3aab1", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f696158567a4969776963335276634639795a57467a623234694f6d3531624778395858303d227d47cb033c", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694c434973496e4e3062334266636d566863323975496a70756457787366563139227db86ac617", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494752764969776963335276634639795a57467a623234694f6d3531624778395858303d227db0992b1d", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694948526f5a534973496e4e3062334266636d566863323975496a70756457787366563139227d5059ad51", + "000000af0000004b765b4f360b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949475a766247787664326c755a794973496e4e3062334266636d566863323975496a70756457787366563139227da7af16c9", + "000000b30000004bd34b35b50b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949474e6862474e3162474630615739754969776963335276634639795a57467a623234694f6d3531624778395858303d227dfaa5d044", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694f694973496e4e3062334266636d566863323975496a70756457787366563139227dbc0b9457", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69584734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d18050f59", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69584734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d18050f59", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6951794973496e4e3062334266636d566863323975496a70756457787366563139227d6418e703", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f695a57787a4969776963335276634639795a57467a623234694f6d3531624778395858303d227df0e3aab1", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f696158567a4969776963335276634639795a57467a623234694f6d3531624778395858303d227d47cb033c", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494430694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d420e6621", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494367694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227df82acb39", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d534973496e4e3062334266636d566863323975496a70756457787366563139227d45239493", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69777241694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d27bae54a", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6952694973496e4e3062334266636d566863323975496a70756457787366563139227dd05517eb", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494330694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d763c0ffe", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949434973496e4e3062334266636d566863323975496a70756457787366563139227d0ee1d3f9", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d794973496e4e3062334266636d566863323975496a70756457787366563139227d2cc43589", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694b534973496e4e3062334266636d566863323975496a70756457787366563139227d9e2e7227", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494d4f584969776963335276634639795a57467a623234694f6d3531624778395858303d227d1309a28c", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949434973496e4e3062334266636d566863323975496a70756457787366563139227d0ee1d3f9", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694e534973496e4e3062334266636d566863323975496a70756457787366563139227d28a567c9", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694c794973496e4e3062334266636d566863323975496a70756457787366563139227d084664bf", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694f534973496e4e3062334266636d566863323975496a70756457787366563139227d0c2736ff", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69584734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d18050f59", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69584734694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d18050f59", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6951794973496e4e3062334266636d566863323975496a70756457787366563139227d6418e703", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f695a57787a4969776963335276634639795a57467a623234694f6d3531624778395858303d227df0e3aab1", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f696158567a4969776963335276634639795a57467a623234694f6d3531624778395858303d227d47cb033c", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494430694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d420e6621", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494367694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227df82acb39", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d534973496e4e3062334266636d566863323975496a70756457787366563139227d45239493", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000000a70000004b462b04f70b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f69494330694c434a7a6447397758334a6c59584e7662694936626e56736248316466513d3d227d763c0ffe", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f6949434973496e4e3062334266636d566863323975496a70756457787366563139227d0ee1d3f9", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d794973496e4e3062334266636d566863323975496a70756457787366563139227d2cc43589", + "000000a30000004bb3aba2370b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694d694973496e4e3062334266636d566863323975496a70756457787366563139227df50f363b", + "000001570000004bc543870f0b3a6576656e742d747970650700056368756e6b0d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226279746573223a2265794a76645852776458527a496a706265794a305a586830496a6f694b534973496e4e3062334266636d566863323975496a6f69624756755a33526f496e31644c434a686257463662323474596d566b636d396a61793170626e5a76593246306157397554575630636d6c6a6379493665794a70626e4231644652766132567551323931626e51694f6a49314c434a7664585277645852556232746c626b4e7664573530496a6f784d444173496d6c75646d396a595852706232354d5958526c626d4e35496a6f784e4451774c434a6d61584a7a64454a356447564d5958526c626d4e35496a6f7a4d6a643966513d3d227d9b82aeca", + ], + ], "amazon.titan-text-express-v1::User: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.": [ { "Content-Type": "application/vnd.amazon.eventstream", @@ -471,6 +580,18 @@ } RESPONSES = { + "mistral.mistral-7b-instruct-v0%3A2::[INST] What is 212 degrees Fahrenheit converted to Celsius? [/INST]": [ + {"Content-Type": "application/json", "x-amzn-RequestId": "48c7ee13-7790-461f-959f-04b0a4cf91c8"}, + 200, + { + "outputs": [ + { + "text": " To convert a temperature from Fahrenheit to Celsius, you can use the following formula:\n\nCelsius = (Fahrenheit - 32) \u00d7 5/9\n\nSo, to convert 212 degrees Fahrenheit to Celsius:\n\nCelsius = (212 - 32) \u00d7 5/9\nCelsius = 180.56 \u00d7 5/9\nCelsius", + "stop_reason": "length", + } + ] + }, + ], "amazon.titan-text-express-v1::User: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.": [ {"Content-Type": "application/json", "x-amzn-RequestId": "884db5c9-18ab-4f27-8892-33656176a2e6"}, 200, @@ -4864,6 +4985,15 @@ 400, {"message": "The provided model identifier is invalid."}, ], + "mistral.mistral-7b-instruct-v0%3A2::[INST] Invalid Token [/INST]": [ + { + "Content-Type": "application/json", + "x-amzn-RequestId": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "x-amzn-ErrorType": "UnrecognizedClientException:http://internal.amazon.com/coral/com.amazon.coral.service/", + }, + 403, + {"message": "The security token included in the request is invalid."}, + ], "ai21.j2-mid-v1::Invalid Token": [ { "Content-Type": "application/json", diff --git a/tests/external_botocore/_test_bedrock_chat_completion.py b/tests/external_botocore/_test_bedrock_chat_completion.py index 2c3e5ce733..f7c536c4e7 100644 --- a/tests/external_botocore/_test_bedrock_chat_completion.py +++ b/tests/external_botocore/_test_bedrock_chat_completion.py @@ -18,9 +18,69 @@ "anthropic.claude-instant-v1": '{"prompt": "Human: %s Assistant:", "temperature": %f, "max_tokens_to_sample": %d}', "cohere.command-text-v14": '{"prompt": "%s", "temperature": %f, "max_tokens": %d}', "meta.llama2-13b-chat-v1": '{"prompt": "%s", "temperature": %f, "max_gen_len": %d}', + "mistral.mistral-7b-instruct-v0:2": '{"prompt": "[INST] %s [/INST]", "temperature": %f, "max_tokens": %d}', } chat_completion_expected_events = { + "mistral.mistral-7b-instruct-v0:2": [ + ( + {"type": "LlmChatCompletionSummary"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "span_id": None, + "trace_id": "trace-id", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "duration": None, # Response time varies each test run + "request.model": "mistral.mistral-7b-instruct-v0:2", + "response.model": "mistral.mistral-7b-instruct-v0:2", + "request.temperature": 0.7, + "request.max_tokens": 100, + "response.choices.finish_reason": "length", + "vendor": "bedrock", + "ingest_source": "Python", + "response.number_of_messages": 2, + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": "[INST] What is 212 degrees Fahrenheit converted to Celsius? [/INST]", + "role": "user", + "completion_id": None, + "sequence": 0, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": " To convert a temperature from Fahrenheit to Celsius, you can use the following formula:\n\nCelsius = (Fahrenheit - 32) \u00d7 5/9\n\nSo, to convert 212 degrees Fahrenheit to Celsius:\n\nCelsius = (212 - 32) \u00d7 5/9\nCelsius = 180.56 \u00d7 5/9\nCelsius", + "role": "assistant", + "completion_id": None, + "sequence": 1, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + "is_response": True, + }, + ), + ], "amazon.titan-text-express-v1": [ ( {"type": "LlmChatCompletionSummary"}, @@ -320,6 +380,65 @@ ], } chat_completion_langchain_expected_streaming_events = { + "mistral.mistral-7b-instruct-v0:2": [ + ( + {"type": "LlmChatCompletionSummary"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "span_id": None, + "trace_id": "trace-id", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "duration": None, # Response time varies each test run + "request.model": "mistral.mistral-7b-instruct-v0:2", + "response.model": "mistral.mistral-7b-instruct-v0:2", + "request.temperature": 0.7, + "request.max_tokens": 100, + "response.choices.finish_reason": "length", + "vendor": "bedrock", + "ingest_source": "Python", + "response.number_of_messages": 2, + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": "[INST] What is 212 degrees Fahrenheit converted to Celsius? [/INST]", + "role": "user", + "completion_id": None, + "sequence": 0, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": " To convert a temperature from Fahrenheit to Celsius, you can use the following formula: Celsius = (Fahrenheit - 32) × 5/9.\n\nSo, to convert 212 degrees Fahrenheit to Celsius, do the following calculation:\n\nCelsius = (212°F - 32) × 5/9\n\nCelsius = (212 - 32)", + "role": "assistant", + "completion_id": None, + "sequence": 1, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + "is_response": True, + }, + ), + ], "amazon.titan-text-express-v1": [ ( {"type": "LlmChatCompletionSummary"}, @@ -492,6 +611,65 @@ ], } chat_completion_langchain_expected_events = { + "mistral.mistral-7b-instruct-v0:2": [ + ( + {"type": "LlmChatCompletionSummary"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "span_id": None, + "trace_id": "trace-id", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "duration": None, # Response time varies each test run + "request.model": "mistral.mistral-7b-instruct-v0:2", + "response.model": "mistral.mistral-7b-instruct-v0:2", + "request.temperature": 0.7, + "request.max_tokens": 100, + "response.choices.finish_reason": "length", + "vendor": "bedrock", + "ingest_source": "Python", + "response.number_of_messages": 2, + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": "[INST] What is 212 degrees Fahrenheit converted to Celsius? [/INST]", + "role": "user", + "completion_id": None, + "sequence": 0, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": " To convert a temperature from Fahrenheit to Celsius, you can use the following formula:\n\nCelsius = (Fahrenheit - 32) \u00d7 5/9\n\nSo, to convert 212 degrees Fahrenheit to Celsius:\n\nCelsius = (212 - 32) \u00d7 5/9\nCelsius = 180.56 \u00d7 5/9\nCelsius", + "role": "assistant", + "completion_id": None, + "sequence": 1, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + "is_response": True, + }, + ), + ], "amazon.titan-text-express-v1": [ ( {"type": "LlmChatCompletionSummary"}, @@ -666,6 +844,65 @@ } chat_completion_streaming_expected_events = { + "mistral.mistral-7b-instruct-v0:2": [ + ( + {"type": "LlmChatCompletionSummary"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "span_id": None, + "trace_id": "trace-id", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "duration": None, # Response time varies each test run + "request.model": "mistral.mistral-7b-instruct-v0:2", + "response.model": "mistral.mistral-7b-instruct-v0:2", + "request.temperature": 0.7, + "request.max_tokens": 100, + "response.choices.finish_reason": "length", + "vendor": "bedrock", + "ingest_source": "Python", + "response.number_of_messages": 2, + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": "[INST] What is 212 degrees Fahrenheit converted to Celsius? [/INST]", + "role": "user", + "completion_id": None, + "sequence": 0, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": " To convert a temperature from Fahrenheit to Celsius, you can use the following formula: Celsius = (Fahrenheit - 32) × 5/9.\n\nSo, to convert 212 degrees Fahrenheit to Celsius, do the following calculation:\n\nCelsius = (212°F - 32) × 5/9\n\nCelsius = (212 - 32)", + "role": "assistant", + "completion_id": None, + "sequence": 1, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + "is_response": True, + }, + ), + ], "amazon.titan-text-express-v1": [ ( {"type": "LlmChatCompletionSummary"}, @@ -926,6 +1163,46 @@ ] chat_completion_invalid_access_key_error_events = { + "mistral.mistral-7b-instruct-v0:2": [ + ( + {"type": "LlmChatCompletionSummary"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "span_id": None, + "trace_id": "trace-id", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "duration": None, # Response time varies each test run + "request.model": "mistral.mistral-7b-instruct-v0:2", + "response.model": "mistral.mistral-7b-instruct-v0:2", + "request.temperature": 0.7, + "request.max_tokens": 100, + "vendor": "bedrock", + "ingest_source": "Python", + "response.number_of_messages": 1, + "error": True, + }, + ), + ( + {"type": "LlmChatCompletionMessage"}, + { + "id": None, # UUID that varies with each run + "llm.conversation_id": "my-awesome-id", + "llm.foo": "bar", + "request_id": "48c7ee13-7790-461f-959f-04b0a4cf91c8", + "span_id": None, + "trace_id": "trace-id", + "content": "[INST] Invalid Token [/INST]", + "role": "user", + "completion_id": None, + "sequence": 0, + "response.model": "mistral.mistral-7b-instruct-v0:2", + "vendor": "bedrock", + "ingest_source": "Python", + }, + ), + ], "amazon.titan-text-express-v1": [ ( {"type": "LlmChatCompletionSummary"}, diff --git a/tests/external_botocore/conftest.py b/tests/external_botocore/conftest.py index 65acfd1e5d..3ac1920035 100644 --- a/tests/external_botocore/conftest.py +++ b/tests/external_botocore/conftest.py @@ -124,7 +124,7 @@ def wrap_botocore_endpoint_Endpoint__do_get_response(wrapped, instance, args, kw if not request: return wrapped(*args, **kwargs) - match = re.search(r"/model/([0-9a-zA-Z.-]+)/", request.url) + match = re.search(r"/model/([0-9a-zA-Z%.-]+)/", request.url) model = match.group(1) # Send request diff --git a/tests/external_botocore/test_bedrock_chat_completion.py b/tests/external_botocore/test_bedrock_chat_completion.py index fe183c27dc..7cab446348 100644 --- a/tests/external_botocore/test_bedrock_chat_completion.py +++ b/tests/external_botocore/test_bedrock_chat_completion.py @@ -81,6 +81,7 @@ def request_streaming(request): "anthropic.claude-instant-v1", "cohere.command-text-v14", "meta.llama2-13b-chat-v1", + "mistral.mistral-7b-instruct-v0:2", ], ) def model_id(request, response_streaming):