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

Commit

Permalink
chore: style black
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdanielpark committed Aug 9, 2023
1 parent ecbbeac commit cd759f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 8 additions & 6 deletions bardapi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_answer(self, input_text: str) -> dict:
api_key=self.google_translator_api_key
)

# [Optional] Set language
# [Optional] Set language
if (
self.language is not None
and self.language not in ALLOWED_LANGUAGES
Expand Down Expand Up @@ -158,7 +158,7 @@ def get_answer(self, input_text: str) -> dict:
}
resp_json = json.loads(resp_dict)

# [Optional] gather image links
# [Optional] gather image links
images = set()
try:
if len(resp_json) >= 3:
Expand All @@ -171,7 +171,7 @@ def get_answer(self, input_text: str) -> dict:
# Parsed Answer Object
parsed_answer = json.loads(resp_dict)

# [Optional] translated by google translator
# [Optional] translated by google translator
# Unofficial
if (
self.language is not None
Expand Down Expand Up @@ -200,9 +200,11 @@ def get_answer(self, input_text: str) -> dict:
for x in parsed_answer[4]
]

# [Optional] get program_lang & code
# [Optional] get program_lang & code
try:
program_lang = parsed_answer[4][0][1][0].split("```")[1].split("\n")[0].strip()
program_lang = (
parsed_answer[4][0][1][0].split("```")[1].split("\n")[0].strip()
)
code = parsed_answer[4][0][1][0].split("```")[1][len(program_lang) :]
except Exception:
program_lang, code = None, None
Expand Down Expand Up @@ -409,7 +411,7 @@ def ask_about_image(self, input_text: str, image: bytes, lang: str = None) -> di
else:
translator_to_eng = GoogleTranslator(source="auto", target="en")

# [Optional] Set language
# [Optional] Set language
if (
(self.language is not None or lang is not None)
and self.language not in ALLOWED_LANGUAGES
Expand Down
12 changes: 7 additions & 5 deletions bardapi/core_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def get_answer(self, input_text: str) -> dict:
api_key=self.google_translator_api_key
)

# [Optional] Set language
# [Optional] Set language
if (
self.language is not None
and self.language not in ALLOWED_LANGUAGES
Expand Down Expand Up @@ -158,7 +158,7 @@ async def get_answer(self, input_text: str) -> dict:
return {"content": f"Response Error: {resp.content}."}
resp_json = json.loads(resp_dict)

# [Optional] Gather image links
# [Optional] Gather image links
try:
images = set()
if len(resp_json) >= 3:
Expand All @@ -174,7 +174,7 @@ async def get_answer(self, input_text: str) -> dict:
pass
parsed_answer = json.loads(resp_dict)

# [Optional] Translated by google translator
# [Optional] Translated by google translator
## Unofficial for testing
if (
self.language is not None
Expand Down Expand Up @@ -204,7 +204,9 @@ async def get_answer(self, input_text: str) -> dict:

# Get code
try:
program_lang = parsed_answer[4][0][1][0].split("```")[1].split("\n")[0].strip()
program_lang = (
parsed_answer[4][0][1][0].split("```")[1].split("\n")[0].strip()
)
code = parsed_answer[4][0][1][0].split("```")[1][len(program_lang) :]
except Exception:
program_lang, code = None, None
Expand Down Expand Up @@ -571,7 +573,7 @@ async def ask_about_image(
else:
translator_to_eng = GoogleTranslator(source="auto", target="en")

# [Optional] Set language
# [Optional] Set language
if (
(self.language is not None or lang is not None)
and self.language not in ALLOWED_LANGUAGES
Expand Down

0 comments on commit cd759f5

Please sign in to comment.