Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
git: ensure the order of image urls (#179)
Browse files Browse the repository at this point in the history
ensure the order of image urls
  • Loading branch information
dsdanielpark authored Sep 4, 2023
2 parents 539a3c5 + 00575ae commit f5d8fcc
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions bardapi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_answer(self, input_text: str) -> dict:
"text_query": str,
"choices": list,
"links": list,
"images": set,
"images": list,
"program_lang": str,
"code": str,
"status_code": int
Expand Down Expand Up @@ -219,12 +219,12 @@ def get_answer(self, input_text: str) -> dict:
resp_json = json.loads(resp_dict)

# [Optional] gather image links
images = set()
images = list()
try:
if len(resp_json) >= 3:
nested_list = resp_json[4][0][4]
for img in nested_list:
images.add(img[0][0][0])
images.append(img[0][0][0])
except (IndexError, TypeError, KeyError):
pass

Expand Down Expand Up @@ -461,7 +461,7 @@ def ask_about_image(
"text_query": str,
"choices": list,
"links": list,
"images": set,
"images": list,
"program_lang": str,
"code": str,
"status_code": int
Expand Down
8 changes: 4 additions & 4 deletions bardapi/core_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def get_answer(self, input_text: str) -> dict:
"text_query": str,
"choices": list,
"links": list
"images": set,
"images": list,
"program_lang": str,
"code": str,
"status_code": int
Expand Down Expand Up @@ -210,12 +210,12 @@ async def get_answer(self, input_text: str) -> dict:

# [Optional] Gather image links
try:
images = set()
images = list()
if len(resp_json) >= 3:
if len(resp_json[4][0]) >= 4 and resp_json[4][0][4] is not None:
for img in resp_json[4][0][4]:
try:
images.add(img[0][0][0])
images.append(img[0][0][0])
except Exception as e:
# TODO:
# handle exception using logging instead
Expand Down Expand Up @@ -584,7 +584,7 @@ async def ask_about_image(
"text_query": str,
"choices": list,
"links": list,
"images": set,
"images": list,
"program_lang": str,
"code": str,
"status_code": int
Expand Down
8 changes: 4 additions & 4 deletions bardapi/core_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_answer(self, input_text: str) -> dict:
"text_query": str,
"choices": list,
"links": list
"images": set,
"images": list,
"program_lang": str,
"code": str,
"status_code": int
Expand Down Expand Up @@ -202,7 +202,7 @@ def ask_about_image(
"text_query": str,
"choices": list,
"links": list,
"images": set,
"images": list,
"program_lang": str,
"code": str,
"status_code": int
Expand Down Expand Up @@ -398,7 +398,7 @@ async def get_answer(self, input_text: str) -> dict:
"text_query": str,
"choices": list,
"links": list
"images": set,
"images": list,
"program_lang": str,
"code": str,
"status_code": int
Expand Down Expand Up @@ -475,7 +475,7 @@ async def ask_about_image(
"text_query": str,
"choices": list,
"links": list,
"images": set,
"images": list,
"program_lang": str,
"code": str,
"status_code": int
Expand Down
2 changes: 1 addition & 1 deletion documents/README_DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ from bardapi import Bard
bard = Bard(token='xxxxxxxx')
res = bard.get_answer("Find me an image of the main entrance of Stanford University.")
res['links'] # Get image links (list)
res['images'] # Get images (set)
res['images'] # Get images (list)
```

<br>
Expand Down
4 changes: 2 additions & 2 deletions func_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"bard = Bard(token=token)\n",
"res = bard.get_answer(\"Find me an image of the main entrance of Stanford University.\")\n",
"res['links'] # Get image links (list)\n",
"res['images'] # Get images (set)"
"res['images'] # Get images (list)"
]
},
{
Expand All @@ -64,7 +64,7 @@
"bard = Bard(token=token)\n",
"res = bard.get_answer(\"Find me an image of the main entrance of Stanford University.\")\n",
"res['links'] # Get image links (list)\n",
"res['images'] # Get images (set)"
"res['images'] # Get images (list)"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions translate_to/asyncio_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ async def get_answer(self, input_text: str) -> dict:
if not resp_dict:
return {"content": f"Response Error: {resp_text}."}
resp_json = json.loads(resp_dict)
images = set()
images = list()
if len(resp_json) >= 3:
if len(resp_json[4][0]) >= 4 and resp_json[4][0][4] is not None:
for img in resp_json[4][0][4]:
images.add(img[0][0][0])
images.append(img[0][0][0])
parsed_answer = json.loads(resp_dict)
if self.language is not None and self.language not in ALLOWED_LANGUAGES:
translator_to_lang = GoogleTranslator(source="auto", target=self.language)
Expand Down
4 changes: 2 additions & 2 deletions translate_to/core_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ async def get_answer(self, input_text: str) -> dict:
resp_json = json.loads(resp_dict)

# Gather image links
images = set()
images = list()
if len(resp_json) >= 3:
if len(resp_json[4][0]) >= 4 and resp_json[4][0][4] is not None:
for img in resp_json[4][0][4]:
try:
images.add(img[0][0][0])
images.append(img[0][0][0])
except Exception as e:
# TODO:
# handle exception using logging instead
Expand Down

0 comments on commit f5d8fcc

Please sign in to comment.