summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--g4f/Provider/FreeChatgpt.py77
-rw-r--r--g4f/models.py20
2 files changed, 50 insertions, 47 deletions
diff --git a/g4f/Provider/FreeChatgpt.py b/g4f/Provider/FreeChatgpt.py
index 05a0016e..82fc3ef4 100644
--- a/g4f/Provider/FreeChatgpt.py
+++ b/g4f/Provider/FreeChatgpt.py
@@ -7,6 +7,15 @@ from ..typing import AsyncResult, Messages
from .base_provider import AsyncGeneratorProvider
+
+models = {
+ "claude-v1":"claude-2.1",
+ "claude-v2":"claude-2.0",
+ "gpt_35_turbo":"gpt-3.5-turbo-1106",
+ "gpt-4":"gpt-4",
+ "gemini-pro":"google-gemini-pro"
+}
+
class FreeChatgpt(AsyncGeneratorProvider):
url = "https://free.chatgpt.org.uk"
working = True
@@ -22,47 +31,31 @@ class FreeChatgpt(AsyncGeneratorProvider):
proxy: str = None,
**kwargs
) -> AsyncResult:
- if not model:
- model = "gpt-3.5-turbo"
+ model = models[model] if model in models else "gpt-3.5-turbo-1106"
headers = {
- "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0",
- "Accept": "application/json, text/event-stream",
- "Accept-Language": "de,en-US;q=0.7,en;q=0.3",
- "Accept-Encoding": "gzip, deflate, br",
- "Content-Type": "application/json",
- "Referer": "https://free.chatgpt.org.uk/",
- "x-requested-with": "XMLHttpRequest",
- "Origin": "https://free.chatgpt.org.uk",
- "Sec-Fetch-Dest": "empty",
- "Sec-Fetch-Mode": "cors",
- "Sec-Fetch-Site": "same-origin",
- "Connection": "keep-alive",
- "Alt-Used": "free.chatgpt.org.uk",
- "Pragma": "no-cache",
- "Cache-Control": "no-cache",
- "TE": "trailers",
- }
+ "Accept": "application/json, text/event-stream",
+ "Content-Type":"application/json",
+ "Accept-Encoding": "gzip, deflate, br",
+ "Accept-Language": "en-US,en;q=0.5",
+ "Host":"free.chatgpt.org.uk",
+ "Referer":f"{cls.url}/",
+ "Origin":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/120.0.0.0 Safari/537.36",
+}
async with ClientSession(headers=headers) as session:
- data = {
- "messages": messages,
- "isAzure": False,
- "azureApiVersion": "2023-08-01-preview",
- "stream": True,
- "model": model,
- "temperature": 0.5,
- "presence_penalty": 0,
- "frequency_penalty": 0,
- "top_p": 1,
- "baseUrl": "/api/openai",
- "maxIterations": 10,
- "returnIntermediateSteps": True,
- "useTools": ["web-search", "calculator", "web-browser"],
- **kwargs
- }
- async with session.post(f"{cls.url}/api/langchain/tool/agent/nodejs", json=data, proxy=proxy) as response:
- response.raise_for_status()
- async for line in response.content:
- if line.startswith(b"data: "):
- data = json.loads(line[6:])
- if data["isSuccess"] and not data["isToolMessage"]:
- yield data["message"] \ No newline at end of file
+ data = {"messages":messages,"stream":True,"model":model,"temperature":0.5,"presence_penalty":0,"frequency_penalty":0,"top_p":1}
+ async with session.post(f'{cls.url}/api/openai/v1/chat/completions',json=data) as result:
+ async for chunk in result.content:
+
+ line = chunk.decode()
+ if line.startswith("data: [DONE]"):
+ break
+ elif line.startswith("data: "):
+ line = json.loads(line[6:])
+ if(line["choices"]==[]):
+ continue
+ if(line["choices"][0]["delta"].get("content") and line["choices"][0]["delta"]["content"]!=None):
+ yield line["choices"][0]["delta"]["content"] \ No newline at end of file
diff --git a/g4f/models.py b/g4f/models.py
index 21e85c72..90d9f444 100644
--- a/g4f/models.py
+++ b/g4f/models.py
@@ -69,8 +69,9 @@ gpt_35_long = Model(
gpt_35_turbo = Model(
name = 'gpt-3.5-turbo',
base_provider = 'openai',
- best_provider=RetryProvider([
- GptGo, You,
+ best_provider=RetryProvider([
+ FreeChatgpt,
+ GptGo, You,
GptForLove, ChatBase,
Chatgpt4Online,
])
@@ -80,7 +81,7 @@ gpt_4 = Model(
name = 'gpt-4',
base_provider = 'openai',
best_provider = RetryProvider([
- Bing, Phind, Liaobots
+ Bing, FreeChatgpt, Phind, Liaobots,
])
)
@@ -158,12 +159,12 @@ claude_instant_v1 = Model(
claude_v1 = Model(
name = 'claude-v1',
base_provider = 'anthropic',
- best_provider = Vercel)
+ best_provider = RetryProvider([FreeChatgpt,Vercel]))
claude_v2 = Model(
name = 'claude-v2',
base_provider = 'anthropic',
- best_provider = Vercel)
+ best_provider = RetryProvider([FreeChatgpt,Vercel]))
command_light_nightly = Model(
name = 'command-light-nightly',
@@ -245,6 +246,13 @@ gpt_4_32k_0613 = Model(
best_provider = gpt_4.best_provider
)
+#Gemini
+gemini_pro = Model(
+ name = 'gemini-pro',
+ base_provider = 'google',
+ best_provider = FreeChatgpt
+)
+
text_ada_001 = Model(
name = 'text-ada-001',
base_provider = 'openai',
@@ -318,6 +326,8 @@ class ModelUtils:
'mistral-7b': mistral_7b,
'openchat_3.5': openchat_35,
+ # Gemini Pro
+ 'gemini-pro': gemini_pro,
# Bard
'palm2' : palm,
'palm' : palm,