Skip to content

Commit

Permalink
feat: 添加复制chatgpt回复功能 (pengzhile#172)
Browse files Browse the repository at this point in the history
* feat: 添加复制chatgpt回复功能

* feat: 更新README.md
  • Loading branch information
c2ray authored Apr 19, 2023
1 parent fec4daf commit 106922d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
* `/new` 直接开启一个新会话。
* `/del` 删除当前会话,回到会话选择界面。
* `/token` 打印当前的`Access Token`,也许你用得上,但不要泄露。
* `/copy` 复制`ChatGPT`上一次回复的内容到剪贴板。
* `/copy_code` 复制`ChatGPT`上一次回复的代码到剪贴板
* `/clear` 清屏,应该不用解释。
* `/version` 打印`Pandora`的版本信息。
* `/exit` 退出`潘多拉`
Expand Down Expand Up @@ -203,4 +205,3 @@
* 因为之后`ChatGPT`的API变动,我可能不会跟进修复。
* 喜欢的可以给颗星,都是老朋友了。
* 不影响`PHP是世界上最好的编程语言!`

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ flask-cors~=3.0.10
waitress~=2.1.2
loguru~=0.6.0
sentry-sdk~=1.17.0
pyjwt[crypto]~=2.6.0
pyjwt[crypto]~=2.6.0
pyperclip~=1.8.2
25 changes: 25 additions & 0 deletions src/pandora/bots/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import uuid

import pyperclip
from rich.prompt import Prompt, Confirm

from .. import __version__
Expand Down Expand Up @@ -105,6 +106,10 @@ def __process_command(self, command):
self.__print_access_token()
elif '/cls' == command or '/clear' == command:
self.__clear_screen()
elif '/copy' == command or '/cp' == command:
self.__copy_text()
elif '/copy_code' == command or "/cp_code" == command:
self.__copy_code()
elif '/ver' == command or '/version' == command:
self.__print_version()
else:
Expand All @@ -123,6 +128,8 @@ def __print_usage():
print('/new\t\tStart a new conversation.')
print('/del\t\tDelete the current conversation.')
print('/token\t\tPrint your access token.')
print('/copy\t\tCopy the last response to clipboard.')
print('/copy_code\t\tCopy code from last response.')
print('/clear\t\tClear your screen.')
print('/version\tPrint the version of Pandora.')
print('/exit\t\tExit Pandora.')
Expand Down Expand Up @@ -467,3 +474,21 @@ def __choice_model(self):
return self.__choice_model()

return models[int(choice) - 1]

def __copy_text(self):
pyperclip.copy(self.state.chatgpt_prompt.prompt)
Console.info("已将上一次返回结果复制到剪切板。")
pass

def __copy_code(self):
text = self.state.chatgpt_prompt.prompt
pattern = re.compile(r'```.*\s([\s\S]*?)\s```')
result = re.findall(pattern, text)
if len(result) == 0:
Console.info("未找到代码。")
return
else:
code = '\n=======================================================\n'.join(result)
pyperclip.copy(code)
Console.info("已将上一次生成的代码复制到剪切板。")
pass

0 comments on commit 106922d

Please sign in to comment.