基于chatgpt的微信自动回复功能如何实现

发布时间:2023-02-24 10:46:39 作者:iii
来源:亿速云 阅读:127

本文小编为大家详细介绍“基于chatgpt的微信自动回复功能如何实现”,内容详细,步骤清晰,细节处理妥当,希望这篇“基于chatgpt的微信自动回复功能如何实现”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

微信自动回复 基于聊天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('发现了新消息')

# 发送消息
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() #将拷贝板内的文字转换为字符串
    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('即将发送的消息:' + reply)
    pyperclip.copy(reply)
    pyautogui.click(X, top + 50)
    pyautogui.hotkey('ctrl', 'v')
    time.sleep(3)
    pyautogui.press('enter')
    print('发送成功!')
    time.sleep(1)
    # 恢复原始状态
    print('恢复原始状态')
    left, top, width, height = pyautogui.locateOnScreen('reset.png', confidence=0.9)
    pyautogui.click(left + 20, top  + 20)

# 开始执行
while True:
    # time.sleep(1)
    # 如果按下退格键,则退出循环
    if keyboard.is_pressed('backspace'):
        print('按下了退格键,程序即将结束')
        break
    
    # 捕获错误
    try:
        findNews()
        sendMsg()

    except TypeError:
        print('没有发现新消息...', 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('发现了新消息')

# 发送消息
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() #将拷贝板内的文字转换为字符串
    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('即将发送的消息:' + reply)
    pyperclip.copy(reply)
    pyautogui.click(X, top + 50)
    pyautogui.hotkey('ctrl', 'v')
    time.sleep(1)
    pyautogui.press('enter')
    print('发送成功!')
    #time.sleep(1)
    # 恢复原始状态
    print('恢复原始状态')
    left, top, width, height = pyautogui.locateOnScreen('reset.png', confidence=0.9)
    pyautogui.click(left + 20, top  + 20)

# 开始执行
while True:
    # time.sleep(1)
    # 如果按下退格键,则退出循环
    if keyboard.is_pressed('backspace'):
        print('按下了退格键,程序即将结束')
        break
    
    # 捕获错误
    try:
        findNews()
        sendMsg()

    except TypeError:
        print('没有发现新消息...', time.time())

pyautogui.alert(text='Python程序已结束!', title='提示', button='好的')
print("程序已结束!")

读到这里,这篇“基于chatgpt的微信自动回复功能如何实现”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. ChatGPT是什么及怎么使用
  2. 怎么调用chatGPT实现代码机器人

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

chatgpt

上一篇:js fill函数填充数组或对象的问题怎么解决

下一篇:js如何获取异步函数数据

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》