XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

8 providers improved

a338ed58
zukixa <56563509+zukixa@users.noreply.github.com>
提交于

代码差异

9 个文件 +53 -104
Modified g4f/Provider/Aura.py +2 -2
@@ -33,8 +33,8 @@ class Aura(AsyncGeneratorProvider):
33 33 new_messages.append(message)
34 34 data = {
35 35 "model": {
36 "id": "openchat_v3.2_mistral",
37 "name": "OpenChat Aura",
36 "id": "openchat_3.6",
37 "name": "OpenChat 3.6 (latest)",
38 38 "maxLength": 24576,
39 39 "tokenLimit": max_tokens
40 40 },
Modified g4f/Provider/Blackbox.py +1 -1
@@ -67,7 +67,7 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
67 67
68 68 async with session.post(
69 69 f"{cls.url}/api/chat", json=data, proxy=proxy
70 ) as response: # type: ClientResponse
70 ) as response:
71 71 response.raise_for_status()
72 72 async for chunk in response.content.iter_any():
73 73 if chunk:
Modified g4f/Provider/ChatgptFree.py +7 -2
@@ -1,6 +1,7 @@
1 1 from __future__ import annotations
2 2
3 3 import re
4 import json
4 5
5 6 from ..requests import StreamSession, raise_for_status
6 7 from ..typing import Messages
@@ -74,6 +75,10 @@ class ChatgptFree(AsyncProvider):
74 75 "message": prompt,
75 76 "bot_id": "0"
76 77 }
77 async with session.post(f"{cls.url}/wp-admin/admin-ajax.php", data=data, cookies=cookies) as response:
78 async with session.get(f"{cls.url}/wp-admin/admin-ajax.php", params=data, cookies=cookies) as response:
78 79 await raise_for_status(response)
79 return (await response.json())["data"]
80 full_answer = ""
81 for line in ((await response.text()).splitlines())[:-1]:
82 if line.startswith("data:") and "[DONE]" not in line:
83 full_answer += json.loads(line[5:])['choices'][0]['delta'].get('content', "")
84 return full_answer
Deleted g4f/Provider/Feedough.py +0 -78
@@ -1,78 +0,0 @@
1 from __future__ import annotations
2
3 import json
4 import asyncio
5 from aiohttp import ClientSession, TCPConnector
6 from urllib.parse import urlencode
7
8 from ..typing import AsyncResult, Messages
9 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
10 from .helper import format_prompt
11
12
13 class Feedough(AsyncGeneratorProvider, ProviderModelMixin):
14 url = "https://www.feedough.com"
15 api_endpoint = "/wp-admin/admin-ajax.php"
16 working = True
17 default_model = ''
18
19 @classmethod
20 async def create_async_generator(
21 cls,
22 model: str,
23 messages: Messages,
24 proxy: str = None,
25 **kwargs
26 ) -> AsyncResult:
27 headers = {
28 "accept": "*/*",
29 "accept-language": "en-US,en;q=0.9",
30 "content-type": "application/x-www-form-urlencoded;charset=UTF-8",
31 "dnt": "1",
32 "origin": cls.url,
33 "referer": f"{cls.url}/ai-prompt-generator/",
34 "sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126"',
35 "sec-ch-ua-mobile": "?0",
36 "sec-ch-ua-platform": '"Linux"',
37 "sec-fetch-dest": "empty",
38 "sec-fetch-mode": "cors",
39 "sec-fetch-site": "same-origin",
40 "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
41 }
42
43 connector = TCPConnector(ssl=False)
44
45 async with ClientSession(headers=headers, connector=connector) as session:
46 data = {
47 "action": "aixg_generate",
48 "prompt": format_prompt(messages),
49 "aixg_generate_nonce": "110c021031"
50 }
51
52 try:
53 async with session.post(
54 f"{cls.url}{cls.api_endpoint}",
55 data=urlencode(data),
56 proxy=proxy
57 ) as response:
58 response.raise_for_status()
59 response_text = await response.text()
60 try:
61 response_json = json.loads(response_text)
62 if response_json.get("success") and "data" in response_json:
63 message = response_json["data"].get("message", "")
64 yield message
65 except json.JSONDecodeError:
66 yield response_text
67 except Exception as e:
68 print(f"An error occurred: {e}")
69
70 @classmethod
71 async def run(cls, *args, **kwargs):
72 async for item in cls.create_async_generator(*args, **kwargs):
73 yield item
74
75 tasks = asyncio.all_tasks()
76 for task in tasks:
77 if not task.done():
78 await task
Modified g4f/Provider/LiteIcoding.py +15 -4
@@ -31,7 +31,7 @@ class LiteIcoding(AsyncGeneratorProvider, ProviderModelMixin):
31 31 headers = {
32 32 "Accept": "*/*",
33 33 "Accept-Language": "en-US,en;q=0.9",
34 "Authorization": "Bearer null",
34 "Authorization": "Bearer b3b2712cf83640a5acfdc01e78369930",
35 35 "Connection": "keep-alive",
36 36 "Content-Type": "application/json;charset=utf-8",
37 37 "DNT": "1",
@@ -74,6 +74,9 @@ class LiteIcoding(AsyncGeneratorProvider, ProviderModelMixin):
74 74 response.raise_for_status()
75 75 buffer = ""
76 76 full_response = ""
77 def decode_content(data):
78 bytes_array = bytes([int(b, 16) ^ 255 for b in data.split()])
79 return bytes_array.decode('utf-8')
77 80 async for chunk in response.content.iter_any():
78 81 if chunk:
79 82 buffer += chunk.decode()
@@ -83,9 +86,17 @@ class LiteIcoding(AsyncGeneratorProvider, ProviderModelMixin):
83 86 content = part[6:].strip()
84 87 if content and content != "[DONE]":
85 88 content = content.strip('"')
86 full_response += content
87
88 full_response = full_response.replace('" "', ' ')
89 # Decoding each content block
90 decoded_content = decode_content(content)
91 full_response += decoded_content
92 full_response = (
93 full_response.replace('""', '') # Handle double quotes
94 .replace('" "', ' ') # Handle space within quotes
95 .replace("\\n\\n", "\n\n")
96 .replace("\\n", "\n")
97 .replace('\\"', '"')
98 .strip()
99 )
89 100 yield full_response.strip()
90 101
91 102 except ClientResponseError as e:
Modified g4f/Provider/MagickPenAsk.py +1 -1
@@ -37,7 +37,7 @@ class MagickPenAsk(AsyncGeneratorProvider, ProviderModelMixin):
37 37 "sec-fetch-mode": "cors",
38 38 "sec-fetch-site": "same-site",
39 39 "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
40 'X-API-Secret': 'WCASR6ZQJYM85DVDX7'
40 'X-API-Secret': 'W252GY255JVYBS9NAM' # this for some reason is just hardcoded in the .js, it makes no sense
41 41 }
42 42 async with ClientSession(headers=headers) as session:
43 43 data = {
Modified g4f/Provider/MagickPenChat.py +2 -1
@@ -37,7 +37,8 @@ class MagickPenChat(AsyncGeneratorProvider, ProviderModelMixin):
37 37 "sec-fetch-dest": "empty",
38 38 "sec-fetch-mode": "cors",
39 39 "sec-fetch-site": "same-site",
40 "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
40 "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
41 'X-Api-Secret': 'W252GY255JVYBS9NAM'
41 42 }
42 43 async with ClientSession(headers=headers) as session:
43 44 data = {
Modified g4f/Provider/PerplexityLabs.py +1 -5
@@ -13,7 +13,7 @@ WS_URL = "wss://www.perplexity.ai/socket.io/"
13 13 class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
14 14 url = "https://labs.perplexity.ai"
15 15 working = True
16 default_model = "mixtral-8x7b-instruct"
16 default_model = "llama-3.1-8b-instruct"
17 17 models = [
18 18 "llama-3.1-sonar-large-128k-online",
19 19 "llama-3.1-sonar-small-128k-online",
@@ -21,10 +21,6 @@ class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
21 21 "llama-3.1-sonar-small-128k-chat",
22 22 "llama-3.1-8b-instruct",
23 23 "llama-3.1-70b-instruct",
24 "gemma-2-9b-it",
25 "gemma-2-27b-it",
26 "nemotron-4-340b-instruct",
27 "mixtral-8x7b-instruct"
28 24 ]
29 25
30 26 @classmethod
Modified g4f/Provider/Rocks.py +24 -10
@@ -1,14 +1,17 @@
1 import asyncio
1 2 import json
2 3 from aiohttp import ClientSession
3
4 4 from ..typing import Messages, AsyncResult
5 5 from .base_provider import AsyncGeneratorProvider
6 6
7 7 class Rocks(AsyncGeneratorProvider):
8 url = "https://api.discord.rocks"
8 url = "https://api.airforce"
9 9 api_endpoint = "/chat/completions"
10 supports_message_history = False
10 supports_message_history = True
11 11 supports_gpt_35_turbo = True
12 supports_gpt_4 = True
13 supports_stream = True
14 supports_system_message = True
12 15 working = True
13 16
14 17 @classmethod
@@ -25,12 +28,13 @@ class Rocks(AsyncGeneratorProvider):
25 28 "Accept": "application/json",
26 29 "Accept-Encoding": "gzip, deflate, br, zstd",
27 30 "Accept-Language": "en-US,en;q=0.9",
28 "Origin": cls.url,
29 "Referer": f"{cls.url}/en",
31 "Authorization": "Bearer missing api key",
32 "Origin": "https://llmplayground.net",
33 "Referer": "https://llmplayground.net/",
30 34 "Sec-Fetch-Dest": "empty",
31 35 "Sec-Fetch-Mode": "cors",
32 36 "Sec-Fetch-Site": "same-origin",
33 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
37 "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
34 38 }
35 39
36 40 async with ClientSession() as session:
@@ -41,16 +45,26 @@ class Rocks(AsyncGeneratorProvider):
41 45 headers=headers
42 46 ) as response:
43 47 response.raise_for_status()
48 last_chunk_time = asyncio.get_event_loop().time()
49
44 50 async for line in response.content:
45 if line.startswith(b"data: "):
51 current_time = asyncio.get_event_loop().time()
52 if current_time - last_chunk_time > 5:
53 return
54
55 if line.startswith(b"\n"):
56 pass
57 elif "discord.com/invite/" in line.decode() or "discord.gg/" in line.decode():
58 pass # trolled
59 elif line.startswith(b"data: "):
46 60 try:
47 61 line = json.loads(line[6:])
48 except:
62 except json.JSONDecodeError:
49 63 continue
50 64 chunk = line["choices"][0]["delta"].get("content")
51 65 if chunk:
52 66 yield chunk
53 elif line.startswith(b"\n"):
54 pass
67 last_chunk_time = current_time
55 68 else:
56 69 raise Exception(f"Unexpected line: {line}")
70 return