Skip to content

Commit

Permalink
feat: api timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
4gac committed Dec 9, 2024
1 parent 992fcb7 commit 8557ad9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/ai.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64

import httpx
from openai import OpenAI


Expand All @@ -12,8 +13,10 @@ def encode_image(image_path: str):
def alt_description(img_path: str, api_key: str, lang: str):
# Getting the base64 string
base64_image = encode_image(img_path)
# print("Using api key: {}".format(api_key))
client = OpenAI(api_key=api_key)

client = OpenAI(
api_key=api_key, timeout=httpx.Timeout(None, connect=10, read=60, write=30)
)

response = client.chat.completions.create(
model="gpt-4o-mini",
Expand Down
8 changes: 2 additions & 6 deletions src/process_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ def render_page(doc: PdfDoc, page_num: int, bbox: PdfRect, zoom: float) -> bytea


def update_image_alt(
elem: PdsStructElement,
doc: PdfDoc,
api_key: str,
overwrite: bool,
lang: str
elem: PdsStructElement, doc: PdfDoc, api_key: str, overwrite: bool, lang: str
) -> None:
img = "image_" + str(elem.GetObject().GetId()) + ".jpg"

Expand Down Expand Up @@ -135,7 +131,7 @@ def alt_text(
tags: str,
license_name: str,
license_key: str,
api_key: str,
api_key: str,
overwrite: bool,
lang: str,
) -> None:
Expand Down

0 comments on commit 8557ad9

Please sign in to comment.