-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Bandit + Only create API Gateway when needed + Add multimodal test (
#555) * chore: Fix bandit script and review the flagged issues * chore: Review/update code analysis feedbacks * feat: Add llm handlers logs to the dashboard + format * test: Add multi modal test * feat: Remove API Gateway when sagemaker multi modal is not used.
- Loading branch information
1 parent
21de272
commit b9545cc
Showing
27 changed files
with
682 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
exclude_dirs: ['tests', 'cdk.out', 'dist', 'node_modules', 'lib/user-interface/react-app'] | ||
exclude_dirs: ['tests', 'cdk.out', 'dist', 'node_modules', 'lib/user-interface/react-app'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import json | ||
import os | ||
import time | ||
import uuid | ||
import boto3 | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
def test_multi_modal( | ||
client, config, cognito_credentials, default_multimodal_model, default_provider | ||
): | ||
bucket = config.get("Storage").get("AWSS3").get("bucket") | ||
s3 = boto3.resource( | ||
"s3", | ||
# Use identity pool credentials to verify it owrks | ||
aws_access_key_id=cognito_credentials.aws_access_key, | ||
aws_secret_access_key=cognito_credentials.aws_secret_key, | ||
aws_session_token=cognito_credentials.aws_token, | ||
) | ||
key = "INTEG_TEST" + str(uuid.uuid4()) + ".jpeg" | ||
object = s3.Object(bucket, "public/" + key) | ||
wrong_object = s3.Object(bucket, "private/notallowed/1.jpg") | ||
current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
object.put(Body=Path(current_dir + "/resources/powered-by-aws.png").read_bytes()) | ||
with pytest.raises(Exception, match="AccessDenied"): | ||
wrong_object.put( | ||
Body=Path(current_dir + "/resources/powered-by-aws.png").read_bytes() | ||
) | ||
|
||
session_id = str(uuid.uuid4()) | ||
|
||
request = { | ||
"action": "run", | ||
"modelInterface": "multimodal", | ||
"data": { | ||
"mode": "chain", | ||
"text": "What is this image?", | ||
"files": [{"key": key, "provider": "s3"}], | ||
"modelName": default_multimodal_model, | ||
"provider": default_provider, | ||
"sessionId": session_id, | ||
}, | ||
} | ||
|
||
client.send_query(json.dumps(request)) | ||
|
||
content = None | ||
retries = 0 | ||
while retries < 30: | ||
time.sleep(1) | ||
retries += 1 | ||
session = client.get_session(session_id) | ||
if session != None and len(session.get("history")) == 2: | ||
content = session.get("history")[1].get("content").lower() | ||
break | ||
|
||
assert "powered by" in content | ||
client.delete_session(session_id) | ||
object.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,13 @@ def cognito_credentials(config, worker_id) -> Credentials: | |
user_pool_id = config.get("aws_user_pools_id") | ||
region = config.get("aws_cognito_region") | ||
user_pool_client_id = config.get("aws_user_pools_web_client_id") | ||
identity_pool_id = config.get("aws_cognito_identity_pool_id") | ||
|
||
cognito = CognitoClient( | ||
region=region, user_pool_id=user_pool_id, client_id=user_pool_client_id | ||
region=region, | ||
user_pool_id=user_pool_id, | ||
client_id=user_pool_client_id, | ||
identity_pool_id=identity_pool_id, | ||
) | ||
email = "[email protected]" + worker_id | ||
|
||
|
@@ -44,6 +48,11 @@ def default_embed_model(): | |
return "amazon.titan-embed-text-v1" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def default_multimodal_model(): | ||
return "anthropic.claude-3-haiku-20240307-v1:0" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def default_provider(): | ||
return "bedrock" | ||
|
@@ -62,7 +71,7 @@ def react_url(): | |
return os.environ["REACT_APP_URL"] | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
@pytest.fixture(scope="module") | ||
def selenium_driver(react_url): | ||
options = webdriver.FirefoxOptions() | ||
if os.getenv("HEADLESS"): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.