2023-03-05 14:07:25 +00:00
|
|
|
from v3 import Chatbot
|
|
|
|
import asyncio
|
|
|
|
from ask_gpt import ask
|
|
|
|
import json
|
2023-03-10 15:45:38 +00:00
|
|
|
from bing import BingBot
|
|
|
|
|
2023-03-05 14:07:25 +00:00
|
|
|
fp = open("config.json", "r")
|
|
|
|
config = json.load(fp)
|
2023-03-10 10:53:51 +00:00
|
|
|
api_key = config.get('api_key', '')
|
2023-03-10 15:45:38 +00:00
|
|
|
bing_api_endpoint = config.get('bing_api_endpoint', '')
|
2023-03-10 10:53:51 +00:00
|
|
|
api_endpoint_list = {
|
|
|
|
"free": "https://chatgpt-api.shn.hk/v1/",
|
|
|
|
"paid": "https://api.openai.com/v1/chat/completions"
|
|
|
|
}
|
2023-03-05 14:07:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_v3(prompt: str):
|
2023-03-10 10:53:51 +00:00
|
|
|
bot = Chatbot(api_key=api_key)
|
2023-03-05 14:07:25 +00:00
|
|
|
resp = bot.ask(prompt=prompt)
|
|
|
|
print(resp)
|
|
|
|
|
|
|
|
|
2023-03-10 10:53:51 +00:00
|
|
|
async def test_ask_gpt_paid(prompt: str):
|
|
|
|
headers = {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Authorization": "Bearer " + api_key,
|
|
|
|
}
|
|
|
|
api_endpoint = api_endpoint_list['paid']
|
|
|
|
# test ask_gpt.py ask()
|
|
|
|
print(await ask(prompt, api_endpoint, headers))
|
|
|
|
|
|
|
|
|
|
|
|
async def test_ask_gpt_free(prompt: str):
|
|
|
|
headers = {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
}
|
|
|
|
api_endpoint = api_endpoint_list['free']
|
|
|
|
print(await ask(prompt, api_endpoint, headers))
|
2023-03-05 14:07:25 +00:00
|
|
|
|
2023-03-10 15:45:38 +00:00
|
|
|
|
|
|
|
async def test_bingbot():
|
|
|
|
if bing_api_endpoint != '':
|
|
|
|
bingbot = BingBot(bing_api_endpoint)
|
|
|
|
prompt1 = "Hello World"
|
|
|
|
prompt2 = "Do you know Victor Marie Hugo"
|
|
|
|
prompt3 = "Can you tell me something about him?"
|
|
|
|
resp1 = await bingbot.ask_bing(prompt1)
|
|
|
|
resp2 = await bingbot.ask_bing(prompt2)
|
|
|
|
resp3 = await bingbot.ask_bing(prompt3)
|
|
|
|
print(resp1)
|
|
|
|
print(resp2)
|
|
|
|
print(resp3)
|
|
|
|
|
2023-03-05 14:07:25 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
test_v3("Hello World")
|
2023-03-10 10:53:51 +00:00
|
|
|
asyncio.run(test_ask_gpt_paid("Hello World"))
|
|
|
|
asyncio.run(test_ask_gpt_free("Hello World"))
|
2023-03-10 15:45:38 +00:00
|
|
|
asyncio.run(test_bingbot())
|