Your task is to review pull requests. Instructions:
- Provide the response in following JSON format: {"reviews": [{"line": <line_number>, "body": "<review comment>"}]}
- Do not give positive comments or compliments.
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
- Write the comment in GitHub Markdown format.
- Use the given description only for the overall context and only comment the code.
- IMPORTANT: NEVER suggest adding comments to the code.

Review the following code diff in the file "g4f/Provider/AIUncensored.py" and take the pull request title and description into account when writing the response.
  
Pull request title: [pull] main from xtekky:main
Pull request description:
---
See [Commits](/specialized806/gpt4free/pull/107/commits) and [Changes](/specialized806/gpt4free/pull/107/files) for more details.

-----
Created by [<img src="https://prod.download/pull-18h-svg" valign="bottom"/> **pull[bot]**](https://github.com/wei/pull)

_Can you help keep this open source service alive? **[💖 Please sponsor : )](https://prod.download/pull-pr-sponsor)**_
---

Each line is prefixed by its number. Code to review:
```
1: from __future__ import annotations
2: 
3: import json
-from aiohttp import ClientSession
4:+import random
5:+from aiohttp import ClientSession, ClientError
6:+import asyncio
7:+from itertools import cycle
8: 
9: from ..typing import AsyncResult, Messages
10: from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
-from .helper import format_prompt
11: from ..image import ImageResponse
12: 
13: class AIUncensored(AsyncGeneratorProvider, ProviderModelMixin):
-    url = "https://www.aiuncensored.info"
14:+    url = "https://www.aiuncensored.info/ai_uncensored"
15:+    api_endpoints_text = [
16:+        "https://twitterclone-i0wr.onrender.com/api/chat",
17:+        "https://twitterclone-4e8t.onrender.com/api/chat",
18:+        "https://twitterclone-8wd1.onrender.com/api/chat",
19:+    ]
20:+    api_endpoints_image = [
21:+        "https://twitterclone-4e8t.onrender.com/api/image",
22:+        "https://twitterclone-i0wr.onrender.com/api/image",
23:+        "https://twitterclone-8wd1.onrender.com/api/image",
24:+    ]
25:     working = True
26:     supports_stream = True
27:     supports_system_message = True
28:     supports_message_history = True
29:     
-    default_model = 'ai_uncensored'
-    chat_models = [default_model]
-    image_models = ['ImageGenerator']
-    models = [*chat_models, *image_models]
-
-    api_endpoints = {
-        'ai_uncensored': "https://twitterclone-i0wr.onrender.com/api/chat",
-        'ImageGenerator': "https://twitterclone-4e8t.onrender.com/api/image"
30:+    default_model = 'TextGenerations'
31:+    text_models = [default_model]
32:+    image_models = ['ImageGenerations']
33:+    models = [*text_models, *image_models]
34:+    
35:+    model_aliases = {
36:+        "flux": "ImageGenerations",
37:     }
38: 
39:+    @staticmethod
40:+    def generate_cipher() -> str:
41:+        """Generate a cipher in format like '3221229284179118'"""
42:+        return ''.join([str(random.randint(0, 9)) for _ in range(16)])
43:+
44:     @classmethod
45:     def get_model(cls, model: str) -> str:
46:         if model in cls.models:
47:             return model
48:+        elif model in cls.model_aliases:
49:+            return cls.model_aliases[model]
50:         else:
51:             return cls.default_model
52: 
56:         model: str,
57:         messages: Messages,
58:         proxy: str = None,
-        stream: bool = False,
59:         **kwargs
60:     ) -> AsyncResult:
61:         model = cls.get_model(model)
62:         
-        if model in cls.chat_models:
-            async with ClientSession(headers={"content-type": "application/json"}) as session:
63:+        headers = {
64:+            'accept': '*/*',
65:+            'accept-language': 'en-US,en;q=0.9',
66:+            'cache-control': 'no-cache',
67:+            'content-type': 'application/json',
68:+            'origin': 'https://www.aiuncensored.info',
69:+            'pragma': 'no-cache',
70:+            'priority': 'u=1, i',
71:+            'referer': 'https://www.aiuncensored.info/',
72:+            'sec-ch-ua': '"Not?A_Brand";v="99", "Chromium";v="130"',
73:+            'sec-ch-ua-mobile': '?0',
74:+            'sec-ch-ua-platform': '"Linux"',
75:+            'sec-fetch-dest': 'empty',
76:+            'sec-fetch-mode': 'cors',
77:+            'sec-fetch-site': 'cross-site',
78:+            'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'
79:+        }
80:+        
81:+        async with ClientSession(headers=headers) as session:
82:+            if model in cls.image_models:
83:+                prompt = messages[-1]['content']
84:                 data = {
-                    "messages": [
-                        {"role": "user", "content": format_prompt(messages)}
-                    ],
-                    "stream": stream
85:+                    "prompt": prompt,
86:+                    "cipher": cls.generate_cipher()
87:                 }
-                async with session.post(cls.api_endpoints[model], json=data, proxy=proxy) as response:
-                    response.raise_for_status()
-                    if stream:
-                        async for chunk in cls._handle_streaming_response(response):
-                            yield chunk
-                    else:
-                        yield await cls._handle_non_streaming_response(response)
-        elif model in cls.image_models:
-            headers = {
-                "accept": "*/*",
-                "accept-language": "en-US,en;q=0.9",
-                "cache-control": "no-cache",
-                "content-type": "application/json",
-                "origin": cls.url,
-                "pragma": "no-cache",
-                "priority": "u=1, i",
-                "referer": f"{cls.url}/",
-                "sec-ch-ua": '"Chromium";v="129", "Not=A?Brand";v="8"',
-                "sec-ch-ua-mobile": "?0",
-                "sec-ch-ua-platform": '"Linux"',
-                "sec-fetch-dest": "empty",
-                "sec-fetch-mode": "cors",
-                "sec-fetch-site": "cross-site",
-                "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
-            }
-            async with ClientSession(headers=headers) as session:
-                prompt = messages[0]['content']
-                data = {"prompt": prompt}
-                async with session.post(cls.api_endpoints[model], json=data, proxy=proxy) as response:
-                    response.raise_for_status()
-                    result = await response.json()
-                    image_url = result.get('image_url', '')
-                    if image_url:
-                        yield ImageResponse(image_url, alt=prompt)
-                    else:
-                        yield "Failed to generate image. Please try again."
-
-    @classmethod
-    async def _handle_streaming_response(cls, response):
-        async for line in response.content:
-            line = line.decode('utf-8').strip()
-            if line.startswith("data: "):
-                if line == "data: [DONE]":
-                    break
-                try:
-                    json_data = json.loads(line[6:])
-                    if 'data' in json_data:
-                        yield json_data['data']
-                except json.JSONDecodeError:
-                    pass
88:+                
89:+                endpoints = cycle(cls.api_endpoints_image)
90:+                
91:+                while True:
92:+                    endpoint = next(endpoints)
93:+                    try:
94:+                        async with session.post(endpoint, json=data, proxy=proxy, timeout=10) as response:
95:+                            response.raise_for_status()
96:+                            response_data = await response.json()
97:+                            image_url = response_data['image_url']
98:+                            image_response = ImageResponse(images=image_url, alt=prompt)
99:+                            yield image_response
100:+                            return
101:+                    except (ClientError, asyncio.TimeoutError):
102:+                        continue
103: 
-    @classmethod
-    async def _handle_non_streaming_response(cls, response):
-        response_json = await response.json()
-        return response_json.get('content', "Sorry, I couldn't generate a response.")
-
-    @classmethod
-    def validate_response(cls, response: str) -> str:
-        return response
104:+            elif model in cls.text_models:
105:+                data = {
106:+                    "messages": messages,
107:+                    "cipher": cls.generate_cipher()
108:+                }
109:+                
110:+                endpoints = cycle(cls.api_endpoints_text)
111:+                
112:+                while True:
113:+                    endpoint = next(endpoints)
114:+                    try:
115:+                        async with session.post(endpoint, json=data, proxy=proxy, timeout=10) as response:
116:+                            response.raise_for_status()
117:+                            full_response = ""
118:+                            async for line in response.content:
119:+                                line = line.decode('utf-8')
120:+                                if line.startswith("data: "):
121:+                                    try:
122:+                                        json_str = line[6:]
123:+                                        if json_str != "[DONE]":
124:+                                            data = json.loads(json_str)
125:+                                            if "data" in data:
126:+                                                full_response += data["data"]
127:+                                                yield data["data"]
128:+                                    except json.JSONDecodeError:
129:+                                        continue
130:+                            return
131:+                    except (ClientError, asyncio.TimeoutError):
132:+                        continue
```