Add langchain integration

This commit is contained in:
hlohaus 2025-02-27 12:25:41 +01:00
parent 65265f3e51
commit 4e12f048b1
11 changed files with 133 additions and 88 deletions

View file

@ -23,10 +23,20 @@ def is_openai(text: str) -> bool:
async def raise_for_status_async(response: Union[StreamResponse, ClientResponse], message: str = None):
if response.ok:
return
text = await response.text()
text = (await response.text()).strip()
if message is None:
is_html = response.headers.get("content-type", "").startswith("text/html") or text.startswith("<!DOCTYPE")
message = "HTML content" if is_html else text
content_type = response.headers.get("content-type", "")
if content_type.startswith("application/json"):
try:
data = await response.json()
message = data.get("error")
if isinstance(message, dict):
message = data.get("message")
except Exception:
pass
else:
is_html = content_type.startswith("text/html") or text.startswith("<!DOCTYPE")
message = "HTML content" if is_html else text
if message == "HTML content":
if response.status == 520:
message = "Unknown error (Cloudflare)"