xhcoding / emacs-aichat

AI Chat in Emacs, including OpenAI and Bing Chat
62 stars 8 forks source link

能否增加几个小功能 #6

Closed luyajun01 closed 1 year ago

luyajun01 commented 1 year ago

老哥,你这包实在太优秀了!

我是从懒猫那边的mind-wave过来,很喜欢这个包的网页和视频摘要功能,由于本人对lisp语言一窍不通,所以请教了new bing,也参考了mind-wave包的实现方法,它给出了以下代码:

;; aichat-bingai-summarize-webpage
(defun aichat-bingai-summarize-webpage (said)
  "Summarize the webpage content of SAID using new bing."
  (interactive "sEnter a webpage URL: ")
  (let ((query (format "Your task is to summarize %s the text I give you in up to seven concise bulletpoints and start with a short, high-quality summary. Pick a suitable emoji for every bullet point. Your response should be in Chinese. Use the following text:" said)))
    (aichat-bingai-conversation
     query
     :on-success
     (lambda (msg)
       (let ((summary (aichat-bingai-message-type-2-text msg)))
         (message "Summary: %s" summary)))
     :on-error
     (lambda (err)
       (message "Error: %s" err)))))

这代码也能跑,但是可惜网页摘要信息是显示在message buffer,我想把网页摘要信息显示在aichat.md buffer,这样方便后面粘贴复制。

另外,按照这个逻辑,也实现了英文转中文的函数。这个函数的问题跟上一个一样,信息只能显示在message buffer。

(defun aichat-bingai-translate-to-chinese (said)
  "Translate input to Chinese using new bing."
  (interactive "s请翻译: ")
  (let ((query (format "我希望你能担任英语翻译、拼写校对和修辞改进的角色。我会用任何语言和你交流,你会识别语言,将其翻译并用更为优美和精炼的中文回答我。请仅回答更正和改进的部分,不要写解释。我的第一句话是 %s,请翻译它。" said)))
    (aichat-bingai-conversation
     query
     :on-success
     (lambda (msg)
       (let ((summary (aichat-bingai-message-type-2-text msg)))
         (message "翻译成: %s" summary)))
     :on-error
     (lambda (err)
       (message "Error: %s" err)))))

有几个请求:

1.能否帮我将这2个函数的输出信息显示在aichat.md buffer上。当然如果优化下这代码就更好了,目前的代码实在不优雅。

2.我还对mind-wave包中的视频摘要功能很感兴趣,不知道emacs-aichat能否实现这个功能。

xhcoding commented 1 year ago

要显示到 aichat.md ,直接在代码里调用 aichat-bingai-chat 函数就可以了

(defun aichat-bingai-translate-to-chinese (said)
  "Translate input to Chinese using new bing."
  (interactive "s请翻译: ")
  (let ((query (format "我希望你能担任英语翻译、拼写校对和修辞改进的角色。我会用任何语言和你交流,你会识别语言,将其翻译并用更为优美和精炼的中文回答我。请仅回答更正和改进的部分,不要写解释。我的第一句话是 %s,请翻译它。" said)))
    (aichat-bingai-chat query)))

emacs-aichat 还有两个命令,可以自定义 prompt,看一下是不是你想要的

https://github.com/xhcoding/emacs-aichat/blob/main/README.zh-CN.org#%E5%91%BD%E4%BB%A4

视频功能我有空研究下

luyajun01 commented 1 year ago

要显示到 aichat.md ,直接在代码里调用 aichat-bingai-chat 函数就可以了

(defun aichat-bingai-translate-to-chinese (said)
  "Translate input to Chinese using new bing."
  (interactive "s请翻译: ")
  (let ((query (format "我希望你能担任英语翻译、拼写校对和修辞改进的角色。我会用任何语言和你交流,你会识别语言,将其翻译并用更为优美和精炼的中文回答我。请仅回答更正和改进的部分,不要写解释。我的第一句话是 %s,请翻译它。" said)))
    (aichat-bingai-chat query)))

emacs-aichat 还有两个命令,可以自定义 prompt,看一下是不是你想要的

https://github.com/xhcoding/emacs-aichat/blob/main/README.zh-CN.org#%E5%91%BD%E4%BB%A4

视频功能我有空研究下

厉害了,确实是这样的。

emacs-aichat 还有两个命令,可以自定义 prompt,看一下是不是你想要的

应该是,就不知道咋用,回头有空研究下。大佬方便的在readme里面多加几个使用样例呀,这包好多西还是挺多的。

视频这块我目前的判断是直接用bing ai好像做不了。需要解析视频网站的字幕信息。当然,大佬回头有新的实现路径烦请告知。

最后,大佬NB。

xhcoding commented 1 year ago

重新实现了一下用户自定义 prompt 的逻辑,参考文档:

https://github.com/xhcoding/emacs-aichat/blob/main/README.zh-CN.org#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%9B%BA%E5%AE%9A%E6%8F%90%E9%97%AE%E6%96%B9%E5%BC%8F