summaryrefslogtreecommitdiffstats
path: root/g4f/.v1/testing
diff options
context:
space:
mode:
authort.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-06-24 03:47:00 +0200
committert.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-06-24 03:47:00 +0200
commit5db58fd87f230fbe5bae599bb4b120ab42cad3be (patch)
tree770be13bca77c5d04dfe3265f378431df788706f /g4f/.v1/testing
parentMerge pull request #664 from LopeKinz/main (diff)
downloadgpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar
gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.gz
gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.bz2
gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.lz
gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.xz
gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.zst
gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.zip
Diffstat (limited to 'g4f/.v1/testing')
-rw-r--r--g4f/.v1/testing/aiassistest.py13
-rw-r--r--g4f/.v1/testing/aicolors_test.py6
-rw-r--r--g4f/.v1/testing/deepai_test.py18
-rw-r--r--g4f/.v1/testing/forefront_test.py9
-rw-r--r--g4f/.v1/testing/gptworldai_test.py18
-rw-r--r--g4f/.v1/testing/hpgptai_test.py41
-rw-r--r--g4f/.v1/testing/italygpt2_test.py4
-rw-r--r--g4f/.v1/testing/openaihosted_test.py14
-rw-r--r--g4f/.v1/testing/poe_account_create_test.py109
-rw-r--r--g4f/.v1/testing/poe_test.py13
-rw-r--r--g4f/.v1/testing/quora_test_2.py12
-rw-r--r--g4f/.v1/testing/sqlchat_test.py4
-rw-r--r--g4f/.v1/testing/t3nsor_test.py4
-rw-r--r--g4f/.v1/testing/test_main.py27
-rw-r--r--g4f/.v1/testing/theb_test.py5
-rw-r--r--g4f/.v1/testing/useless_test.py25
-rw-r--r--g4f/.v1/testing/usesless_test.py13
-rw-r--r--g4f/.v1/testing/writesonic_test.py35
-rw-r--r--g4f/.v1/testing/you_test.py27
19 files changed, 397 insertions, 0 deletions
diff --git a/g4f/.v1/testing/aiassistest.py b/g4f/.v1/testing/aiassistest.py
new file mode 100644
index 00000000..57a34f15
--- /dev/null
+++ b/g4f/.v1/testing/aiassistest.py
@@ -0,0 +1,13 @@
+import aiassist
+
+question1 = "Who won the world series in 2020?"
+req = aiassist.Completion.create(prompt=question1)
+answer = req["text"]
+message_id = req["parentMessageId"]
+
+question2 = "Where was it played?"
+req2 = aiassist.Completion.create(prompt=question2, parentMessageId=message_id)
+answer2 = req2["text"]
+
+print(answer)
+print(answer2)
diff --git a/g4f/.v1/testing/aicolors_test.py b/g4f/.v1/testing/aicolors_test.py
new file mode 100644
index 00000000..853f7e45
--- /dev/null
+++ b/g4f/.v1/testing/aicolors_test.py
@@ -0,0 +1,6 @@
+from gpt4free import aicolors
+
+prompt = "Light green color"
+req = aicolors.Completion.create(prompt=prompt)
+
+print(req)
diff --git a/g4f/.v1/testing/deepai_test.py b/g4f/.v1/testing/deepai_test.py
new file mode 100644
index 00000000..474f663e
--- /dev/null
+++ b/g4f/.v1/testing/deepai_test.py
@@ -0,0 +1,18 @@
+from gpt4free import deepai
+
+#single completion
+for chunk in deepai.Completion.create("Write a list of possible vacation destinations:"):
+ print(chunk, end="", flush=True)
+print()
+
+#chat completion
+print("==============")
+messages = [ #taken from the openai docs
+ {"role": "system", "content": "You are a helpful assistant."},
+ {"role": "user", "content": "Who won the world series in 2020?"},
+ {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
+ {"role": "user", "content": "Where was it played?"}
+]
+for chunk in deepai.ChatCompletion.create(messages):
+ print(chunk, end="", flush=True)
+print() \ No newline at end of file
diff --git a/g4f/.v1/testing/forefront_test.py b/g4f/.v1/testing/forefront_test.py
new file mode 100644
index 00000000..b7b5c57c
--- /dev/null
+++ b/g4f/.v1/testing/forefront_test.py
@@ -0,0 +1,9 @@
+from gpt4free import forefront
+
+# create an account
+token = forefront.Account.create(logging=True)
+print(token)
+
+# get a response
+for response in forefront.StreamingCompletion.create(token=token, prompt='hello world', model='gpt-4'):
+ print(response.text, end='')
diff --git a/g4f/.v1/testing/gptworldai_test.py b/g4f/.v1/testing/gptworldai_test.py
new file mode 100644
index 00000000..3dfb32ce
--- /dev/null
+++ b/g4f/.v1/testing/gptworldai_test.py
@@ -0,0 +1,18 @@
+import gptworldAi
+
+# single completion
+for chunk in gptworldAi.Completion.create("你是谁", "127.0.0.1:7890"):
+ print(chunk, end="", flush=True)
+print()
+
+# chat completion
+message = []
+while True:
+ prompt = input("请输入问题:")
+ message.append({"role": "user", "content": prompt})
+ text = ""
+ for chunk in gptworldAi.ChatCompletion.create(message, '127.0.0.1:7890'):
+ text = text + chunk
+ print(chunk, end="", flush=True)
+ print()
+ message.append({"role": "assistant", "content": text})
diff --git a/g4f/.v1/testing/hpgptai_test.py b/g4f/.v1/testing/hpgptai_test.py
new file mode 100644
index 00000000..cdd146dd
--- /dev/null
+++ b/g4f/.v1/testing/hpgptai_test.py
@@ -0,0 +1,41 @@
+import hpgptai
+
+#single completion
+res = hpgptai.Completion.create("你是谁","127.0.0.1:7890")
+print(res["reply"])
+
+
+#chat completion
+messages = [
+ {
+ "content": "你是谁",
+ "html": "你是谁",
+ "id": hpgptai.ChatCompletion.randomStr(),
+ "role": "user",
+ "who": "User: ",
+ },
+ {
+ "content": "我是一位AI助手,专门为您提供各种服务和支持。我可以回答您的问题,帮助您解决问题,提供相关信息,并执行一些任务。请随时告诉我您需要什么帮助。",
+ "html": "我是一位AI助手,专门为您提供各种服务和支持。我可以回答您的问题,帮助您解决问题,提供相关信息,并执行一些任务。请随时告诉我您需要什么帮助。",
+ "id": hpgptai.ChatCompletion.randomStr(),
+ "role": "assistant",
+ "who": "AI: ",
+ },
+ {
+ "content": "我上一句问的是什么?",
+ "html": "我上一句问的是什么?",
+ "id": hpgptai.ChatCompletion.randomStr(),
+ "role": "user",
+ "who": "User: ",
+ },
+]
+res = hpgptai.ChatCompletion.create(messages,proxy="127.0.0.1:7890")
+print(res["reply"])
+
+
+
+
+
+
+
+
diff --git a/g4f/.v1/testing/italygpt2_test.py b/g4f/.v1/testing/italygpt2_test.py
new file mode 100644
index 00000000..0494c8a2
--- /dev/null
+++ b/g4f/.v1/testing/italygpt2_test.py
@@ -0,0 +1,4 @@
+from gpt4free import italygpt2
+account_data=italygpt2.Account.create()
+for chunk in italygpt2.Completion.create(account_data=account_data,prompt="Who are you?"):
+ print(chunk, end="", flush=True) \ No newline at end of file
diff --git a/g4f/.v1/testing/openaihosted_test.py b/g4f/.v1/testing/openaihosted_test.py
new file mode 100644
index 00000000..d5a79e52
--- /dev/null
+++ b/g4f/.v1/testing/openaihosted_test.py
@@ -0,0 +1,14 @@
+import openaihosted
+
+messages = [{"role": "system", "content": "You are a helpful assistant."}]
+while True:
+ question = input("Question: ")
+ if question == "!stop":
+ break
+
+ messages.append({"role": "user", "content": question})
+ request = openaihosted.Completion.create(messages=messages)
+
+ response = request["responses"]
+ messages.append({"role": "assistant", "content": response})
+ print(f"Answer: {response}")
diff --git a/g4f/.v1/testing/poe_account_create_test.py b/g4f/.v1/testing/poe_account_create_test.py
new file mode 100644
index 00000000..41ae5a33
--- /dev/null
+++ b/g4f/.v1/testing/poe_account_create_test.py
@@ -0,0 +1,109 @@
+from hashlib import md5
+from json import dumps
+from re import findall
+from typing import Optional
+
+from tls_client import Session as TLS
+from twocaptcha import TwoCaptcha
+
+from gpt4free.quora import extract_formkey
+from gpt4free.quora.mail import Emailnator
+
+solver = TwoCaptcha('')
+
+
+class Account:
+ @staticmethod
+ def create(proxy: Optional[str] = None, logging: bool = False, enable_bot_creation: bool = False):
+ client = TLS(client_identifier='chrome110')
+ client.proxies = {'http': f'http://{proxy}', 'https': f'http://{proxy}'} if proxy else None
+
+ mail_client = Emailnator()
+ mail_address = mail_client.get_mail()
+
+ if logging:
+ print('email', mail_address)
+
+ client.headers = {
+ 'authority': 'poe.com',
+ 'accept': '*/*',
+ 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
+ 'content-type': 'application/json',
+ 'origin': 'https://poe.com',
+ 'poe-formkey': 'null',
+ 'poe-tag-id': 'null',
+ 'poe-tchannel': 'null',
+ 'referer': 'https://poe.com/login',
+ 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
+ 'sec-ch-ua-mobile': '?0',
+ 'sec-ch-ua-platform': '"macOS"',
+ 'sec-fetch-dest': 'empty',
+ 'sec-fetch-mode': 'cors',
+ 'sec-fetch-site': 'same-origin',
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
+ }
+
+ client.headers["poe-formkey"] = extract_formkey(client.get('https://poe.com/login').text)
+ client.headers["poe-tchannel"] = client.get('https://poe.com/api/settings').json()['tchannelData']['channel']
+
+ # token = reCaptchaV3('https://www.recaptcha.net/recaptcha/enterprise/anchor?ar=1&k=6LflhEElAAAAAI_ewVwRWI9hsyV4mbZnYAslSvlG&co=aHR0cHM6Ly9wb2UuY29tOjQ0Mw..&hl=en&v=4PnKmGB9wRHh1i04o7YUICeI&size=invisible&cb=bi6ivxoskyal')
+ token = solver.recaptcha(
+ sitekey='6LflhEElAAAAAI_ewVwRWI9hsyV4mbZnYAslSvlG',
+ url='https://poe.com/login?redirect_url=%2F',
+ version='v3',
+ enterprise=1,
+ invisible=1,
+ action='login',
+ )['code']
+
+ payload = dumps(
+ separators=(',', ':'),
+ obj={
+ 'queryName': 'MainSignupLoginSection_sendVerificationCodeMutation_Mutation',
+ 'variables': {'emailAddress': mail_address, 'phoneNumber': None, 'recaptchaToken': token},
+ 'query': 'mutation MainSignupLoginSection_sendVerificationCodeMutation_Mutation(\n $emailAddress: String\n $phoneNumber: String\n $recaptchaToken: String\n) {\n sendVerificationCode(verificationReason: login, emailAddress: $emailAddress, phoneNumber: $phoneNumber, recaptchaToken: $recaptchaToken) {\n status\n errorMessage\n }\n}\n',
+ },
+ )
+
+ base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k'
+ client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
+
+ print(dumps(client.headers, indent=4))
+
+ response = client.post('https://poe.com/api/gql_POST', data=payload)
+
+ if 'automated_request_detected' in response.text:
+ print('please try using a proxy / wait for fix')
+
+ if 'Bad Request' in response.text:
+ if logging:
+ print('bad request, retrying...', response.json())
+ quit()
+
+ if logging:
+ print('send_code', response.json())
+
+ mail_content = mail_client.get_message()
+ mail_token = findall(r';">(\d{6,7})</div>', mail_content)[0]
+
+ if logging:
+ print('code', mail_token)
+
+ payload = dumps(
+ separators=(',', ':'),
+ obj={
+ "queryName": "SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation",
+ "variables": {"verificationCode": str(mail_token), "emailAddress": mail_address, "phoneNumber": None},
+ "query": "mutation SignupOrLoginWithCodeSection_signupWithVerificationCodeMutation_Mutation(\n $verificationCode: String!\n $emailAddress: String\n $phoneNumber: String\n) {\n signupWithVerificationCode(verificationCode: $verificationCode, emailAddress: $emailAddress, phoneNumber: $phoneNumber) {\n status\n errorMessage\n }\n}\n",
+ },
+ )
+
+ base_string = payload + client.headers["poe-formkey"] + 'WpuLMiXEKKE98j56k'
+ client.headers["poe-tag-id"] = md5(base_string.encode()).hexdigest()
+
+ response = client.post('https://poe.com/api/gql_POST', data=payload)
+ if logging:
+ print('verify_code', response.json())
+
+
+Account.create(proxy='', logging=True)
diff --git a/g4f/.v1/testing/poe_test.py b/g4f/.v1/testing/poe_test.py
new file mode 100644
index 00000000..6edc030c
--- /dev/null
+++ b/g4f/.v1/testing/poe_test.py
@@ -0,0 +1,13 @@
+from time import sleep
+
+from gpt4free import quora
+
+token = quora.Account.create(proxy=None, logging=True)
+print('token', token)
+
+sleep(2)
+
+for response in quora.StreamingCompletion.create(model='ChatGPT', prompt='hello world', token=token):
+ print(response.text, flush=True)
+
+quora.Account.delete(token)
diff --git a/g4f/.v1/testing/quora_test_2.py b/g4f/.v1/testing/quora_test_2.py
new file mode 100644
index 00000000..297ca7a1
--- /dev/null
+++ b/g4f/.v1/testing/quora_test_2.py
@@ -0,0 +1,12 @@
+from gpt4free import quora
+
+token = quora.Account.create(logging=True, enable_bot_creation=True)
+
+model = quora.Model.create(
+ token=token, model='ChatGPT', system_prompt='you are ChatGPT a large language model ...' # or claude-instant-v1.0
+)
+
+print(model.name)
+
+for response in quora.StreamingCompletion.create(custom_model=model.name, prompt='hello world', token=token):
+ print(response.text)
diff --git a/g4f/.v1/testing/sqlchat_test.py b/g4f/.v1/testing/sqlchat_test.py
new file mode 100644
index 00000000..1db71be2
--- /dev/null
+++ b/g4f/.v1/testing/sqlchat_test.py
@@ -0,0 +1,4 @@
+import sqlchat
+
+for response in sqlchat.StreamCompletion.create(prompt='write python code to reverse a string', messages=[]):
+ print(response.completion.choices[0].text, end='')
diff --git a/g4f/.v1/testing/t3nsor_test.py b/g4f/.v1/testing/t3nsor_test.py
new file mode 100644
index 00000000..6d36400d
--- /dev/null
+++ b/g4f/.v1/testing/t3nsor_test.py
@@ -0,0 +1,4 @@
+import t3nsor
+
+for response in t3nsor.StreamCompletion.create(prompt='write python code to reverse a string', messages=[]):
+ print(response.completion.choices[0].text)
diff --git a/g4f/.v1/testing/test_main.py b/g4f/.v1/testing/test_main.py
new file mode 100644
index 00000000..7c28f1d2
--- /dev/null
+++ b/g4f/.v1/testing/test_main.py
@@ -0,0 +1,27 @@
+import gpt4free
+from gpt4free import Provider, quora, forefront
+
+# usage You
+response = gpt4free.Completion.create(Provider.You, prompt='Write a poem on Lionel Messi')
+print(response)
+
+# usage Poe
+token = quora.Account.create(logging=False)
+response = gpt4free.Completion.create(Provider.Poe, prompt='Write a poem on Lionel Messi', token=token, model='ChatGPT')
+print(response)
+
+# usage forefront
+token = forefront.Account.create(logging=False)
+response = gpt4free.Completion.create(
+ Provider.ForeFront, prompt='Write a poem on Lionel Messi', model='gpt-4', token=token
+)
+print(response)
+print(f'END')
+
+# usage theb
+response = gpt4free.Completion.create(Provider.Theb, prompt='Write a poem on Lionel Messi')
+print(response)
+
+# usage cocalc
+response = gpt4free.Completion.create(Provider.CoCalc, prompt='Write a poem on Lionel Messi', cookie_input='')
+print(response)
diff --git a/g4f/.v1/testing/theb_test.py b/g4f/.v1/testing/theb_test.py
new file mode 100644
index 00000000..5fa80908
--- /dev/null
+++ b/g4f/.v1/testing/theb_test.py
@@ -0,0 +1,5 @@
+from gpt4free import theb
+
+for token in theb.Completion.create('hello world'):
+ print(token, end='', flush=True)
+ print('asdsos')
diff --git a/g4f/.v1/testing/useless_test.py b/g4f/.v1/testing/useless_test.py
new file mode 100644
index 00000000..47c92386
--- /dev/null
+++ b/g4f/.v1/testing/useless_test.py
@@ -0,0 +1,25 @@
+from gpt4free import usesless
+
+message_id = ""
+while True:
+ prompt = input("Question: ")
+ if prompt == "!stop":
+ break
+
+ req = usesless.Completion.create(prompt=prompt, parentMessageId=message_id)
+
+ print(f"Answer: {req['text']}")
+ message_id = req["id"]
+
+import gpt4free
+
+message_id = ""
+while True:
+ prompt = input("Question: ")
+ if prompt == "!stop":
+ break
+
+ req = gpt4free.Completion.create(provider=gpt4free.Provider.UseLess, prompt=prompt, parentMessageId=message_id)
+
+ print(f"Answer: {req['text']}")
+ message_id = req["id"]
diff --git a/g4f/.v1/testing/usesless_test.py b/g4f/.v1/testing/usesless_test.py
new file mode 100644
index 00000000..e2e35547
--- /dev/null
+++ b/g4f/.v1/testing/usesless_test.py
@@ -0,0 +1,13 @@
+import usesless
+
+question1 = "Who won the world series in 2020?"
+req = usesless.Completion.create(prompt=question1)
+answer = req["text"]
+message_id = req["parentMessageId"]
+
+question2 = "Where was it played?"
+req2 = usesless.Completion.create(prompt=question2, parentMessageId=message_id)
+answer2 = req2["text"]
+
+print(answer)
+print(answer2)
diff --git a/g4f/.v1/testing/writesonic_test.py b/g4f/.v1/testing/writesonic_test.py
new file mode 100644
index 00000000..aff847f0
--- /dev/null
+++ b/g4f/.v1/testing/writesonic_test.py
@@ -0,0 +1,35 @@
+# import writesonic
+import writesonic
+
+# create account (3-4s)
+account = writesonic.Account.create(logging=True)
+
+# with loging:
+# 2023-04-06 21:50:25 INFO __main__ -> register success : '{"id":"51aa0809-3053-44f7-922a...' (2s)
+# 2023-04-06 21:50:25 INFO __main__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
+# 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...'
+# 2023-04-06 21:50:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
+
+# simple completion
+response = writesonic.Completion.create(api_key=account.key, prompt='hello world')
+
+print(response.completion.choices[0].text) # Hello! How may I assist you today?
+
+# conversation
+
+response = writesonic.Completion.create(
+ api_key=account.key,
+ prompt='what is my name ?',
+ enable_memory=True,
+ history_data=[{'is_sent': True, 'message': 'my name is Tekky'}, {'is_sent': False, 'message': 'hello Tekky'}],
+)
+
+print(response.completion.choices[0].text) # Your name is Tekky.
+
+# enable internet
+
+response = writesonic.Completion.create(
+ api_key=account.key, prompt='who won the quatar world cup ?', enable_google_results=True
+)
+
+print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ...
diff --git a/g4f/.v1/testing/you_test.py b/g4f/.v1/testing/you_test.py
new file mode 100644
index 00000000..1e9f6205
--- /dev/null
+++ b/g4f/.v1/testing/you_test.py
@@ -0,0 +1,27 @@
+from gpt4free import you
+
+# simple request with links and details
+response = you.Completion.create(prompt="hello world", detailed=True, include_links=True)
+
+print(response)
+
+# {
+# "response": "...",
+# "links": [...],
+# "extra": {...},
+# "slots": {...}
+# }
+# }
+
+# chatbot
+
+chat = []
+
+while True:
+ prompt = input("You: ")
+
+ response = you.Completion.create(prompt=prompt, chat=chat)
+
+ print("Bot:", response.text)
+
+ chat.append({"question": prompt, "answer": response.text})