Skip to content

Commit

Permalink
image creator cookies fix
Browse files Browse the repository at this point in the history
  • Loading branch information
brainboost committed Mar 31, 2024
1 parent da01097 commit 49f5de9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
12 changes: 8 additions & 4 deletions engines/dalle_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ def create() -> ImageGen:
bucket_name = read_ssm_param(param_name="BOT_S3_BUCKET")
auth_cookies = read_json_from_s3(bucket_name, "bing-cookies.json")
u = [x.get("value") for x in auth_cookies if x.get("name") == "_U"][0]
srch = [x.get("value") for x in auth_cookies if x.get("name") == "SRCHHPGUSR"][0]
return ImageGen(
auth_cookie=u, auth_cookie_SRCHHPGUSR=srch, quiet=True, all_cookies=auth_cookies
)
srch = srch = [
x.get("value")
for x in auth_cookies
if x.get("name") == "SRCHHPGUSR" and x.get("path") == "/images"
][0]
return ImageGen(auth_cookie=u, auth_cookie_SRCHHPGUSR=srch, quiet=True)


imageGen = create()
result_topic = read_ssm_param(param_name="RESULT_SNS_TOPIC_ARN")
sns = boto3.session.Session().client("sns")


def __process_payload(payload: Any, request_id: str) -> None:
prompt = payload["text"]
list = []
Expand Down Expand Up @@ -82,6 +85,7 @@ def sqs_handler(event, context):
payload = json.loads(record["body"])
__process_payload(payload, request_id)


def sns_handler(event, context):
"""AWS SNS event handler"""
request_id = context.aws_request_id
Expand Down
2 changes: 1 addition & 1 deletion engines/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
revchatgpt @ git+https://github.com/brainboost/ChatGPT.git
bingimagecreator @ git+https://github.com/brainboost/BingImageCreator.git
BingImageCreator-plus
EdgeGPT-plus
google-generativeai
deepl
Expand Down
11 changes: 11 additions & 0 deletions tests/test_bing_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from engines.dalle_img import imageGen


# @pytest.mark.skip()
def test_check_and_refresh(capsys):
with capsys.disabled():
prompt = "roasted coffee beans in palms"
assert imageGen
list = imageGen.get_images(prompt)
assert list
print(list)
8 changes: 4 additions & 4 deletions tests/test_ideogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
)


# @pytest.mark.skip()
@pytest.mark.skip()
def test_check_and_refresh(capsys):
with capsys.disabled():
tokens = check_and_refresh_auth_tokens()
assert "access_token" in tokens
assert "refresh_token" in tokens


# @pytest.mark.skip()
@pytest.mark.skip()
def test_refresh(capsys):
with capsys.disabled():
bucket_name = read_ssm_param(param_name="BOT_S3_BUCKET")
Expand All @@ -27,7 +27,7 @@ def test_refresh(capsys):
assert not is_expired(data["access_token"])


# @pytest.mark.skip()
@pytest.mark.skip()
def test_request_images(capsys):
with capsys.disabled():
response = request_images(
Expand All @@ -36,7 +36,7 @@ def test_request_images(capsys):
assert response


# @pytest.mark.skip()
@pytest.mark.skip()
def test_get_session_cookies(capsys):
with capsys.disabled():
bucket_name = read_ssm_param(param_name="BOT_S3_BUCKET")
Expand Down

0 comments on commit 49f5de9

Please sign in to comment.