Skip to content

Commit

Permalink
feat: 支持命令查看provider
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Dec 10, 2023
1 parent 7b051d5 commit 37d62f9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
目前支持的逆向库及使用方式如下, 下方所述文件保存位置均为主程序`config.py`同目录,若无此文件,请自行创建:

<details>
<summary>ChatGPT网页版</summary>
<summary>ChatGPT网页版(暂不可用)</summary>

本插件默认使用的逆向库,使用方法请参考配置文件注释。
使用的是 [acheong08/ChatGPT](https://github.com/acheong08/ChatGPT)
Expand Down Expand Up @@ -109,6 +109,11 @@ output_references = False

接入[xtekky/gpt4free](https://github.com/xtekky/gpt4free)自动从数个平台选择可用的 GPT-4,**无需鉴权**,但很不稳定,仅需要在`revcfg.py`中修改`reverse_lib`的值为`xtekky/gpt4free`即可。

#### 配置

- gpt4free 提供了多个渠道,默认情况下程序会自动测试并选择可用的渠道,可以在 `revcfg.py` 中指定要使用的渠道和要排除的渠道
- 向机器人发送 `!provider ls` 来查看所有支持设置的渠道, 发送 `!provider` 查看当前使用的渠道

</details>

<br/>
Expand Down
4 changes: 2 additions & 2 deletions pkg/process/impls/gpt4free.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create_instance() -> tuple[RevLibInterface, bool, dict]:

@classmethod
def select_provider(cls):
logging.debug("[rev] 测试并选择provider")
logging.info("[rev] 测试并选择provider,如果某个provider测试过久,可以在revcfg.py中将其排除")

from g4f.Provider import __all__ as providers

Expand All @@ -46,7 +46,7 @@ def select_provider(cls):
if provider in exclude:
continue

logging.debug("[rev] 测试provider: {}".format(provider))
logging.info("[rev] 测试provider: {}".format(provider))
provider = getattr(g4f.Provider, provider)
try:
response = g4f.ChatCompletion.create(
Expand Down
19 changes: 19 additions & 0 deletions pkg/process/proccmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +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
import plugins.revLibs.pkg.process.impls.gpt4free as gpt4free


def process_command(session_name: str, **kwargs) -> str:
Expand Down Expand Up @@ -109,4 +110,22 @@ def process_command(session_name: str, **kwargs) -> str:
else:
reply_message = "仅当使用New Bing逆向库时可切换风格"

elif cmd == "provider":
if revss.__rev_interface_impl_class__ == gpt4free.GPT4FreeImpl:
if len(params) >= 1:
if params[0] == 'ls':
from g4f.Provider import __all__ as providers
providers = providers.copy()
reply_message = "适配器列表:\n"
for adapter in providers:
reply_message += " - {}\n".format(adapter)
reply_message = reply_message[:-1]
else:
if gpt4free.GPT4FreeImpl.use_provider is None:
reply_message = "当前未选择适配器,第一次对话时将测试并选择适配器"
else:
reply_message = "当前使用的适配器: {}".format(gpt4free.GPT4FreeImpl.use_provider)
else:
reply_message = "仅当使用gpt4free逆向库时可查看适配器"

return reply_message
2 changes: 1 addition & 1 deletion revcfg-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
# 所有适配器列表可以在
# https://github.com/xtekky/gpt4free/blob/main/g4f/Provider/__init__.py
# 中找到
# 也可以再启动机器人之后,发送命令 !provider 列出所有适配器
# 也可以再启动机器人之后,发送命令 `!provider ls` 列出所有适配器
#
# 注意:设置此字段可能会影响可用性,请确认指定的适配器可用
g4f_use_adapters = []
Expand Down

0 comments on commit 37d62f9

Please sign in to comment.