community[patch]: chat model mypy fixes (#17061)

Related to #17048
This commit is contained in:
Bagatur
2024-02-05 13:42:59 -08:00
committed by GitHub
parent d93de71d08
commit 66e45e8ab7
17 changed files with 101 additions and 89 deletions

View File

@@ -120,11 +120,10 @@ def _parse_chat_history_gemini(
image = load_image_from_gcs(path=path, project=project)
elif path.startswith("data:image/"):
# extract base64 component from image uri
try:
encoded = re.search(r"data:image/\w{2,4};base64,(.*)", path).group( # type: ignore[union-attr]
1
)
except AttributeError:
encoded: Any = re.search(r"data:image/\w{2,4};base64,(.*)", path)
if encoded:
encoded = encoded.group(1)
else:
raise ValueError(
"Invalid image uri. It should be in the format "
"data:image/<image_type>;base64,<base64_encoded_image>."