Skip to content

Commit

Permalink
Merge pull request #90 from RockChinQ/newbing-style
Browse files Browse the repository at this point in the history
[Feat] New Bing的风格设置
  • Loading branch information
RockChinQ authored Mar 23, 2023
2 parents f4fb34b + f06c051 commit 38525d4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 24 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
得益于[QChatGPT项目](https://github.com/RockChinQ/QChatGPT)的插件功能,此插件将允许接入`ChatGPT网页版`用以替换原项目主线的GPT-3模型接口,提升回复质量。
[官方接口与ChatGPT网页版的区别?](https://github.com/RockChinQ/QChatGPT/wiki/%E5%AE%98%E6%96%B9%E6%8E%A5%E5%8F%A3%E4%B8%8EChatGPT%E7%BD%91%E9%A1%B5%E7%89%88)

## 使用方式
## 安装方式

> 若您未安装QChatGPT程序,请先查看原仓库[文档](https://github.com/RockChinQ/QChatGPT)
> 目前已支持中国主机使用,请在revcfg.py中修改openai_account字段,按照注释使用access_token方式登录
Expand All @@ -34,7 +34,7 @@
`QChatGPT`程序目录编辑`revcfg.py`文件,根据注释修改必填配置项。
配置完成后重新启动主程序以使用。

## 更换逆向库
## 选择逆向库

目前支持的逆向库及使用方式如下:

Expand Down Expand Up @@ -63,12 +63,16 @@

#### 配置

new bing逆向库默认输出参考资料, 若不需要, 请在`revcfg.py`中设置:
- new bing逆向库默认输出参考资料, 若不需要, 请在`revcfg.py`中设置:

```python
output_references = False
```

- 设置New Bing的风格

查看revcfg.py中的`new_bing_style`字段,按照说明更改。在运行期间可以通过指令`!style <风格(创意、平衡、精确)>`来更改风格。

</details>
<br/>

Expand Down
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import plugins.revLibs.pkg.process.revss as revss
import plugins.revLibs.pkg.process.procmsg as procmsg
import plugins.revLibs.pkg.process.proccmd as proccmd
from EdgeGPT import ConversationStyle

"""
接入ChatGPT的逆向库
Expand Down Expand Up @@ -59,6 +60,9 @@ def __init__(self, plugin_host: PluginHost):

import revcfg

if not hasattr(revcfg, "new_bing_style"):
setattr(revcfg, "new_bing_style", ConversationStyle.balanced)

try:
if revcfg.reverse_lib == "acheong08/ChatGPT.V1":
import plugins.revLibs.pkg.process.impls.v1impl as v1impl
Expand Down
4 changes: 3 additions & 1 deletion pkg/process/impls/edgegpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def create_instance() -> tuple[RevLibInterface, bool, dict]:
with open("cookies.json", "r", encoding="utf-8") as f:
cookies_dict = json.load(f)

return EdgeGPTImpl(cookies_dict, ConversationStyle.creative), True, cookies_dict
import revcfg

return EdgeGPTImpl(cookies_dict, revcfg.new_bing_style if hasattr(revcfg, "new_bing_style") else ConversationStyle.balanced), True, cookies_dict

def __init__(self, cookies, style):
logging.debug("[rev] 初始化接口实现,使用账户cookies: {}".format(str(cookies)[:30]))
Expand Down
75 changes: 55 additions & 20 deletions pkg/process/proccmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import plugins.revLibs.pkg.process.revss as revss
import plugins.revLibs.pkg.process.impls.v1impl as v1impl
import plugins.revLibs.pkg.process.impls.edgegpt as edgegpt


def process_command(session_name: str, **kwargs) -> str:
"""处理命令"""
Expand Down Expand Up @@ -52,26 +55,58 @@ def process_command(session_name: str, **kwargs) -> str:
"""查看每个账户的使用情况"""
import plugins.revLibs.pkg.accounts.accmgr as accmgr

reply_message = "账户列表:\n"

for account in accmgr.get_account_list():
"""
- 账户名称
"""
reply_message += "账户: {}\n - ".format(accmgr.get_account_brief_name(account))

using = False
for k in revss.__sessions__:
v: revss.RevSession = revss.__sessions__[k]
if accmgr.get_account_brief_name(v.using_account) == accmgr.get_account_brief_name(account):
reply_message += v.name + ", "
using = True
if not using:
reply_message += "未使用"
else:
reply_message = reply_message[:-2]
if revss.__rev_interface_impl_class__ == v1impl.RevInterfaceImplV1:

reply_message = "账户列表:\n"

for account in accmgr.get_account_list():
"""
- 账户名称
"""
reply_message += "账户: {}\n - ".format(accmgr.get_account_brief_name(account))

using = False
for k in revss.__sessions__:
v: revss.RevSession = revss.__sessions__[k]
if accmgr.get_account_brief_name(v.using_account) == accmgr.get_account_brief_name(account):
reply_message += v.name + ", "
using = True
if not using:
reply_message += "未使用"
else:
reply_message = reply_message[:-2]

reply_message += "\n\n"
reply_message = reply_message[:-1]
else:
reply_message = "仅当使用ChatGPT逆向库时可查看账户负载情况"
elif cmd == "style":
if revss.__rev_interface_impl_class__ == edgegpt.EdgeGPTImpl:
import revcfg
from EdgeGPT import ConversationStyle
if len(params) >= 1:

mapping = {
"创意": ConversationStyle.creative,
"平衡": ConversationStyle.balanced,
"精确": ConversationStyle.precise,
}

if params[0] not in mapping:
reply_message = "风格参数错误,可选参数: 创意, 平衡, 精确"
return reply_message

reply_message += "\n\n"
reply_message = reply_message[:-1]
setattr(revcfg, "new_bing_style", mapping[params[0]])

reply_message = "已切换到{}风格,重置会话后生效".format(params[0])
else:
current = "创意"
if getattr(revcfg, "new_bing_style") == ConversationStyle.balanced:
current = "平衡"
elif getattr(revcfg, "new_bing_style") == ConversationStyle.precise:
current = "精确"
reply_message = "当前风格为: {},可选参数: 创意, 平衡, 精确\n例如: !style 创意".format(current)
else:
reply_message = "仅当使用New Bing逆向库时可切换风格"

return reply_message
7 changes: 7 additions & 0 deletions revcfg-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
# 以分钟为单位
openai_account_resume_interval = 60

# New Bing的Style
# 请将此值设置为以下之一:
# "h3imaginative" 有创意
# "harmonyv3" 平衡
# "h3precise" 精确
new_bing_style = "harmonyv3"

# 使用New Bing时是否显示参考资料
output_references = True

Expand Down

0 comments on commit 38525d4

Please sign in to comment.