Skip to content

Commit

Permalink
Merge pull request #3274 from digitalfabrik/feature/intgreat-chat-req…
Browse files Browse the repository at this point in the history
…uest-timeout

Add timeout setting for Integreat chat
  • Loading branch information
svenseeberg authored Dec 7, 2024
2 parents b0f0dcd + e56db91 commit c391eaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions integreat_cms/api/v3/chat/utils/chat_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def automatic_answer(message: str, region: Region, language_slug: str) -> str |
f"https://{settings.INTEGREAT_CHAT_BACK_END_DOMAIN}/chatanswers/extract_answer/"
)
body = {"message": message, "language": language_slug, "region": region.slug}
r = requests.post(url, json=body, timeout=120)
r = requests.post(url, json=body, timeout=settings.INTEGREAT_CHAT_BACK_END_TIMEOUT)
return format_message(r.json())


Expand All @@ -58,7 +58,9 @@ def automatic_translation(
"source_language": source_language_slug,
"target_language": target_language_slug,
}
response = requests.post(url, json=body, timeout=120).json()
response = requests.post(
url, json=body, timeout=settings.INTEGREAT_CHAT_BACK_END_TIMEOUT
).json()
if "status" in response and response["status"] == "success":
return response["translation"]
raise ValueError("Did not receive success response for translation request.")
Expand Down
9 changes: 8 additions & 1 deletion integreat_cms/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,14 @@
USER_CHAT_TICKET_GROUP: Final[str] = "integreat-chat"

#: Integreat Chat (app) backend server domain
INTEGREAT_CHAT_BACK_END_DOMAIN = "igchat-inference.tuerantuer.org"
INTEGREAT_CHAT_BACK_END_DOMAIN = os.environ.get(
"INTEGREAT_CMS_INTEGREAT_CHAT_BACK_END_DOMAIN", "igchat-inference.tuerantuer.org"
)

#: Integreat Chat (app) backend timeout
INTEGREAT_CHAT_BACK_END_TIMEOUT = os.environ.get(
"INTEGREAT_CMS_INTEGREAT_CHAT_BACK_END_TIMEOUT", 300
)

##########
# CELERY #
Expand Down

0 comments on commit c391eaa

Please sign in to comment.