Skip to content

Commit

Permalink
Merge branch 'main' into fix-glue
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther authored Feb 5, 2024
2 parents 2d63a8e + 4b0bd9a commit 34505cd
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# .git-blame-ignore-revs
# Normalize SPDX Copyright header
de7b1ee3fae2e3cd7d81a24c17345040f76b1d75
# Full linting pass for PHP
a89ae9751bb71d5fbd4c998adcd34c911c088a1c
2 changes: 1 addition & 1 deletion .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v1
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

Expand Down
54 changes: 49 additions & 5 deletions cpp/example_code/mediaconvert/tests/MediaConvert_gtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,42 @@
#include <aws/testing/mocks/http/MockHttpClient.h>
#include "mediaconvert_samples.h"

// Debug testing framework start.
#include <aws/core/utils/logging/ConsoleLogSystem.h>

class DebugMockHTTPClient : public MockHttpClient {
public:
DebugMockHTTPClient() {}

std::shared_ptr<Aws::Http::HttpResponse>
MakeRequest(const std::shared_ptr<Aws::Http::HttpRequest> &request,
Aws::Utils::RateLimits::RateLimiterInterface *readLimiter,
Aws::Utils::RateLimits::RateLimiterInterface *writeLimiter) const override {

auto result = MockHttpClient::MakeRequest(request, readLimiter, writeLimiter);

std::cout << "DebugMockHTTPClient::MakeRequest URI " << request->GetURIString()
<< ", query " << request->GetQueryString()
<< ", result " << result.get() << "." << std::endl;

return result;
}
};
// Debug testing framework end.

Aws::SDKOptions AwsDocTest::MediaConvert_GTests::s_options;
std::unique_ptr<Aws::Client::ClientConfiguration> AwsDocTest::MediaConvert_GTests::s_clientConfig;
static const char ALLOCATION_TAG[] = "RDS_GTEST";

