summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Ecosia.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-18 21:13:26 +0200
committerGitHub <noreply@github.com>2024-04-18 21:13:26 +0200
commit718ea7c187b0852aacc18bf890fcc105dfff2665 (patch)
tree84f59d4ea5a679382df3f71ff3de027aad2a8fd4 /g4f/Provider/Ecosia.py
parentMerge pull request #1848 from hlohaus/nem (diff)
parentAdd Ecosia Provider, Add OpenaiAccount alias (diff)
downloadgpt4free-718ea7c187b0852aacc18bf890fcc105dfff2665.tar
gpt4free-718ea7c187b0852aacc18bf890fcc105dfff2665.tar.gz
gpt4free-718ea7c187b0852aacc18bf890fcc105dfff2665.tar.bz2
gpt4free-718ea7c187b0852aacc18bf890fcc105dfff2665.tar.lz
gpt4free-718ea7c187b0852aacc18bf890fcc105dfff2665.tar.xz
gpt4free-718ea7c187b0852aacc18bf890fcc105dfff2665.tar.zst
gpt4free-718ea7c187b0852aacc18bf890fcc105dfff2665.zip
Diffstat (limited to 'g4f/Provider/Ecosia.py')
-rw-r--r--g4f/Provider/Ecosia.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/g4f/Provider/Ecosia.py b/g4f/Provider/Ecosia.py
new file mode 100644
index 00000000..1cae3560
--- /dev/null
+++ b/g4f/Provider/Ecosia.py
@@ -0,0 +1,47 @@
+
+from __future__ import annotations
+
+import base64
+import json
+from aiohttp import ClientSession, BaseConnector
+
+from ..typing import AsyncResult, Messages
+from ..requests.raise_for_status import raise_for_status
+from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
+from .helper import get_connector
+
+class Ecosia(AsyncGeneratorProvider, ProviderModelMixin):
+ url = "https://www.ecosia.org"
+ working = True
+ supports_gpt_35_turbo = True
+ default_model = "gpt-3.5-turbo-0125"
+ model_aliases = {"gpt-3.5-turbo": "gpt-3.5-turbo-0125"}
+
+ @classmethod
+ async def create_async_generator(
+ cls,
+ model: str,
+ messages: Messages,
+ connector: BaseConnector = None,
+ green: bool = False,
+ proxy: str = None,
+ **kwargs
+ ) -> AsyncResult:
+ cls.get_model(model)
+ headers = {
+ "authority": "api.ecosia.org",
+ "accept": "*/*",
+ "origin": cls.url,
+ "referer": f"{cls.url}/",
+ "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36",
+ }
+ async with ClientSession(headers=headers, connector=get_connector(connector, proxy)) as session:
+ data = {
+ "messages": base64.b64encode(json.dumps(messages).encode()).decode()
+ }
+ api_url = f"https://api.ecosia.org/v2/chat/?sp={'eco' if green else 'productivity'}"
+ async with session.post(api_url, json=data) as response:
+ await raise_for_status(response)
+ async for chunk in response.content.iter_any():
+ if chunk:
+ yield chunk.decode(errors="ignore") \ No newline at end of file