mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-15 14:51:19 -08:00
Add langchain integration
This commit is contained in:
parent
65265f3e51
commit
4e12f048b1
11 changed files with 133 additions and 88 deletions
|
|
@ -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)"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue