summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/LiteIcoding.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2024-08-01 21:10:29 +0200
committerGitHub <noreply@github.com>2024-08-01 21:10:29 +0200
commit36e6306bd0fea03c9d1ec341ad1949b6b825d571 (patch)
tree203d4138d994e03f0e9954cb74d52d70963c4904 /g4f/Provider/LiteIcoding.py
parentMerge pull request #2106 from zachey01/main (diff)
parentAdded new providers TeachAnything MagickPenAsk MagickPenChat (diff)
downloadgpt4free-36e6306bd0fea03c9d1ec341ad1949b6b825d571.tar
gpt4free-36e6306bd0fea03c9d1ec341ad1949b6b825d571.tar.gz
gpt4free-36e6306bd0fea03c9d1ec341ad1949b6b825d571.tar.bz2
gpt4free-36e6306bd0fea03c9d1ec341ad1949b6b825d571.tar.lz
gpt4free-36e6306bd0fea03c9d1ec341ad1949b6b825d571.tar.xz
gpt4free-36e6306bd0fea03c9d1ec341ad1949b6b825d571.tar.zst
gpt4free-36e6306bd0fea03c9d1ec341ad1949b6b825d571.zip
Diffstat (limited to 'g4f/Provider/LiteIcoding.py')
-rw-r--r--g4f/Provider/LiteIcoding.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/g4f/Provider/LiteIcoding.py b/g4f/Provider/LiteIcoding.py
new file mode 100644
index 00000000..6aa407ca
--- /dev/null
+++ b/g4f/Provider/LiteIcoding.py
@@ -0,0 +1,97 @@
+from __future__ import annotations
+
+from aiohttp import ClientSession, ClientResponseError
+from ..typing import AsyncResult, Messages
+from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
+from .helper import format_prompt
+
+
+class LiteIcoding(AsyncGeneratorProvider, ProviderModelMixin):
+ url = "https://lite.icoding.ink"
+ api_endpoint = "/api/v1/gpt/message"
+ working = True
+ supports_gpt_4 = True
+ default_model = "gpt-4o"
+ models = [
+ 'gpt-4o',
+ 'gpt-4-turbo',
+ 'claude-3',
+ 'claude-3.5',
+ 'gemini-1.5',
+ ]
+
+ @classmethod
+ async def create_async_generator(
+ cls,
+ model: str,
+ messages: Messages,
+ proxy: str = None,
+ **kwargs
+ ) -> AsyncResult:
+ headers = {
+ "Accept": "*/*",
+ "Accept-Language": "en-US,en;q=0.9",
+ "Authorization": "Bearer null",
+ "Connection": "keep-alive",
+ "Content-Type": "application/json;charset=utf-8",
+ "DNT": "1",
+ "Origin": cls.url,
+ "Referer": f"{cls.url}/",
+ "Sec-Fetch-Dest": "empty",
+ "Sec-Fetch-Mode": "cors",
+ "Sec-Fetch-Site": "same-origin",
+ "User-Agent": (
+ "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) "
+ "Chrome/126.0.0.0 Safari/537.36"
+ ),
+ "sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126"',
+ "sec-ch-ua-mobile": "?0",
+ "sec-ch-ua-platform": '"Linux"',
+ }
+
+ data = {
+ "model": model,
+ "chatId": "-1",
+ "messages": [
+ {
+ "role": msg["role"],
+ "content": msg["content"],
+ "time": msg.get("time", ""),
+ "attachments": msg.get("attachments", []),
+ }
+ for msg in messages
+ ],
+ "plugins": [],
+ "systemPrompt": "",
+ "temperature": 0.5,
+ }
+
+ async with ClientSession(headers=headers) as session:
+ try:
+ async with session.post(
+ f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy
+ ) as response:
+ response.raise_for_status()
+ buffer = ""
+ full_response = ""
+ async for chunk in response.content.iter_any():
+ if chunk:
+ buffer += chunk.decode()
+ while "\n\n" in buffer:
+ part, buffer = buffer.split("\n\n", 1)
+ if part.startswith("data: "):
+ content = part[6:].strip()
+ if content and content != "[DONE]":
+ content = content.strip('"')
+ full_response += content
+
+ full_response = full_response.replace('" "', ' ')
+ yield full_response.strip()
+
+ except ClientResponseError as e:
+ raise RuntimeError(
+ f"ClientResponseError {e.status}: {e.message}, url={e.request_info.url}, data={data}"
+ ) from e
+
+ except Exception as e:
+ raise RuntimeError(f"Unexpected error: {str(e)}") from e