chatgpt的时代,先用gpt3来做一个哪里都可以接入的代码吧

Posted 星涅爱别离

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了chatgpt的时代,先用gpt3来做一个哪里都可以接入的代码吧相关的知识,希望对你有一定的参考价值。

from aiowebsocket.converses import AioWebSocket
import json
import requests
import time
from tkinter import *
import random
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from seleniumwire import webdriver
# from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
import re
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
browser = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
# 清除所有cookie
browser.delete_all_cookies()
browser.get(\'https://chat.forchange.cn\')
time.sleep(5)
num = 0
while True:
input_add = browser.find_element(By.XPATH, r\'//*[@id="chatgpt"]/div/div[1]/main/div[2]/form/div/div[2]/textarea\')
input_word = input(str(num * 2 + 1) + \'你要说到话:\')
if input_word == \'退出\':
break
input_add.send_keys(input_word)
browser_click = browser.find_element(By.XPATH, r\'//*[@id="chatgpt"]/div/div[1]/main/div[2]/form/div/div[2]/button\')
browser_click.click()
time.sleep(5)
do_find = False
while do_find == False:
try:
try:
answer_error = browser.find_element(By.XPATH,
r\'//*[@id="chatgpt"]/div/div[1]/main/div[1]/div/div/div/div[\' + str(
num * 2 + 2) + \']/div/div[2]/div\')
if answer_error.text == \'sorry,当前访问人数太多,请稍后再试!\':
print(\'现在网络不好,即将点击重试按钮\')
time.sleep(5)
retry_button = browser.find_element(By.XPATH,
r\'//*[@id="chatgpt"]/div/div[1]/main/div[2]/form/div/div[1]/button\')
retry_button.click()
except Exception as e:
print(\'没找到这个错误到时候,是不是能找到下面到情况\')
time.sleep(10)
answer = browser.find_element(By.XPATH, r\'//*[@id="chatgpt"]/div/div[1]/main/div[1]/div/div/div/div[\' + str(
num * 2 + 2) + \']/div/div[2]/div\')
if len(answer.text) != 0:
# print(num + 1, \'你:\', input_word)
print(str(num * 2 + 2) + \'机器人:\',answer.text)
do_find = True
num += 1
except Exception as e:
print(e)
time.sleep(5)
browser.close()

看看结果:

1你要说到话:请给出2022最伟大的人物
2机器人: 2022年最伟大的人物可能是美国总统唐纳德·特朗普,他在2022年将继续推动美国经济增长,改善美国的外交关系,并继续推动全球和平。
3你要说到话:

 

还不错哦,将它打包成方法,结果return就可以在任何地方接入了

以上是关于chatgpt的时代,先用gpt3来做一个哪里都可以接入的代码吧的主要内容,如果未能解决你的问题,请参考以下文章

程序员与ChatGPT的日常问答

Meta 推出大型语言模型 LLaMA,比 GPT3.5 性能更高

基于GPT3.5实现本地知识库解决方案-利用向量数据库和GPT向量接口-实现智能回复并限制ChatGPT回答的范围...

微软ChatGPT越牛逼,.Net越落寞?

ChatGPT没有API?OpenAI官方API带你起飞

关于ChatGPT的一切;CUDA入门之矩阵乘;PyTorch 2.0发布|AI系统前沿动态