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

其他教程   发布日期:2023年07月05日   浏览次数:914

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

微信自动回复 基于聊天api的

  1. import pyautogui
  2. import pyperclip
  3. import keyboard
  4. import requests
  5. import time
  6. print('程序即将开始,请打开微信!')
  7. # 检测是否有新消息
  8. def findNews():
  9. left, top, width, height = pyautogui.locateOnScreen("news.png", confidence=0.9)
  10. pyautogui.click(left + 20, top + 20)
  11. print('发现了新消息')
  12. # 发送消息
  13. def sendMsg():
  14. left, top, width, height = pyautogui.locateOnScreen('icon.png', confidence=0.9)
  15. print('获取到了图标位置')
  16. X = left + width
  17. pyautogui.rightClick(X, top - 40)
  18. pyautogui.click(X + 10, top - 40 + 10)
  19. friendMsg = pyperclip.paste() #将拷贝板内的文字转换为字符串
  20. print('好友的消息:' + friendMsg)
  21. url = 'https://v.api.aa1.cn/api/api-xiaoai/talk.php'
  22. print('正在思考如何回复...')
  23. res = requests.get(url, params="msg=" + friendMsg)
  24. time.sleep(1)
  25. reply = res.text
  26. print('即将发送的消息:' + reply)
  27. pyperclip.copy(reply)
  28. pyautogui.click(X, top + 50)
  29. pyautogui.hotkey('ctrl', 'v')
  30. time.sleep(3)
  31. pyautogui.press('enter')
  32. print('发送成功!')
  33. time.sleep(1)
  34. # 恢复原始状态
  35. print('恢复原始状态')
  36. left, top, width, height = pyautogui.locateOnScreen('reset.png', confidence=0.9)
  37. pyautogui.click(left + 20, top + 20)
  38. # 开始执行
  39. while True:
  40. # time.sleep(1)
  41. # 如果按下退格键,则退出循环
  42. if keyboard.is_pressed('backspace'):
  43. print('按下了退格键,程序即将结束')
  44. break
  45. # 捕获错误
  46. try:
  47. findNews()
  48. sendMsg()
  49. except TypeError:
  50. print('没有发现新消息...', time.time())
  51. pyautogui.alert(text='Python程序已结束!', title='提示', button='好的')
  52. print("程序已结束!")

微信自动回复 基于chatgpt的

  1. import openai
  2. import pyautogui
  3. import pyperclip
  4. import keyboard
  5. import time
  6. openai.api_key = "你的chat-gpt API"
  7. def chat_gpt(prompt):# 你的问题prompt = prompt# 调用 ChatGPT 接口
  8. model_engine = "text-davinci-003"
  9. completion = openai.Completion.create(
  10. engine=model_engine,
  11. prompt=prompt,
  12. max_tokens=1024,
  13. n=1,
  14. stop=None,
  15. temperature=0.5,)
  16. response = completion.choices[0].text
  17. return response
  18. print('程序即将开始,请打开微信!')
  19. # 检测是否有新消息
  20. def findNews():
  21. left, top, width, height = pyautogui.locateOnScreen("news.png", confidence=0.9)
  22. pyautogui.click(left + 20, top + 20)
  23. print('发现了新消息')
  24. # 发送消息
  25. def sendMsg():
  26. left, top, width, height = pyautogui.locateOnScreen('icon.png', confidence=0.9)
  27. print('获取到了图标位置')
  28. X = left + width
  29. pyautogui.rightClick(X, top - 35)
  30. pyautogui.click(X + 10, top - 40 + 10)
  31. friendMsg = pyperclip.paste() #将拷贝板内的文字转换为字符串
  32. print('好友的消息:' + friendMsg)
  33. #url = 'https://v.api.aa1.cn/api/api-xiaoai/talk.php'
  34. print('正在思考如何回复...')
  35. #res = requests.get(url, params="msg=" + friendMsg)
  36. #time.sleep(1)
  37. reply = chat_gpt(friendMsg).replace('?','').strip()
  38. print('即将发送的消息:' + reply)
  39. pyperclip.copy(reply)
  40. pyautogui.click(X, top + 50)
  41. pyautogui.hotkey('ctrl', 'v')
  42. time.sleep(1)
  43. pyautogui.press('enter')
  44. print('发送成功!')
  45. #time.sleep(1)
  46. # 恢复原始状态
  47. print('恢复原始状态')
  48. left, top, width, height = pyautogui.locateOnScreen('reset.png', confidence=0.9)
  49. pyautogui.click(left + 20, top + 20)
  50. # 开始执行
  51. while True:
  52. # time.sleep(1)
  53. # 如果按下退格键,则退出循环
  54. if keyboard.is_pressed('backspace'):
  55. print('按下了退格键,程序即将结束')
  56. break
  57. # 捕获错误
  58. try:
  59. findNews()
  60. sendMsg()
  61. except TypeError:
  62. print('没有发现新消息...', time.time())
  63. pyautogui.alert(text='Python程序已结束!', title='提示', button='好的')
  64. print("程序已结束!")

以上就是基于chatgpt的微信自动回复功能如何实现的详细内容,更多关于基于chatgpt的微信自动回复功能如何实现的资料请关注九品源码其它相关文章!