diff options
author | zukixa <56563509+zukixa@users.noreply.github.com> | 2024-08-25 10:00:06 +0200 |
---|---|---|
committer | zukixa <56563509+zukixa@users.noreply.github.com> | 2024-08-25 10:00:06 +0200 |
commit | a338ed588397737d3c1be66ee4f15d51c84f1770 (patch) | |
tree | 0de45ef57733bfb8c3c38e74dddabeb697ee445a /g4f/Provider/Rocks.py | |
parent | . (diff) | |
download | gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.gz gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.bz2 gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.lz gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.xz gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.tar.zst gpt4free-a338ed588397737d3c1be66ee4f15d51c84f1770.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/Rocks.py | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/g4f/Provider/Rocks.py b/g4f/Provider/Rocks.py index 8465a6c0..f44e0060 100644 --- a/g4f/Provider/Rocks.py +++ b/g4f/Provider/Rocks.py @@ -1,14 +1,17 @@ +import asyncio import json from aiohttp import ClientSession - from ..typing import Messages, AsyncResult from .base_provider import AsyncGeneratorProvider class Rocks(AsyncGeneratorProvider): - url = "https://api.discord.rocks" + url = "https://api.airforce" api_endpoint = "/chat/completions" - supports_message_history = False + supports_message_history = True supports_gpt_35_turbo = True + supports_gpt_4 = True + supports_stream = True + supports_system_message = True working = True @classmethod @@ -25,12 +28,13 @@ class Rocks(AsyncGeneratorProvider): "Accept": "application/json", "Accept-Encoding": "gzip, deflate, br, zstd", "Accept-Language": "en-US,en;q=0.9", - "Origin": cls.url, - "Referer": f"{cls.url}/en", + "Authorization": "Bearer missing api key", + "Origin": "https://llmplayground.net", + "Referer": "https://llmplayground.net/", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", - "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", + "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", } async with ClientSession() as session: @@ -41,16 +45,26 @@ class Rocks(AsyncGeneratorProvider): headers=headers ) as response: response.raise_for_status() + last_chunk_time = asyncio.get_event_loop().time() + async for line in response.content: - if line.startswith(b"data: "): + current_time = asyncio.get_event_loop().time() + if current_time - last_chunk_time > 5: + return + + if line.startswith(b"\n"): + pass + elif "discord.com/invite/" in line.decode() or "discord.gg/" in line.decode(): + pass # trolled + elif line.startswith(b"data: "): try: line = json.loads(line[6:]) - except: + except json.JSONDecodeError: continue chunk = line["choices"][0]["delta"].get("content") if chunk: yield chunk - elif line.startswith(b"\n"): - pass + last_chunk_time = current_time else: raise Exception(f"Unexpected line: {line}") + return
\ No newline at end of file |