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

XFEstudio/gpt4free

feat(g4f/Provider/AIChatFree.py): add AIChatFree provider

9ff38497
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

2 个文件 +77 -0
Modified docs/providers-and-models.md +1 -0
@@ -11,6 +11,7 @@
11 11 |Website|Provider|Text Model|Image Model|Vision Model|Stream|Status|Auth|
12 12 |--|--|--|--|--|--|--|--|
13 13 |[chat.ai365vip.com](https://chat.ai365vip.com)|`g4f.Provider.AI365VIP`|`gpt-3.5-turbo, gpt-4o`|❌|❌|?|![Cloudflare](https://img.shields.io/badge/Cloudflare-f48d37)|❌|
14 |[aichatfree.info](https://aichatfree.info)|`g4f.Provider.AIChatFree`|`gemini-pro`|❌|❌|✔|[Active](https://img.shields.io/badge/Active-brightgreen)|❌|
14 15 |[aichatonline.org](https://aichatonline.org)|`g4f.Provider.AiChatOnline`|`gpt-4o-mini`|❌|❌|?|![Cloudflare](https://img.shields.io/badge/Cloudflare-f48d37)|❌|
15 16 |[ai-chats.org](https://ai-chats.org)|`g4f.Provider.AiChats`|`gpt-4`|`dalle`|❌|?|![Captcha](https://img.shields.io/badge/Captcha-f48d37)|❌|
16 17 |[api.airforce](https://api.airforce)|`g4f.Provider.Airforce`|`llama-2-13b, llama-3-70b, llama-3-8b, llama-3.1-405b, llama-3.1-70b, llama-3.1-8b, mixtral-8x7b, mixtral-8x22b, mistral-7b, mixtral-8x7b-dpo, qwen-1.5-72b, qwen-1.5-110b, qwen-2-72b, gemma-2b, gemma-2b-9b, gemma-2b-27b, deepseek, yi-34b, wizardlm-2-8x22b, solar-10-7b, sh-n-7b, sparkdesk-v1.1,gpt-4o, gpt-4o-mini, gpt-3.5-turbo, gemini-flash, gemini-pro, dbrx-instruct`|`flux, flux-realism', flux-anime, flux-3d, flux-disney, flux-pixel, flux-4o, any-dark, dalle-3`|❌|✔|![Active](https://img.shields.io/badge/Active-brightgreen)|❌|
Added g4f/Provider/AIChatFree.py +76 -0
@@ -0,0 +1,76 @@
1 from __future__ import annotations
2
3 import time
4 from hashlib import sha256
5
6 from aiohttp import BaseConnector, ClientSession
7
8 from ..errors import RateLimitError
9 from ..requests import raise_for_status
10 from ..requests.aiohttp import get_connector
11 from ..typing import AsyncResult, Messages
12 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
13
14
15 class AIChatFree(AsyncGeneratorProvider, ProviderModelMixin):
16 url = "https://aichatfree.info/"
17 working = True
18 supports_stream = True
19 supports_message_history = True
20 default_model = 'gemini-pro'
21
22 @classmethod
23 async def create_async_generator(
24 cls,
25 model: str,
26 messages: Messages,
27 proxy: str = None,
28 connector: BaseConnector = None,
29 **kwargs,
30 ) -> AsyncResult:
31 headers = {
32 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0",
33 "Accept": "*/*",
34 "Accept-Language": "en-US,en;q=0.5",
35 "Accept-Encoding": "gzip, deflate, br",
36 "Content-Type": "text/plain;charset=UTF-8",
37 "Referer": f"{cls.url}/",
38 "Origin": cls.url,
39 "Sec-Fetch-Dest": "empty",
40 "Sec-Fetch-Mode": "cors",
41 "Sec-Fetch-Site": "same-origin",
42 "Connection": "keep-alive",
43 "TE": "trailers",
44 }
45 async with ClientSession(
46 connector=get_connector(connector, proxy), headers=headers
47 ) as session:
48 timestamp = int(time.time() * 1e3)
49 data = {
50 "messages": [
51 {
52 "role": "model" if message["role"] == "assistant" else "user",
53 "parts": [{"text": message["content"]}],
54 }
55 for message in messages
56 ],
57 "time": timestamp,
58 "pass": None,
59 "sign": generate_signature(timestamp, messages[-1]["content"]),
60 }
61 async with session.post(
62 f"{cls.url}/api/generate", json=data, proxy=proxy
63 ) as response:
64 if response.status == 500:
65 if "Quota exceeded" in await response.text():
66 raise RateLimitError(
67 f"Response {response.status}: Rate limit reached"
68 )
69 await raise_for_status(response)
70 async for chunk in response.content.iter_any():
71 yield chunk.decode(errors="ignore")
72
73
74 def generate_signature(time: int, text: str, secret: str = ""):
75 message = f"{time}:{text}:{secret}"
76 return sha256(message.encode()).hexdigest()