Skip to content

Commit

Permalink
feat: 基本测试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Mar 4, 2024
1 parent d2ca068 commit e26154e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions draft/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# QChatGPT 3.x 新扩展方式草案

## 背景

### 历史问题

在过去的实践中,QChatGPT 直接从 `plugins` 目录下加载所有`.py`文件,这些文件中可以自由自定义类和函数,并通过 QChatGPT 提供的 API 注册插件类。但在实践中,我们发现此种加载方式存在以下问题:

#### 设计上的

- 插件类命名和插件包(目录)命名不符,造成混乱。
- 一个插件内实际上可以注册多个插件类,未强制限定。
- 插件需要的依赖由 QChatGPT 动态安装,这对网络环境较差的用户以及使用 Docker 的情况很不友好。
- 通过源代码发布的插件代码,管理松散,不利于分发。

#### 加载逻辑上的

- 遍历插件目录下所有py模块,无统一的入口

### 未来需求

- QChatGPT 可能会以可执行文件的形式发布,这时动态安装依赖将不再可行。
- 插件的发布和管理需要更加规范和统一的方式。

## 设计

在新的扩展方案中,
9 changes: 9 additions & 0 deletions exts-src/basic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class PluginClass:

name: str

def __init__(self) -> None:
self.name = "Basic Plugin"

def get_name(self) -> str:
return self.name
9 changes: 9 additions & 0 deletions exts-src/basic/basic_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class PluginClass:

name: str

def __init__(self) -> None:
self.name = "Basic Plugin Inner"

def get_name(self) -> str:
return self.name
Binary file added exts/basic.zip
Binary file not shown.
7 changes: 7 additions & 0 deletions loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys

sys.path.insert(0, "exts/basic.zip")

import basic

print(basic.PluginClass().get_name())

0 comments on commit e26154e

Please sign in to comment.