Skip to content

Commit bd9aade

Browse files
fix(docs):多份文档汉译英并整理 (#8001)
* docs(en): translate plugin-platform-adapter.md from Chinese to English * docs(en): translate plugin-platform-adapter.md from Chinese to English * Update ppio.md * Update provider-lmstudio.md * Update function-calling.md * Update skills.md * Update ai.md * Update simple.md * Update mcp.md * Update config.mjs kook * fix(docs): fix MessageSesion import path in platform adapter example Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 4bcaaab commit bd9aade

10 files changed

Lines changed: 102 additions & 120 deletions

File tree

docs/.vitepress/config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ export default defineConfig({
343343
{ text: "Mattermost", link: "/mattermost" },
344344
{ text: "Misskey", link: "/misskey" },
345345
{ text: "Discord", link: "/discord" },
346+
{ text: "KOOK", link: "/kook" },
346347
{
347348
text: "Satori",
348349
base: "/en/platform/satori",
@@ -357,7 +358,6 @@ export default defineConfig({
357358
collapsed: false,
358359
items: [
359360
{ text: "Matrix", link: "/matrix" },
360-
{ text: "KOOK", link: "/kook" },
361361
{ text: "VoceChat", link: "/vocechat" },
362362
],
363363
},

docs/en/dev/plugin-platform-adapter.md

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
outline: deep
33
---
44

5-
# 开发一个平台适配器
5+
# Developing a Platform Adapter
66

7-
AstrBot 支持以插件的形式接入平台适配器,你可以自行接入 AstrBot 没有的平台。如飞书、钉钉甚至是哔哩哔哩私信、Minecraft
7+
AstrBot supports integrating platform adapters in plugin form, allowing you to connect platforms that AstrBot does not natively support — such as Lark, DingTalk, Bilibili private messages, or even Minecraft.
88

9-
我们以一个平台 `FakePlatform` 为例展开讲解。
9+
We will use a platform called `FakePlatform` as an example.
1010

11-
首先,在插件目录下新增 `fake_platform_adapter.py` `fake_platform_event.py` 文件。前者主要是平台适配器的实现,后者是平台事件的定义。
11+
First, add `fake_platform_adapter.py` and `fake_platform_event.py` to your plugin directory. The former handles the platform adapter implementation, while the latter defines the platform event.
1212

13-
## 平台适配器
13+
## Platform Adapter
1414

15-
假设 FakePlatform 的客户端 SDK 是这样:
15+
Assume FakePlatform's client SDK looks like this:
1616

1717
```py
1818
import asyncio
1919

2020
class FakeClient():
21-
'''模拟一个消息平台,这里 5 秒钟下发一个消息'''
21+
'''Simulates a messaging platform that sends a message every 5 seconds'''
2222
def __init__(self, token: str, username: str):
2323
self.token = token
2424
self.username = username
@@ -29,101 +29,102 @@ class FakeClient():
2929
await asyncio.sleep(5)
3030
await getattr(self, 'on_message_received')({
3131
'bot_id': '123',
32-
'content': '新消息',
32+
'content': 'new message',
3333
'username': 'zhangsan',
3434
'userid': '123',
3535
'message_id': 'asdhoashd',
3636
'group_id': 'group123',
3737
})
3838

3939
async def send_text(self, to: str, message: str):
40-
print('发了消息:', to, message)
40+
print('Message sent:', to, message)
4141

4242
async def send_image(self, to: str, image_path: str):
43-
print('发了消息:', to, image_path)
43+
print('Image sent:', to, image_path)
4444
```
4545

46-
我们创建 `fake_platform_adapter.py`
46+
Now create `fake_platform_adapter.py`:
4747

4848
```py
4949
import asyncio
5050

5151
from astrbot.api.platform import Platform, AstrBotMessage, MessageMember, PlatformMetadata, MessageType
5252
from astrbot.api.event import MessageChain
53-
from astrbot.api.message_components import Plain, Image, Record # 消息链中的组件,可以根据需要导入
54-
from astrbot.core.platform.astr_message_event import MessageSesion
53+
from astrbot.api.message_components import Plain, Image, Record # Message chain components, import as needed
54+
from astrbot.core.platform.message_session import MessageSesion
5555
from astrbot.api.platform import register_platform_adapter
5656
from astrbot import logger
5757
from .client import FakeClient
5858
from .fake_platform_event import FakePlatformEvent
5959

60-
# 注册平台适配器。第一个参数为平台名,第二个为描述。第三个为默认配置。
61-
@register_platform_adapter("fake", "fake 适配器", default_config_tmpl={
60+
# Register the platform adapter. First param: platform name, second: description, third: default config.
61+
@register_platform_adapter("fake", "fake adapter", default_config_tmpl={
6262
"token": "your_token",
6363
"username": "bot_username"
6464
})
6565
class FakePlatformAdapter(Platform):
6666

6767
def __init__(self, platform_config: dict, platform_settings: dict, event_queue: asyncio.Queue) -> None:
6868
super().__init__(event_queue)
69-
self.config = platform_config # 上面的默认配置,用户填写后会传到这里
70-
self.settings = platform_settings # platform_settings 平台设置。
69+
self.config = platform_config # The default config above; filled in by the user and passed here
70+
self.settings = platform_settings # platform_settings: platform settings
7171

7272
async def send_by_session(self, session: MessageSesion, message_chain: MessageChain):
73-
# 必须实现
73+
# Must be implemented
7474
await super().send_by_session(session, message_chain)
7575

7676
def meta(self) -> PlatformMetadata:
77-
# 必须实现,直接像下面一样返回即可。
77+
# Must be implemented. Simply return as shown below.
7878
return PlatformMetadata(
7979
"fake",
80-
"fake 适配器",
80+
"fake adapter",
8181
)
8282

8383
async def run(self):
84-
# 必须实现,这里是主要逻辑。
84+
# Must be implemented. This is the main logic.
8585

86-
# FakeClient 是我们自己定义的,这里只是示例。这个是其回调函数
86+
# FakeClient is defined by us — this is just an example. This is its callback function.
8787
async def on_received(data):
8888
logger.info(data)
89-
abm = await self.convert_message(data=data) # 转换成 AstrBotMessage
89+
abm = await self.convert_message(data=data) # Convert to AstrBotMessage
9090
await self.handle_msg(abm)
9191

92-
# 初始化 FakeClient
92+
# Initialize FakeClient
9393
self.client = FakeClient(self.config['token'], self.config['username'])
9494
self.client.on_message_received = on_received
95-
await self.client.start_polling() # 持续监听消息,这是个堵塞方法。
95+
await self.client.start_polling() # Continuously listens for messages; this is a blocking call.
9696

9797
async def convert_message(self, data: dict) -> AstrBotMessage:
98-
# 将平台消息转换成 AstrBotMessage
99-
# 这里就体现了适配程度,不同平台的消息结构不一样,这里需要根据实际情况进行转换。
98+
# Convert the platform message to AstrBotMessage.
99+
# The degree of adaptation is reflected here. Different platforms have different message
100+
# structures; convert accordingly.
100101
abm = AstrBotMessage()
101-
abm.type = MessageType.GROUP_MESSAGE # 还有 friend_message,对应私聊。具体平台具体分析。重要!
102-
abm.group_id = data['group_id'] # 如果是私聊,这里可以不填
103-
abm.message_str = data['content'] # 纯文本消息。重要!
104-
abm.sender = MessageMember(user_id=data['userid'], nickname=data['username']) # 发送者。重要!
105-
abm.message = [Plain(text=data['content'])] # 消息链。如果有其他类型的消息,直接 append 即可。重要!
106-
abm.raw_message = data # 原始消息。
102+
abm.type = MessageType.GROUP_MESSAGE # Also friend_message for private chats. Analyze per platform. Important!
103+
abm.group_id = data['group_id'] # Can be omitted for private chats
104+
abm.message_str = data['content'] # Plain text message. Important!
105+
abm.sender = MessageMember(user_id=data['userid'], nickname=data['username']) # Sender. Important!
106+
abm.message = [Plain(text=data['content'])] # Message chain. Append other message types as needed. Important!
107+
abm.raw_message = data # Raw message.
107108
abm.self_id = data['bot_id']
108-
abm.session_id = data['userid'] # 会话 ID。重要!
109-
abm.message_id = data['message_id'] # 消息 ID
109+
abm.session_id = data['userid'] # Session ID. Important!
110+
abm.message_id = data['message_id'] # Message ID.
110111

111112
return abm
112113

113114
async def handle_msg(self, message: AstrBotMessage):
114-
# 处理消息
115+
# Handle the message
115116
message_event = FakePlatformEvent(
116117
message_str=message.message_str,
117118
message_obj=message,
118119
platform_meta=self.meta(),
119120
session_id=message.session_id,
120121
client=self.client
121122
)
122-
self.commit_event(message_event) # 提交事件到事件队列。不要忘记!
123+
self.commit_event(message_event) # Submit the event to the event queue. Don't forget this!
123124
```
124125

125126

126-
`fake_platform_event.py`
127+
`fake_platform_event.py`:
127128

128129
```py
129130
from astrbot.api.event import AstrMessageEvent, MessageChain
@@ -138,28 +139,28 @@ class FakePlatformEvent(AstrMessageEvent):
138139
self.client = client
139140

140141
async def send(self, message: MessageChain):
141-
for i in message.chain: # 遍历消息链
142-
if isinstance(i, Plain): # 如果是文字类型的
142+
for i in message.chain: # Iterate over the message chain
143+
if isinstance(i, Plain): # If it's a text message
143144
await self.client.send_text(to=self.get_sender_id(), message=i.text)
144-
elif isinstance(i, Image): # 如果是图片类型的
145+
elif isinstance(i, Image): # If it's an image
145146
img_url = i.file
146147
img_path = ""
147-
# 下面的三个条件可以直接参考一下。
148+
# The three conditions below can be used as a reference.
148149
if img_url.startswith("file:///"):
149150
img_path = img_url[8:]
150151
elif i.file and i.file.startswith("http"):
151152
img_path = await download_image_by_url(i.file)
152153
else:
153154
img_path = img_url
154155

155-
# 请善于 Debug!
156+
# Make good use of debugging!
156157

157158
await self.client.send_image(to=self.get_sender_id(), image_path=img_path)
158159

159-
await super().send(message) # 需要最后加上这一段,执行父类的 send 方法。
160+
await super().send(message) # Must be called at the end to invoke the parent class's send method.
160161
```
161162

162-
最后,main.py 只需这样,在初始化的时候导入 fake_platform_adapter 模块。装饰器会自动注册。
163+
Finally, in `main.py`, simply import the `fake_platform_adapter` module during initialization. The decorator will handle registration automatically.
163164

164165
```py
165166
from astrbot.api.star import Context, Star
@@ -169,17 +170,17 @@ class MyPlugin(Star):
169170
from .fake_platform_adapter import FakePlatformAdapter # noqa
170171
```
171172

172-
搞好后,运行 AstrBot
173+
Once set up, run AstrBot:
173174

174175
![image](https://files.astrbot.app/docs/source/images/plugin-platform-adapter/QQ_1738155926221.png)
175176

176-
这里出现了我们创建的 fake
177+
The `fake` adapter we created now appears here.
177178

178179
![image](https://files.astrbot.app/docs/source/images/plugin-platform-adapter/QQ_1738155982211.png)
179180

180-
启动后,可以看到正常工作:
181+
After starting, you can see it working correctly:
181182

182183
![image](https://files.astrbot.app/docs/source/images/plugin-platform-adapter/QQ_1738156166893.png)
183184

184185

185-
有任何疑问欢迎加群询问~
186+
If you have any questions, feel free to join the community group and ask~

docs/en/dev/star/guides/ai.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ curr_cid = await conv_mgr.get_curr_conversation_id(uid)
257257
conversation = await conv_mgr.get_conversation(uid, curr_cid) # Conversation
258258
```
259259

260-
::: details Conversation 类型定义
260+
::: details Conversation Type Definition
261261

262262
```py
263263
@dataclass
@@ -438,7 +438,7 @@ persona_mgr = self.context.persona_manager
438438
- **Returns**
439439
`Personality` – Default persona object in v3 format
440440

441-
::: details Persona / Personality 类型定义
441+
::: details Persona / Personality Type Definition
442442

443443
```py
444444

docs/en/dev/star/guides/simple.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,3 @@ Explanation:
4040
4141
All handler functions must be written within the plugin class. To keep content concise, in subsequent sections, we may omit the plugin class definition.
4242
```
43-
44-
解释如下:
45-
46-
- 插件需要继承 `Star` 类。
47-
- `Context` 类用于插件与 AstrBot Core 交互,可以由此调用 AstrBot Core 提供的各种 API。
48-
- 具体的处理函数 `Handler` 在插件类中定义,如这里的 `helloworld` 函数。
49-
- `AstrMessageEvent` 是 AstrBot 的消息事件对象,存储了消息发送者、消息内容等信息。
50-
- `AstrBotMessage` 是 AstrBot 的消息对象,存储了消息平台下发的消息的具体内容。可以通过 `event.message_obj` 获取。
51-
52-
> [!TIP]
53-
>
54-
> `Handler` 一定需要在插件类中注册,前两个参数必须为 `self` 和 `event`。如果文件行数过长,可以将服务写在外部,然后在 `Handler` 中调用。
55-
>
56-
> 插件类所在的文件名需要命名为 `main.py`。
57-
58-
所有的处理函数都需写在插件类中。为了精简内容,在之后的章节中,我们可能会忽略插件类的定义。

docs/en/providers/302ai.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# 接入 302.AI
1+
# Connect 302.AI
22

3-
302.AI 是企业级 AI 应用平台,支持快捷接入全球各类 AI 模型。
3+
[302.AI](https://302.ai) is an enterprise-grade AI application platform that provides quick access to a wide range of AI models worldwide.
44

5-
## 使用
5+
## Getting Started
66

7-
点击[此链接](https://share.302.ai/rr1M3l) 注册账户。
7+
Click [this link](https://share.302.ai/rr1M3l) to register an account.
88

9-
注册完毕之后,点击[此链接](https://302.ai/apis/)选择需要接入的模型。
9+
After registering, click [this link](https://302.ai/apis/) to select the model you want to use.
1010

11-
根据需求,进入[此链接](https://dash.302.ai/charge) 充值对应的金额。
11+
If needed, visit [this link](https://dash.302.ai/charge) to top up your account balance.
1212

13-
## 接入
13+
## Connect
1414

15-
打开 AstrBot 控制台 -> 服务提供商页面,点击新增提供商,找到并点击 `302.AI`(需要版本 >= 3.5.18)
15+
Open the AstrBot dashboard → Service Providers page, click **Add Provider**, find and click `302.AI` (requires version >= 3.5.18).
1616

17-
修改 ID,并将 API Key 和模型名称填入对话框表单,点击保存,即可完成创建。
17+
Set an ID, fill in the API Key and model name in the dialog form, then click **Save** to complete the setup.
1818

19-
## 使用
19+
## Usage
2020

21-
对机器人输入 `/provider` 指令,将提供商切换到刚刚添加的 302.AI 提供商,即可使用。
21+
Send the `/provider` command to the bot to switch to the 302.AI provider you just added.

docs/en/providers/ppio.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
# 接入 PPIO 派欧云
1+
# Connect PPIO Cloud
22

3-
PPIO 派欧云是中国领先的独立分布式云计算服务商,您可以在派欧云上使用稳定、低价甚至免费的模型服务。
3+
PPIO Cloud is a leading independent distributed cloud computing provider in China, offering stable, affordable, and even free model services.
44

5-
## 准备
5+
## Preparation
66

7-
打开 [PPIO 派欧云官网](https://ppio.cn/user/register?invited_by=AIOONE),并注册账户(通过此链接注册的账户将会获得 15 元人民币的代金券)。
7+
Open the [PPIO Cloud website](https://ppio.cn/user/register?invited_by=AIOONE) and register an account (accounts registered through this link will receive a ¥15 voucher).
88

9-
进入 [模型 API 服务](https://ppio.cn/model-api/console),找到你想接入的模型。你可以通过筛选器选择不同厂商或者免费的模型。
9+
Go to [Model API Service](https://ppio.cn/model-api/console) and find the model you want to use. You can filter by provider or select free models.
1010

1111
![image](https://files.astrbot.app/docs/source/images/ppio/image-1.png)
1212

13-
找到你想要接入的模型后,点击模型卡片,侧边会展开一个模型详情卡片,找到下方的 API 接入指南,如果您还没创建过 Key 可以点击创建。
13+
Once you find the model, click its card to expand a detail panel on the right. Scroll down to the API integration guide — if you haven't created a key yet, click to create one.
1414

1515
![image](https://files.astrbot.app/docs/source/images/ppio/image-3.png)
1616

17-
打开 AstrBot 控制台 -> 服务提供商页面,点击新增提供商,找到并点击 `PPIO派欧云`(需要版本 >= 3.5.10,旧版本也可使用,见下文)。
17+
Open the AstrBot dashboard → Service Providers page, click **Add Provider**, find and click `PPIO Cloud` (requires version >= 3.5.10; older versions are also supported, see below).
1818

1919
![image](https://files.astrbot.app/docs/source/images/ppio/image.png)
2020

21-
API Key 和模型名称填入对话框表单,点击保存,即可完成创建。
21+
Fill in the API Key and model name in the dialog form, then click **Save** to complete the setup.
2222

2323
> [!TIP]
24-
> 如果您是 AstrBot 旧版本(< 3.5.10)的用户,请打开 AstrBot 控制台 -> 服务提供商页面,点击新增提供商,找到 `OpenAI`,点击进入。
25-
> 1. ID 命名为 `ppio`(随意)
26-
> 2. 然后将 `API Base URL` 设置为 `https://api.ppinfra.com/v3/openai`
27-
> 3. 然后将 API Key 和模型名称填入对话框表单,点击保存,即可完成创建。
24+
> If you are using an older version of AstrBot (< 3.5.10), open the AstrBot dashboard → Service Providers page, click **Add Provider**, find `OpenAI`, and click to enter.
25+
> 1. Set the ID to `ppio` (any name works)
26+
> 2. Set `API Base URL` to `https://api.ppinfra.com/v3/openai`
27+
> 3. Fill in the API Key and model name in the dialog form, then click **Save** to complete the setup.
2828
29+
## Usage
2930

30-
## 使用
31+
Send the `/provider` command to the bot to switch to the PPIO Cloud provider you just added.
3132

32-
对机器人输入 `/provider` 指令,将提供商切换到刚刚添加的 PPIO 派欧云提供商,即可使用。
33+
## FAQ
3334

34-
## 常见问题
35-
36-
#### 显示 `400` 错误
35+
#### `400` Error
3736

3837
```log
3938
Error code: 400 - {'code': 400, 'message': '"auto" tool choice requires --enable-auto-tool-choice and --tool-call-parser to be set', 'type': 'BadRequestError'}
4039
```
4140

42-
43-
请暂时使用 `/tool off_all` 禁用所有的函数调用工具即可使用,或者换用其他模型。
41+
Temporarily disable all function calling tools with `/tool off_all`, or switch to a different model.

0 commit comments

Comments
 (0)