基于chatgpt的微信自動回復功能實現(xiàn)
更新時間:2023年02月24日 08:59:05 作者:AubeLiang
這篇文章主要介紹了基于chatgpt的微信自動回復功能實現(xiàn),微信自動回復基于聊天api的實現(xiàn)代碼,本文通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下
微信自動回復 基于聊天api的
import pyautogui
import pyperclip
import keyboard
import requests
import time
print('程序即將開始,請打開微信!')
# 檢測是否有新消息
def findNews():
left, top, width, height = pyautogui.locateOnScreen("news.png", confidence=0.9)
pyautogui.click(left + 20, top + 20)
print('發(fā)現(xiàn)了新消息')
# 發(fā)送消息
def sendMsg():
left, top, width, height = pyautogui.locateOnScreen('icon.png', confidence=0.9)
print('獲取到了圖標位置')
X = left + width
pyautogui.rightClick(X, top - 40)
pyautogui.click(X + 10, top - 40 + 10)
friendMsg = pyperclip.paste() #將拷貝板內(nèi)的文字轉換為字符串
print('好友的消息:' + friendMsg)
url = 'https://v.api.aa1.cn/api/api-xiaoai/talk.php'
print('正在思考如何回復...')
res = requests.get(url, params="msg=" + friendMsg)
time.sleep(1)
reply = res.text
print('即將發(fā)送的消息:' + reply)
pyperclip.copy(reply)
pyautogui.click(X, top + 50)
pyautogui.hotkey('ctrl', 'v')
time.sleep(3)
pyautogui.press('enter')
print('發(fā)送成功!')
time.sleep(1)
# 恢復原始狀態(tài)
print('恢復原始狀態(tài)')
left, top, width, height = pyautogui.locateOnScreen('reset.png', confidence=0.9)
pyautogui.click(left + 20, top + 20)
# 開始執(zhí)行
while True:
# time.sleep(1)
# 如果按下退格鍵,則退出循環(huán)
if keyboard.is_pressed('backspace'):
print('按下了退格鍵,程序即將結束')
break
# 捕獲錯誤
try:
findNews()
sendMsg()
except TypeError:
print('沒有發(fā)現(xiàn)新消息...', time.time())
pyautogui.alert(text='Python程序已結束!', title='提示', button='好的')
print("程序已結束!")
微信自動回復 基于chatgpt的
import openai
import pyautogui
import pyperclip
import keyboard
import time
openai.api_key = "你的chat-gpt API"
def chat_gpt(prompt):# 你的問題prompt = prompt# 調用 ChatGPT 接口
model_engine = "text-davinci-003"
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,)
response = completion.choices[0].text
return response
print('程序即將開始,請打開微信!')
# 檢測是否有新消息
def findNews():
left, top, width, height = pyautogui.locateOnScreen("news.png", confidence=0.9)
pyautogui.click(left + 20, top + 20)
print('發(fā)現(xiàn)了新消息')
# 發(fā)送消息
def sendMsg():
left, top, width, height = pyautogui.locateOnScreen('icon.png', confidence=0.9)
print('獲取到了圖標位置')
X = left + width
pyautogui.rightClick(X, top - 35)
pyautogui.click(X + 10, top - 40 + 10)
friendMsg = pyperclip.paste() #將拷貝板內(nèi)的文字轉換為字符串
print('好友的消息:' + friendMsg)
#url = 'https://v.api.aa1.cn/api/api-xiaoai/talk.php'
print('正在思考如何回復...')
#res = requests.get(url, params="msg=" + friendMsg)
#time.sleep(1)
reply = chat_gpt(friendMsg).replace('?','').strip()
print('即將發(fā)送的消息:' + reply)
pyperclip.copy(reply)
pyautogui.click(X, top + 50)
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)
pyautogui.press('enter')
print('發(fā)送成功!')
#time.sleep(1)
# 恢復原始狀態(tài)
print('恢復原始狀態(tài)')
left, top, width, height = pyautogui.locateOnScreen('reset.png', confidence=0.9)
pyautogui.click(left + 20, top + 20)
# 開始執(zhí)行
while True:
# time.sleep(1)
# 如果按下退格鍵,則退出循環(huán)
if keyboard.is_pressed('backspace'):
print('按下了退格鍵,程序即將結束')
break
# 捕獲錯誤
try:
findNews()
sendMsg()
except TypeError:
print('沒有發(fā)現(xiàn)新消息...', time.time())
pyautogui.alert(text='Python程序已結束!', title='提示', button='好的')
print("程序已結束!")
到此這篇關于基于chatgpt的微信自動回復功能實現(xiàn)的文章就介紹到這了,更多相關chatgpt微信自動回復內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
git工作區(qū)暫存區(qū)與版本庫基本理解及提交流程全解
這篇文章主要為大家介紹了git工作區(qū)暫存區(qū)與版本庫基本理解及提交流程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步2022-04-04
深入解析HetuEngine實現(xiàn)On Yarn原理
這篇文章主要介紹了HetuEngine實現(xiàn)On Yarn原理,介紹了HetuEngine On Yarn的原理,其實現(xiàn)主要是借助了Yarn Service提供的能力,感興趣的朋友一起通過本文學習下2022-01-01

