Update main.py
Browse files
main.py
CHANGED
@@ -106,7 +106,6 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
|
|
106 |
) -> Any:
|
107 |
model = cls.get_model(model)
|
108 |
|
109 |
-
# Check if the model is working
|
110 |
if not cls.working or model not in cls.models:
|
111 |
raise ModelNotWorkingException(model)
|
112 |
|
@@ -176,8 +175,8 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
|
|
176 |
async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
|
177 |
response.raise_for_status()
|
178 |
response_text = await response.text()
|
179 |
-
|
180 |
-
# Check if the response is empty
|
181 |
if not response_text.strip():
|
182 |
raise ModelNotWorkingException(model)
|
183 |
|
@@ -188,13 +187,15 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
|
|
188 |
yield ImageResponse(image_url, alt=messages[-1]['content'])
|
189 |
else:
|
190 |
raise Exception("Image URL not found in the response")
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
198 |
except ClientError as e:
|
199 |
logger.error(f"HTTP request failed: {e}")
|
200 |
raise HTTPException(status_code=503, detail="Service is unavailable. Please try again later.")
|
|
|
106 |
) -> Any:
|
107 |
model = cls.get_model(model)
|
108 |
|
|
|
109 |
if not cls.working or model not in cls.models:
|
110 |
raise ModelNotWorkingException(model)
|
111 |
|
|
|
175 |
async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
|
176 |
response.raise_for_status()
|
177 |
response_text = await response.text()
|
178 |
+
|
179 |
+
# Check if the response is empty or just whitespace
|
180 |
if not response_text.strip():
|
181 |
raise ModelNotWorkingException(model)
|
182 |
|
|
|
187 |
yield ImageResponse(image_url, alt=messages[-1]['content'])
|
188 |
else:
|
189 |
raise Exception("Image URL not found in the response")
|
190 |
+
|
191 |
+
# Handle normal responses
|
192 |
+
async for chunk in response.content.iter_any():
|
193 |
+
if chunk:
|
194 |
+
decoded_chunk = chunk.decode(errors='ignore')
|
195 |
+
decoded_chunk = re.sub(r'\$@\$v=[^$]+\$@\$', '', decoded_chunk)
|
196 |
+
if decoded_chunk.strip():
|
197 |
+
yield decoded_chunk
|
198 |
+
|
199 |
except ClientError as e:
|
200 |
logger.error(f"HTTP request failed: {e}")
|
201 |
raise HTTPException(status_code=503, detail="Service is unavailable. Please try again later.")
|