您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“基于chatgpt的微信自動回復(fù)功能如何實現(xiàn)”,內(nèi)容詳細,步驟清晰,細節(jié)處理妥當(dāng),希望這篇“基于chatgpt的微信自動回復(fù)功能如何實現(xiàn)”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識吧。
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)的文字轉(zhuǎn)換為字符串 print('好友的消息:' + friendMsg) url = 'https://v.api.aa1.cn/api/api-xiaoai/talk.php' print('正在思考如何回復(fù)...') 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) # 恢復(fù)原始狀態(tài) print('恢復(fù)原始狀態(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('按下了退格鍵,程序即將結(jié)束') break # 捕獲錯誤 try: findNews() sendMsg() except TypeError: print('沒有發(fā)現(xiàn)新消息...', time.time()) pyautogui.alert(text='Python程序已結(jié)束!', title='提示', button='好的') print("程序已結(jié)束!")
import openai import pyautogui import pyperclip import keyboard import time openai.api_key = "你的chat-gpt API" def chat_gpt(prompt):# 你的問題prompt = prompt# 調(diào)用 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)的文字轉(zhuǎn)換為字符串 print('好友的消息:' + friendMsg) #url = 'https://v.api.aa1.cn/api/api-xiaoai/talk.php' print('正在思考如何回復(fù)...') #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) # 恢復(fù)原始狀態(tài) print('恢復(fù)原始狀態(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('按下了退格鍵,程序即將結(jié)束') break # 捕獲錯誤 try: findNews() sendMsg() except TypeError: print('沒有發(fā)現(xiàn)新消息...', time.time()) pyautogui.alert(text='Python程序已結(jié)束!', title='提示', button='好的') print("程序已結(jié)束!")
讀到這里,這篇“基于chatgpt的微信自動回復(fù)功能如何實現(xiàn)”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。