返回提交历史
Renamed
g4f/Provider/HuggingChat.py
+3
-3
Modified
g4f/Provider/__init__.py
+1
-8
Modified
g4f/Provider/bing/create_images.py
+25
-38
Renamed
g4f/Provider/deprecated/Aichat.py
+4
-6
Renamed
g4f/Provider/deprecated/Berlin.py
+3
-3
Renamed
g4f/Provider/deprecated/Opchatgpts.py
+3
-3
Renamed
g4f/Provider/deprecated/Yqcloud.py
+3
-3
Modified
g4f/Provider/deprecated/__init__.py
+5
-1
Modified
g4f/Provider/needs_auth/__init__.py
+0
-1
Renamed
g4f/Provider/selenium/AItianhuSpace.py
+5
-5
Renamed
g4f/Provider/selenium/MyShell.py
+4
-4
Renamed
g4f/Provider/selenium/PerplexityAi.py
+4
-4
Renamed
g4f/Provider/selenium/TalkAi.py
+3
-3
Modified
g4f/Provider/selenium/__init__.py
+5
-1
XFEstudio/gpt4free
Improve CreateImagesBing Sort providers by category
38dbe4b8
代码差异
14 个文件
+68
-83
@@ -4,9 +4,9 @@ import json, uuid
4
4
5
5
from aiohttp import ClientSession
6
6
7
from ...typing import AsyncResult, Messages
8
from ..base_provider import AsyncGeneratorProvider
9
from ..helper import format_prompt, get_cookies
7
from ..typing import AsyncResult, Messages
8
from .base_provider import AsyncGeneratorProvider
9
from .helper import format_prompt, get_cookies
10
10
11
11
map = {
12
12
"openchat/openchat_3.5": "openchat/openchat-3.5-1210",
@@ -11,11 +11,8 @@ from .selenium import *
11
11
12
12
from .Aura import Aura
13
13
from .AiAsk import AiAsk
14
from .Aichat import Aichat
15
14
from .AiChatOnline import AiChatOnline
16
15
from .AItianhu import AItianhu
17
from .AItianhuSpace import AItianhuSpace
18
from .Berlin import Berlin
19
16
from .Bing import Bing
20
17
from .ChatAnywhere import ChatAnywhere
21
18
from .ChatBase import ChatBase
@@ -43,20 +40,16 @@ from .GptGo import GptGo
43
40
from .GptGod import GptGod
44
41
from .GptTalkRu import GptTalkRu
45
42
from .Hashnode import Hashnode
43
from .HuggingChat import HuggingChat
46
44
from .Koala import Koala
47
45
from .Liaobots import Liaobots
48
46
from .Llama2 import Llama2
49
from .MyShell import MyShell
50
47
from .OnlineGpt import OnlineGpt
51
from .Opchatgpts import Opchatgpts
52
from .PerplexityAi import PerplexityAi
53
48
from .Phind import Phind
54
49
from .Pi import Pi
55
from .TalkAi import TalkAi
56
50
from .Vercel import Vercel
57
51
from .Ylokh import Ylokh
58
52
from .You import You
59
from .Yqcloud import Yqcloud
60
53
from .Bestim import Bestim
61
54
62
55
import sys
@@ -13,10 +13,10 @@ from urllib.parse import quote
13
13
from typing import Generator, List, Dict
14
14
15
15
from ..create_images import CreateImagesProvider
16
from ..helper import get_cookies, get_event_loop
16
from ..helper import get_cookies
17
17
from ...webdriver import WebDriver, get_driver_cookies, get_browser
18
18
from ...base_provider import ProviderType
19
from ...image import format_images_markdown
19
from ...image import ImageResponse
20
20
21
21
BING_URL = "https://www.bing.com"
22
22
TIMEOUT_LOGIN = 1200
@@ -161,23 +161,7 @@ def read_images(html_content: str) -> List[str]:
161
161
raise RuntimeError("No images found")
162
162
return images
163
163
164
async def create_images_markdown(cookies: Dict[str, str], prompt: str, proxy: str = None) -> str:
165
"""
166
Creates markdown formatted string with images based on the prompt.
167
168
Args:
169
cookies (Dict[str, str]): Cookies to be used for the session.
170
prompt (str): Prompt to generate images.
171
proxy (str, optional): Proxy configuration.
172
173
Returns:
174
str: Markdown formatted string with images.
175
"""
176
async with create_session(cookies) as session:
177
images = await create_images(session, prompt, proxy)
178
return format_images_markdown(images, prompt)
179
180
def get_cookies_from_browser(proxy: str = None) -> Dict[str, str]:
164
def get_cookies_from_browser(proxy: str = None) -> dict[str, str]:
181
165
"""
182
166
Retrieves cookies from the browser using webdriver.
183
167
@@ -185,7 +169,7 @@ def get_cookies_from_browser(proxy: str = None) -> Dict[str, str]:
185
169
proxy (str, optional): Proxy configuration.
186
170
187
171
Returns:
188
Dict[str, str]: Retrieved cookies.
172
dict[str, str]: Retrieved cookies.
189
173
"""
190
174
with get_browser(proxy=proxy) as driver:
191
175
wait_for_login(driver)
@@ -194,48 +178,47 @@ def get_cookies_from_browser(proxy: str = None) -> Dict[str, str]:
194
178
195
179
class CreateImagesBing:
196
180
"""A class for creating images using Bing."""
197
198
_cookies: Dict[str, str] = {}
199
181
200
@classmethod
201
def create_completion(cls, prompt: str, cookies: Dict[str, str] = None, proxy: str = None) -> Generator[str, None, None]:
182
def __init__(self, cookies: dict[str, str] = {}, proxy: str = None) -> None:
183
self.cookies = cookies
184
self.proxy = proxy
185
186
def create_completion(self, prompt: str) -> Generator[ImageResponse, None, None]:
202
187
"""
203
188
Generator for creating imagecompletion based on a prompt.
204
189
205
190
Args:
206
191
prompt (str): Prompt to generate images.
207
cookies (Dict[str, str], optional): Cookies for the session. If None, cookies are retrieved automatically.
208
proxy (str, optional): Proxy configuration.
209
192
210
193
Yields:
211
194
Generator[str, None, None]: The final output as markdown formatted string with images.
212
195
"""
213
loop = get_event_loop()
214
cookies = cookies or cls._cookies or get_cookies(".bing.com")
196
cookies = self.cookies or get_cookies(".bing.com")
215
197
if "_U" not in cookies:
216
198
login_url = os.environ.get("G4F_LOGIN_URL")
217
199
if login_url:
218
200
yield f"Please login: [Bing]({login_url})\n\n"
219
cls._cookies = cookies = get_cookies_from_browser(proxy)
220
yield loop.run_until_complete(create_images_markdown(cookies, prompt, proxy))
201
self.cookies = get_cookies_from_browser(self.proxy)
202
yield asyncio.run(self.create_async(prompt))
221
203
222
@classmethod
223
async def create_async(cls, prompt: str, cookies: Dict[str, str] = None, proxy: str = None) -> str:
204
async def create_async(self, prompt: str) -> ImageResponse:
224
205
"""
225
206
Asynchronously creates a markdown formatted string with images based on the prompt.
226
207
227
208
Args:
228
209
prompt (str): Prompt to generate images.
229
cookies (Dict[str, str], optional): Cookies for the session. If None, cookies are retrieved automatically.
230
proxy (str, optional): Proxy configuration.
231
210
232
211
Returns:
233
212
str: Markdown formatted string with images.
234
213
"""
235
cookies = cookies or cls._cookies or get_cookies(".bing.com")
214
cookies = self.cookies or get_cookies(".bing.com")
236
215
if "_U" not in cookies:
237
cls._cookies = cookies = get_cookies_from_browser(proxy)
238
return await create_images_markdown(cookies, prompt, proxy)
216
raise RuntimeError('"_U" cookie is missing')
217
async with create_session(cookies) as session:
218
images = await create_images(session, prompt, self.proxy)
219
return ImageResponse(images, prompt)
220
221
service = CreateImagesBing()
239
222
240
223
def patch_provider(provider: ProviderType) -> CreateImagesProvider:
241
224
"""
@@ -247,4 +230,8 @@ def patch_provider(provider: ProviderType) -> CreateImagesProvider:
247
230
Returns:
248
231
CreateImagesProvider: The patched provider with image creation capabilities.
249
232
"""
250
return CreateImagesProvider(provider, CreateImagesBing.create_completion, CreateImagesBing.create_async)
233
return CreateImagesProvider(
234
provider,
235
service.create_completion,
236
service.create_async
237
)
@@ -1,11 +1,9 @@
1
1
from __future__ import annotations
2
2
3
from aiohttp import ClientSession
4
5
from ..typing import Messages
6
from .base_provider import AsyncProvider, format_prompt
7
from .helper import get_cookies
8
from ..requests import StreamSession
3
from ...typing import Messages
4
from ..base_provider import AsyncProvider, format_prompt
5
from ..helper import get_cookies
6
from ...requests import StreamSession
9
7
10
8
class Aichat(AsyncProvider):
11
9
url = "https://chat-gpt.org/chat"
@@ -5,9 +5,9 @@ import uuid
5
5
import json
6
6
from aiohttp import ClientSession
7
7
8
from ..typing import AsyncResult, Messages
9
from .base_provider import AsyncGeneratorProvider
10
from .helper import format_prompt
8
from ...typing import AsyncResult, Messages
9
from ..base_provider import AsyncGeneratorProvider
10
from ..helper import format_prompt
11
11
12
12
13
13
class Berlin(AsyncGeneratorProvider):
@@ -3,9 +3,9 @@ from __future__ import annotations
3
3
import random, string, json
4
4
from aiohttp import ClientSession
5
5
6
from ..typing import Messages, AsyncResult
7
from .base_provider import AsyncGeneratorProvider
8
from .helper import get_random_string
6
from ...typing import Messages, AsyncResult
7
from ..base_provider import AsyncGeneratorProvider
8
from ..helper import get_random_string
9
9
10
10
class Opchatgpts(AsyncGeneratorProvider):
11
11
url = "https://opchatgpts.net"
@@ -1,10 +1,10 @@
1
1
from __future__ import annotations
2
2
3
3
import random
4
from ..requests import StreamSession
4
from ...requests import StreamSession
5
5
6
from ..typing import AsyncResult, Messages
7
from .base_provider import AsyncGeneratorProvider, format_prompt
6
from ...typing import AsyncResult, Messages
7
from ..base_provider import AsyncGeneratorProvider, format_prompt
8
8
9
9
10
10
class Yqcloud(AsyncGeneratorProvider):
@@ -18,4 +18,8 @@ from .Acytoo import Acytoo
18
18
from .Aibn import Aibn
19
19
from .Ails import Ails
20
20
from .ChatgptDuo import ChatgptDuo
21
from .Cromicle import Cromicle
21
from .Cromicle import Cromicle
22
from .Opchatgpts import Opchatgpts
23
from .Yqcloud import Yqcloud
24
from .Aichat import Aichat
25
from .Berlin import Berlin
@@ -2,7 +2,6 @@ from .Bard import Bard
2
2
from .Raycast import Raycast
3
3
from .Theb import Theb
4
4
from .ThebApi import ThebApi
5
from .HuggingChat import HuggingChat
6
5
from .OpenaiChat import OpenaiChat
7
6
from .OpenAssistant import OpenAssistant
8
7
from .Poe import Poe
@@ -3,11 +3,11 @@ from __future__ import annotations
3
3
import time
4
4
import random
5
5
6
from ..typing import CreateResult, Messages
7
from .base_provider import AbstractProvider
8
from .helper import format_prompt, get_random_string
9
from ..webdriver import WebDriver, WebDriverSession
10
from .. import debug
6
from ...typing import CreateResult, Messages
7
from ..base_provider import AbstractProvider
8
from ..helper import format_prompt, get_random_string
9
from ...webdriver import WebDriver, WebDriverSession
10
from ... import debug
11
11
12
12
class AItianhuSpace(AbstractProvider):
13
13
url = "https://chat3.aiyunos.top/"
@@ -2,10 +2,10 @@ from __future__ import annotations
2
2
3
3
import time, json
4
4
5
from ..typing import CreateResult, Messages
6
from .base_provider import AbstractProvider
7
from .helper import format_prompt
8
from ..webdriver import WebDriver, WebDriverSession, bypass_cloudflare
5
from ...typing import CreateResult, Messages
6
from ..base_provider import AbstractProvider
7
from ..helper import format_prompt
8
from ...webdriver import WebDriver, WebDriverSession, bypass_cloudflare
9
9
10
10
class MyShell(AbstractProvider):
11
11
url = "https://app.myshell.ai/chat"
@@ -6,10 +6,10 @@ from selenium.webdriver.support.ui import WebDriverWait
6
6
from selenium.webdriver.support import expected_conditions as EC
7
7
from selenium.webdriver.common.keys import Keys
8
8
9
from ..typing import CreateResult, Messages
10
from .base_provider import AbstractProvider
11
from .helper import format_prompt
12
from ..webdriver import WebDriver, WebDriverSession
9
from ...typing import CreateResult, Messages
10
from ..base_provider import AbstractProvider
11
from ..helper import format_prompt
12
from ...webdriver import WebDriver, WebDriverSession
13
13
14
14
class PerplexityAi(AbstractProvider):
15
15
url = "https://www.perplexity.ai"