void AwsDocTest::MediaConvert_GTests::SetUpTestSuite() {
// Debug testing framework start.
s_options.loggingOptions.logger_create_fn = []() {
std::cerr << "Log create function called. " << std::endl;
return Aws::MakeShared<Aws::Utils::Logging::ConsoleLogSystem>(
ALLOCATION_TAG, Aws::Utils::Logging::LogLevel::Debug);
};
s_options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;
// Debug testing framework end.
InitAPI(s_options);

// s_clientConfig must be a pointer because the client config must be initialized
Expand Down Expand Up @@ -72,7 +102,8 @@ void AwsDocTest::MediaConvert_GTests::AddCommandLineResponses(


bool AwsDocTest::MediaConvert_GTests::suppressStdOut() {
return std::getenv("EXAMPLE_TESTS_LOG_ON") == nullptr;
// return std::getenv("EXAMPLE_TESTS_LOG_ON") == nullptr;
return false; // Temporary override to debug testing framework.
}

void AwsDocTest::MediaConvert_GTests::createEndpointCache() {
Expand Down Expand Up @@ -107,35 +138,48 @@ int AwsDocTest::MyStringBuffer::underflow() {
}

AwsDocTest::MockHTTP::MockHTTP() {
mockHttpClient = Aws::MakeShared<MockHttpClient>(ALLOCATION_TAG);
mockHttpClient = Aws::MakeShared<DebugMockHTTPClient>(
ALLOCATION_TAG); // Debug testing framework.
mockHttpClientFactory = Aws::MakeShared<MockHttpClientFactory>(ALLOCATION_TAG);
mockHttpClientFactory->SetClient(mockHttpClient);
SetHttpClientFactory(mockHttpClientFactory);
requestTmp = CreateHttpRequest(Aws::Http::URI("https://test.com/"),
Aws::Http::HttpMethod::HTTP_GET,
Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);

std::cout << "AwsDocTest::MockHTTP::MockHTTP called."
<< std::endl; // Debug testing framework.
}

AwsDocTest::MockHTTP::~MockHTTP() {
std::cout << "AwsDocTest::MockHTTP::~MockHTTP called."
<< std::endl; // Debug testing framework.
Aws::Http::CleanupHttp();
Aws::Http::InitHttp();
}

bool AwsDocTest::MockHTTP::addResponseWithBody(const std::string &fileName,
Aws::Http::HttpResponseCode httpResponseCode) {

std::ifstream inStream(std::string(SRC_DIR) + "/" + fileName);
std::string filePath = std::string(SRC_DIR) + "/" + fileName;
std::cout << "AwsDocTest::MockHTTP::addResponseWithBody called with file "
<< filePath
<< "." << std::endl; // Debug testing framework.
std::ifstream inStream(filePath);
if (inStream) {
std::shared_ptr<Aws::Http::Standard::StandardHttpResponse> goodResponse = Aws::MakeShared<Aws::Http::Standard::StandardHttpResponse>(
ALLOCATION_TAG, requestTmp);
goodResponse->AddHeader("Content-Type", "text/json");
goodResponse->SetResponseCode(httpResponseCode);
goodResponse->GetResponseBody() << inStream.rdbuf();
mockHttpClient->AddResponseToReturn(goodResponse);

std::cout << "AwsDocTest::MockHTTP::addResponseWithBody response added "
<< goodResponse.get()
<< "." << std::endl; // Debug testing framework.
return true;
}

std::cerr << "MockHTTP::addResponseWithBody open file error '" << fileName << "'."
std::cerr << "MockHTTP::addResponseWithBody open file error '" << filePath << "'."
<< std::endl;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#include "S3_GTests.h"

namespace AwsDocTest {
// This test is flaky. Add the D to disable it.
// NOLINTNEXTLINE(readability-named-parameter)
TEST_F(S3_GTests, list_buckets_diabling_dns_cache_2_) {
TEST_F(S3_GTests, list_buckets_disabling_dns_cache_2D_) {

bool result = AwsDoc::S3::ListBucketDisablingDnsCache(*s_clientConfig);
EXPECT_TRUE(result);
Expand Down
36 changes: 5 additions & 31 deletions cpp/example_code/ses/tests/ses_gtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@
#include <aws/core/utils/UUID.h>
#include <aws/testing/mocks/http/MockHttpClient.h>

// Debug testing framework.
class DebugMockHTTPClient : public MockHttpClient {
public:
DebugMockHTTPClient() {}

std::shared_ptr<Aws::Http::HttpResponse>
MakeRequest(const std::shared_ptr<Aws::Http::HttpRequest> &request,
Aws::Utils::RateLimits::RateLimiterInterface *readLimiter,
Aws::Utils::RateLimits::RateLimiterInterface *writeLimiter) const override {

auto result = MockHttpClient::MakeRequest(request, readLimiter, writeLimiter);

std::cout << "DebugMockHTTPClient::MakeRequest result " << result.get() << "." << std::endl;

return result;
}
};

Aws::SDKOptions AwsDocTest::SES_GTests::s_options;
std::unique_ptr<Aws::Client::ClientConfiguration> AwsDocTest::SES_GTests::s_clientConfig;
Expand Down Expand Up @@ -84,8 +67,7 @@ void AwsDocTest::SES_GTests::AddCommandLineResponses(
}

bool AwsDocTest::SES_GTests::suppressStdOut() {
// return std::getenv("EXAMPLE_TESTS_LOG_ON") == nullptr;
return false; // Temporary override to debug testing framework.
return std::getenv("EXAMPLE_TESTS_LOG_ON") == nullptr;
}

int AwsDocTest::MyStringBuffer::underflow() {
Expand All @@ -100,43 +82,35 @@ int AwsDocTest::MyStringBuffer::underflow() {


AwsDocTest::MockHTTP::MockHTTP() {
mockHttpClient = Aws::MakeShared<DebugMockHTTPClient>(ALLOCATION_TAG); // Debug testing framework.
mockHttpClient = Aws::MakeShared<MockHttpClient>(ALLOCATION_TAG);
mockHttpClientFactory = Aws::MakeShared<MockHttpClientFactory>(ALLOCATION_TAG);
mockHttpClientFactory->SetClient(mockHttpClient);
SetHttpClientFactory(mockHttpClientFactory);
requestTmp = CreateHttpRequest(Aws::Http::URI("https://test.com/"),
Aws::Http::HttpMethod::HTTP_GET,
Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);

std::cout << "AwsDocTest::MockHTTP::MockHTTP called." << std::endl; // Debug testing framework.
}

AwsDocTest::MockHTTP::~MockHTTP() {
std::cout << "AwsDocTest::MockHTTP::~MockHTTP called." << std::endl; // Debug testing framework.
Aws::Http::CleanupHttp();
Aws::Http::InitHttp();
}

bool AwsDocTest::MockHTTP::addResponseWithBody(const std::string &fileName,
Aws::Http::HttpResponseCode httpResponseCode) {
std::string filePath = std::string(SRC_DIR) + "/" + fileName;
std::cout << "AwsDocTest::MockHTTP::addResponseWithBody called with file " << filePath
<< "." << std::endl; // Debug testing framework.
std::ifstream inStream(filePath);

std::ifstream inStream(std::string(SRC_DIR) + "/" + fileName);
if (inStream) {
std::shared_ptr<Aws::Http::Standard::StandardHttpResponse> goodResponse = Aws::MakeShared<Aws::Http::Standard::StandardHttpResponse>(
ALLOCATION_TAG, requestTmp);
goodResponse->AddHeader("Content-Type", "text/json");
goodResponse->SetResponseCode(httpResponseCode);
goodResponse->GetResponseBody() << inStream.rdbuf();
mockHttpClient->AddResponseToReturn(goodResponse);

std::cout << "AwsDocTest::MockHTTP::addResponseWithBody response added " << goodResponse.get()
<< "." << std::endl; // Debug testing framework.
return true;
}

std::cerr << "MockHTTP::addResponseWithBody open file error '" << filePath << "'."
std::cerr << "MockHTTP::addResponseWithBody open file error '" << fileName << "'."
<< std::endl;

return false;
Expand Down
52 changes: 28 additions & 24 deletions cpp/run_automated_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ def run_tests(run_files=[], type1=False, type2=False, type3=False):
if type3:
filters.append("*_3_")

filter_arg = ""
if len(filters) > 0:
filter_arg = f"--gtest_filter={':'.join(filters)}"
if len(filters) == 0:
filters.append("") # Run once with no filter.

passed_tests = 0
failed_tests = 0
Expand All @@ -126,27 +125,32 @@ def run_tests(run_files=[], type1=False, type2=False, type3=False):
os.makedirs(name=run_dir, exist_ok=True)
os.chdir(run_dir)
for run_file in run_files:
print(f"Calling '{run_file} {filter_arg}'.")
proc = subprocess.Popen(
[run_file, filter_arg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
for line in proc.stdout:
line = line.decode("utf-8")
sys.stdout.write(line)

match = re.search("\[ PASSED \] (\d+) test", line)
if match is not None:
passed_tests = passed_tests + int(match.group(1))
continue
match = re.search("\[ FAILED \] (\d+) test", line)
if match is not None:
failed_tests = failed_tests + int(match.group(1))
continue

proc.wait()

if proc.returncode != 0:
has_error = True
# Run each filter separately or the no filter case.
for filter in filters:
filter_arg = ""
if len(filter) > 0:
filter_arg = f"--gtest_filter={filter}"
print(f"Calling '{run_file} {filter_arg}'.")
proc = subprocess.Popen(
[run_file, filter_arg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
for line in proc.stdout:
line = line.decode("utf-8")
sys.stdout.write(line)

match = re.search("\[ PASSED \] (\d+) test", line)
if match is not None:
passed_tests = passed_tests + int(match.group(1))
continue
match = re.search("\[ FAILED \] (\d+) test", line)
if match is not None:
failed_tests = failed_tests + int(match.group(1))
continue

proc.wait()

if proc.returncode != 0:
has_error = True

print("-" * 88)
print(f"{passed_tests} tests passed.")
Expand Down
4 changes: 2 additions & 2 deletions gov2/bedrock-runtime/actions/invoke_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type InvokeModelWrapper struct {

// Each model provider has their own individual request and response formats.
// For the format, ranges, and default values for Anthropic Claude, refer to:
// https://docs.anthropic.com/claude/reference/complete_post
// https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html

type ClaudeRequest struct {
Prompt string `json:"prompt"`
Expand Down Expand Up @@ -79,7 +79,7 @@ func (wrapper InvokeModelWrapper) InvokeClaude(prompt string) (string, error) {

// Each model provider has their own individual request and response formats.
// For the format, ranges, and default values for AI21 Labs Jurassic-2, refer to:
// https://docs.ai21.com/reference/j2-complete-ref
// https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-jurassic2.html

type Jurassic2Request struct {
Prompt string `json:"prompt"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const invokeClaude = async (prompt) => {

/* The different model providers have individual request and response formats.
* For the format, ranges, and default values for Anthropic Claude, refer to:
* https://docs.anthropic.com/claude/reference/complete_post
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html
*/
const payload = {
prompt: enclosedPrompt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const invokeJurassic2 = async (prompt) => {

/* The different model providers have individual request and response formats.
* For the format, ranges, and default values for AI21 Labs Jurassic-2, refer to:
* https://docs.ai21.com/reference/j2-complete-ref
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-jurassic2.html
*/
const payload = {
prompt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static String invokeClaude(String prompt) {
/*
* The different model providers have individual request and response formats.
* For the format, ranges, and default values for Anthropic Claude, refer to:
* https://docs.anthropic.com/claude/reference/complete_post
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html
*/

String claudeModelId = "anthropic.claude-v2";
Expand Down Expand Up @@ -89,7 +89,7 @@ public static String invokeJurassic2(String prompt) {
* The different model providers have individual request and response formats.
* For the format, ranges, and default values for AI21 Labs Jurassic-2, refer
* to:
* https://docs.ai21.com/reference/j2-complete-ref
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-jurassic2.html
*/

String jurassic2ModelId = "ai21.j2-mid-v1";
Expand Down Expand Up @@ -190,7 +190,7 @@ public static String invokeStableDiffusion(String prompt, long seed, String styl
* The different model providers have individual request and response formats.
* For the format, ranges, and available style_presets of Stable Diffusion
* models refer to:
* https://platform.stability.ai/docs/api-reference#tag/v1generation
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-stability-diffusion.html
*/

String stableDiffusionModelId = "stability.stable-diffusion-xl";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
package com.example.bedrockruntime;

// snippet-start:[bedrock-runtime.java2.invoke_model_async.import]

import org.json.JSONArray;
import org.json.JSONObject;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;
import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelRequest;
import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelResponse;

Expand Down Expand Up @@ -41,7 +41,7 @@ public static String invokeClaude(String prompt) {
/*
* The different model providers have individual request and response formats.
* For the format, ranges, and default values for Anthropic Claude, refer to:
* https://docs.anthropic.com/claude/reference/complete_post
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html
*/

String claudeModelId = "anthropic.claude-v2";
Expand Down Expand Up @@ -103,7 +103,7 @@ public static String invokeJurassic2(String prompt) {
/*
* The different model providers have individual request and response formats.
* For the format, ranges, and default values for Anthropic Claude, refer to:
* https://docs.anthropic.com/claude/reference/complete_post
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html
*/

String jurassic2ModelId = "ai21.j2-mid-v1";
Expand Down Expand Up @@ -232,7 +232,7 @@ public static String invokeStableDiffusion(String prompt, long seed, String styl
* The different model providers have individual request and response formats.
* For the format, ranges, and available style_presets of Stable Diffusion
* models refer to:
* https://platform.stability.ai/docs/api-reference#tag/v1generation
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-stability-diffusion.html
*/

String stableDiffusionModelId = "stability.stable-diffusion-xl";
Expand Down
Loading

0 comments on commit 34505cd

Please sign in to comment.