Skip to content

Commit fcc6280

Browse files
committed
add Meta Llama and Cohere Command model test cases
1 parent e3cc650 commit fcc6280

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

test/contract-tests/images/applications/TestSimpleApp.AWSSDK.Core/BedrockTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,62 @@ public object InvokeModelAnthropicClaudeResponse()
104104
};
105105
}
106106

107+
public void InvokeModelMetaLlama()
108+
{
109+
bedrockRuntime.InvokeModelAsync(new InvokeModelRequest
110+
{
111+
ModelId = "meta.llama3-8b-instruct-v1:0",
112+
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new
113+
{
114+
prompt = "sample input text",
115+
temperature = 0.123,
116+
top_p = 0.456,
117+
max_gen_len = 123,
118+
}))),
119+
ContentType = "application/json",
120+
});
121+
return;
122+
}
123+
124+
public object InvokeModelMetaLlamaResponse()
125+
{
126+
return new
127+
{
128+
generation = "sample output text",
129+
prompt_token_count = 456,
130+
generation_token_count = 789,
131+
stop_reason = "finish_reason",
132+
};
133+
}
134+
135+
public void InvokeModelCohereCommand()
136+
{
137+
bedrockRuntime.InvokeModelAsync(new InvokeModelRequest
138+
{
139+
ModelId = "cohere.command-r-v1:0",
140+
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new
141+
{
142+
// prompt is 72 chars long, input_tokens should be estimated as ceil(72/6) = 12
143+
message = "sample input text sample input text sample input text sample input text ",
144+
temperature = 0.123,
145+
p = 0.456,
146+
max_tokens = 123,
147+
}))),
148+
ContentType = "application/json",
149+
});
150+
return;
151+
}
152+
153+
public object InvokeModelCohereCommandResponse()
154+
{
155+
return new
156+
{
157+
// response is 56 chars long, output_tokens should be estimated as ceil(56/6) = 10
158+
text = "sample output text sample output text sample output text",
159+
finish_reason = "finish_reason",
160+
};
161+
}
162+
107163
public Task<GetAgentResponse> GetAgent()
108164
{
109165
return bedrockAgent.GetAgentAsync(new GetAgentRequest

test/contract-tests/images/applications/TestSimpleApp.AWSSDK.Core/Program.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,19 @@
128128
app.MapGet("bedrock/invokemodel/invoke-model-titan", (BedrockTests bedrock) => bedrock.InvokeModelAmazonTitan())
129129
.WithName("invoke-model-titan")
130130
.WithOpenApi();
131+
131132
app.MapGet("bedrock/invokemodel/invoke-model-claude", (BedrockTests bedrock) => bedrock.InvokeModelAnthropicClaude())
132133
.WithName("invoke-model-claude")
133134
.WithOpenApi();
134135

136+
app.MapGet("bedrock/invokemodel/invoke-model-llama", (BedrockTests bedrock) => bedrock.InvokeModelMetaLlama())
137+
.WithName("invoke-model-llama")
138+
.WithOpenApi();
139+
140+
app.MapGet("bedrock/invokemodel/invoke-model-command", (BedrockTests bedrock) => bedrock.InvokeModelCohereCommand())
141+
.WithName("invoke-model-command")
142+
.WithOpenApi();
143+
135144
app.MapGet("bedrock/getagent/get-agent", (BedrockTests bedrock) => bedrock.GetAgent())
136145
.WithName("get-agent")
137146
.WithOpenApi();
@@ -157,6 +166,8 @@
157166
app.MapGet("guardrails/test-guardrail", (BedrockTests bedrock) => bedrock.GetGuardrailResponse());
158167
app.MapPost("model/amazon.titan-text-express-v1/invoke", (BedrockTests bedrock) => bedrock.InvokeModelAmazonTitanResponse());
159168
app.MapPost("model/anthropic.claude-v2:1/invoke", (BedrockTests bedrock) => bedrock.InvokeModelAnthropicClaudeResponse());
169+
app.MapPost("model/meta.llama3-8b-instruct-v1:0/invoke", (BedrockTests bedrock) => bedrock.InvokeModelMetaLlamaResponse());
170+
app.MapPost("model/cohere.command-r-v1:0/invoke", (BedrockTests bedrock) => bedrock.InvokeModelCohereCommandResponse());
160171
app.MapGet("agents/test-agent", (BedrockTests bedrock) => bedrock.GetAgentResponse());
161172
app.MapGet("knowledgebases/test-knowledge-base", (BedrockTests bedrock) => bedrock.GetKnowledgeBaseResponse());
162173
app.MapGet("knowledgebases/test-knowledge-base/datasources/test-data-source", (BedrockTests bedrock) => bedrock.GetDataSourceResponse());

test/contract-tests/tests/test/amazon/awssdk/awssdk_test.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,54 @@ def test_bedrock_runtime_invoke_model_claude(self):
370370
},
371371
span_name="Bedrock Runtime.InvokeModel",
372372
)
373+
374+
def test_bedrock_runtime_invoke_model_llama(self):
375+
self.do_test_requests(
376+
"bedrock/invokemodel/invoke-model-llama",
377+
"GET",
378+
200,
379+
0,
380+
0,
381+
rpc_service="Bedrock Runtime",
382+
remote_service="AWS::BedrockRuntime",
383+
remote_operation="InvokeModel",
384+
remote_resource_type="AWS::Bedrock::Model",
385+
remote_resource_identifier="meta.llama3-8b-instruct-v1:0",
386+
request_specific_attributes={
387+
_GEN_AI_REQUEST_MODEL: "meta.llama3-8b-instruct-v1:0",
388+
_GEN_AI_REQUEST_TEMPERATURE: 0.123,
389+
_GEN_AI_REQUEST_TOP_P: 0.456,
390+
_GEN_AI_REQUEST_MAX_TOKENS: 123,
391+
_GEN_AI_USAGE_INPUT_TOKENS: 456,
392+
_GEN_AI_USAGE_OUTPUT_TOKENS: 789,
393+
_GEN_AI_RESPONSE_FINISH_REASONS: ["finish_reason"],
394+
},
395+
span_name="Bedrock Runtime.InvokeModel",
396+
)
397+
398+
def test_bedrock_runtime_invoke_model_command(self):
399+
self.do_test_requests(
400+
"bedrock/invokemodel/invoke-model-command",
401+
"GET",
402+
200,
403+
0,
404+
0,
405+
rpc_service="Bedrock Runtime",
406+
remote_service="AWS::BedrockRuntime",
407+
remote_operation="InvokeModel",
408+
remote_resource_type="AWS::Bedrock::Model",
409+
remote_resource_identifier="cohere.command-r-v1:0",
410+
request_specific_attributes={
411+
_GEN_AI_REQUEST_MODEL: "cohere.command-r-v1:0",
412+
_GEN_AI_REQUEST_TEMPERATURE: 0.123,
413+
_GEN_AI_REQUEST_TOP_P: 0.456,
414+
_GEN_AI_REQUEST_MAX_TOKENS: 123,
415+
_GEN_AI_USAGE_INPUT_TOKENS: 12,
416+
_GEN_AI_USAGE_OUTPUT_TOKENS: 10,
417+
_GEN_AI_RESPONSE_FINISH_REASONS: ["finish_reason"],
418+
},
419+
span_name="Bedrock Runtime.InvokeModel",
420+
)
373421

374422
def test_bedrock_agent_runtime_invoke_agent(self):
375423
self.do_test_requests(
@@ -637,6 +685,8 @@ def _filter_bedrock_metrics(self, target_metrics: List[Metric]):
637685
"POST agents/test-agent/agentAliases/test-agent-alias/sessions/test-session/text",
638686
"POST model/amazon.titan-text-express-v1/invoke",
639687
"POST model/anthropic.claude-v2:1/invoke",
688+
"POST model/meta.llama3-8b-instruct-v1:0/invoke",
689+
"POST model/cohere.command-r-v1:0/invoke",
640690
"POST knowledgebases/test-knowledge-base/retrieve"
641691
}
642692
for metric in target_metrics:

0 commit comments

Comments
 (0)