mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-17 09:25:50 +00:00
refactored code
This commit is contained in:
parent
1eefa094e3
commit
05494ebbb1
@ -4,8 +4,8 @@ from gpt4free import cocalc
|
|||||||
from gpt4free import forefront
|
from gpt4free import forefront
|
||||||
from gpt4free import quora
|
from gpt4free import quora
|
||||||
from gpt4free import theb
|
from gpt4free import theb
|
||||||
from gpt4free import you
|
|
||||||
from gpt4free import usesless
|
from gpt4free import usesless
|
||||||
|
from gpt4free import you
|
||||||
|
|
||||||
|
|
||||||
class Provider(Enum):
|
class Provider(Enum):
|
||||||
@ -24,7 +24,6 @@ class Completion:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(provider: Provider, prompt: str, **kwargs) -> str:
|
def create(provider: Provider, prompt: str, **kwargs) -> str:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Invokes the given provider with given prompt and addition arguments and returns the string response
|
Invokes the given provider with given prompt and addition arguments and returns the string response
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ class Completion:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __useless_service(prompt: str, **kwargs) -> str:
|
def __useless_service(prompt: str, **kwargs) -> str:
|
||||||
return usesless.Completion.create(prompt = prompt, **kwargs)
|
return usesless.Completion.create(prompt=prompt, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __you_service(prompt: str, **kwargs) -> str:
|
def __you_service(prompt: str, **kwargs) -> str:
|
||||||
|
@ -5,8 +5,8 @@ from typing import Generator, Optional
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
from requests import post
|
|
||||||
from pymailtm import MailTm, Message
|
from pymailtm import MailTm, Message
|
||||||
|
from requests import post
|
||||||
from tls_client import Session
|
from tls_client import Session
|
||||||
|
|
||||||
from .typing import ForeFrontResponse
|
from .typing import ForeFrontResponse
|
||||||
@ -43,10 +43,7 @@ class Account:
|
|||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4',
|
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4',
|
||||||
data={
|
data={'strategy': 'email_link', 'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'},
|
||||||
'strategy': 'email_link',
|
|
||||||
'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if logging:
|
if logging:
|
||||||
@ -93,14 +90,14 @@ class StreamingCompletion:
|
|||||||
action_type='new',
|
action_type='new',
|
||||||
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
||||||
model='gpt-4',
|
model='gpt-4',
|
||||||
proxy=None
|
proxy=None,
|
||||||
) -> Generator[ForeFrontResponse, None, None]:
|
) -> Generator[ForeFrontResponse, None, None]:
|
||||||
if not token:
|
if not token:
|
||||||
raise Exception('Token is required!')
|
raise Exception('Token is required!')
|
||||||
if not chat_id:
|
if not chat_id:
|
||||||
chat_id = str(uuid4())
|
chat_id = str(uuid4())
|
||||||
|
|
||||||
proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else None
|
proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else None
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
|
'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
|
||||||
@ -168,7 +165,7 @@ class Completion:
|
|||||||
action_type='new',
|
action_type='new',
|
||||||
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
|
||||||
model='gpt-4',
|
model='gpt-4',
|
||||||
proxy=None
|
proxy=None,
|
||||||
) -> ForeFrontResponse:
|
) -> ForeFrontResponse:
|
||||||
text = ''
|
text = ''
|
||||||
final_response = None
|
final_response = None
|
||||||
@ -179,7 +176,7 @@ class Completion:
|
|||||||
action_type=action_type,
|
action_type=action_type,
|
||||||
default_persona=default_persona,
|
default_persona=default_persona,
|
||||||
model=model,
|
model=model,
|
||||||
proxy=proxy
|
proxy=proxy,
|
||||||
):
|
):
|
||||||
if response:
|
if response:
|
||||||
final_response = response
|
final_response = response
|
||||||
@ -191,4 +188,3 @@ class Completion:
|
|||||||
raise Exception('Unable to get the response, Please try again')
|
raise Exception('Unable to get the response, Please try again')
|
||||||
|
|
||||||
return final_response
|
return final_response
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
from requests import Session
|
|
||||||
from time import sleep
|
|
||||||
from json import loads
|
from json import loads
|
||||||
from re import findall
|
from re import findall
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
from requests import Session
|
||||||
|
|
||||||
|
|
||||||
class Mail:
|
class Mail:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.client = Session()
|
self.client = Session()
|
||||||
@ -9,27 +12,32 @@ class Mail:
|
|||||||
self.cookies = {'acceptcookie': 'true'}
|
self.cookies = {'acceptcookie': 'true'}
|
||||||
self.cookies["ci_session"] = self.client.cookies.get_dict()["ci_session"]
|
self.cookies["ci_session"] = self.client.cookies.get_dict()["ci_session"]
|
||||||
self.email = None
|
self.email = None
|
||||||
|
|
||||||
def get_mail(self):
|
def get_mail(self):
|
||||||
respone=self.client.post("https://etempmail.com/getEmailAddress")
|
respone = self.client.post("https://etempmail.com/getEmailAddress")
|
||||||
#cookies
|
# cookies
|
||||||
self.cookies["lisansimo"] = eval(respone.text)["recover_key"]
|
self.cookies["lisansimo"] = eval(respone.text)["recover_key"]
|
||||||
self.email = eval(respone.text)["address"]
|
self.email = eval(respone.text)["address"]
|
||||||
return self.email
|
return self.email
|
||||||
|
|
||||||
def get_message(self):
|
def get_message(self):
|
||||||
print("Waiting for message...")
|
print("Waiting for message...")
|
||||||
while True:
|
while True:
|
||||||
sleep(5)
|
sleep(5)
|
||||||
respone=self.client.post("https://etempmail.com/getInbox")
|
respone = self.client.post("https://etempmail.com/getInbox")
|
||||||
mail_token=loads(respone.text)
|
mail_token = loads(respone.text)
|
||||||
print(self.client.cookies.get_dict())
|
print(self.client.cookies.get_dict())
|
||||||
if len(mail_token) == 1:
|
if len(mail_token) == 1:
|
||||||
break
|
break
|
||||||
|
|
||||||
params = {'id': '1',}
|
params = {
|
||||||
self.mail_context = self.client.post("https://etempmail.com/getInbox",params=params)
|
'id': '1',
|
||||||
|
}
|
||||||
|
self.mail_context = self.client.post("https://etempmail.com/getInbox", params=params)
|
||||||
self.mail_context = eval(self.mail_context.text)[0]["body"]
|
self.mail_context = eval(self.mail_context.text)[0]["body"]
|
||||||
return self.mail_context
|
return self.mail_context
|
||||||
#,cookies=self.cookies
|
|
||||||
|
# ,cookies=self.cookies
|
||||||
def get_verification_code(self):
|
def get_verification_code(self):
|
||||||
message = self.mail_context
|
message = self.mail_context
|
||||||
code = findall(r';">(\d{6,7})</div>', message)[0]
|
code = findall(r';">(\d{6,7})</div>', message)[0]
|
||||||
|
@ -19,7 +19,7 @@ class Completion:
|
|||||||
stream_completed = False
|
stream_completed = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def request(prompt: str, proxy: Optional[str]=None):
|
def request(prompt: str, proxy: Optional[str] = None):
|
||||||
headers = {
|
headers = {
|
||||||
'authority': 'chatbot.theb.ai',
|
'authority': 'chatbot.theb.ai',
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
@ -40,7 +40,7 @@ class Completion:
|
|||||||
Completion.stream_completed = True
|
Completion.stream_completed = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(prompt: str, proxy: Optional[str]=None) -> Generator[str, None, None]:
|
def create(prompt: str, proxy: Optional[str] = None) -> Generator[str, None, None]:
|
||||||
Thread(target=Completion.request, args=[prompt, proxy]).start()
|
Thread(target=Completion.request, args=[prompt, proxy]).start()
|
||||||
|
|
||||||
while not Completion.stream_completed or not Completion.message_queue.empty():
|
while not Completion.stream_completed or not Completion.message_queue.empty():
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class Completion:
|
class Completion:
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -30,12 +30,12 @@ class Completion:
|
|||||||
include_links: bool = False,
|
include_links: bool = False,
|
||||||
detailed: bool = False,
|
detailed: bool = False,
|
||||||
debug: bool = False,
|
debug: bool = False,
|
||||||
proxy: Optional[str] = None
|
proxy: Optional[str] = None,
|
||||||
) -> PoeResponse:
|
) -> PoeResponse:
|
||||||
if chat is None:
|
if chat is None:
|
||||||
chat = []
|
chat = []
|
||||||
|
|
||||||
proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else {}
|
proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else {}
|
||||||
|
|
||||||
client = Session(client_identifier='chrome_108')
|
client = Session(client_identifier='chrome_108')
|
||||||
client.headers = Completion.__get_headers()
|
client.headers = Completion.__get_headers()
|
||||||
|
@ -11,7 +11,6 @@ while True:
|
|||||||
print(f"Answer: {req['text']}")
|
print(f"Answer: {req['text']}")
|
||||||
message_id = req["id"]
|
message_id = req["id"]
|
||||||
|
|
||||||
|
|
||||||
import gpt4free
|
import gpt4free
|
||||||
|
|
||||||
message_id = ""
|
message_id = ""
|
||||||
@ -20,8 +19,7 @@ while True:
|
|||||||
if prompt == "!stop":
|
if prompt == "!stop":
|
||||||
break
|
break
|
||||||
|
|
||||||
req = gpt4free.Completion.create(provider = gpt4free.Provider.UseLess,
|
req = gpt4free.Completion.create(provider=gpt4free.Provider.UseLess, prompt=prompt, parentMessageId=message_id)
|
||||||
prompt=prompt, parentMessageId=message_id)
|
|
||||||
|
|
||||||
print(f"Answer: {req['text']}")
|
print(f"Answer: {req['text']}")
|
||||||
message_id = req["id"]
|
message_id = req["id"]
|
Loading…
Reference in New Issue
Block a user