Skip to content

Commit

Permalink
Merge 923eec6 into b194b6d
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko authored Jul 13, 2024
2 parents b194b6d + 923eec6 commit c88f87a
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 28 deletions.
10 changes: 7 additions & 3 deletions applogic/chatglm.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ func (app *App) ChatHandlerGlm(w http.ResponseWriter, r *http.Request) {
// 添加用户历史到总历史中
history = append(history, userHistory...)
} else {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
var systemHistory []structs.Message
if promptstr != "" {
systemHistory, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
history = append(history, systemHistory...)
}
}

Expand Down
15 changes: 7 additions & 8 deletions applogic/chatgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ func (app *App) ChatHandlerChatgpt(w http.ResponseWriter, r *http.Request) {
// 添加用户历史到总历史中
history = append(history, userHistory...)
} else {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
var systemHistory []structs.Message
if promptstr != "" {
systemHistory, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
history = append(history, systemHistory...)
}
}

Expand Down Expand Up @@ -255,11 +259,6 @@ func (app *App) ChatHandlerChatgpt(w http.ResponseWriter, r *http.Request) {

// 获取代理服务器地址
proxyURL := config.GetProxy(promptstr)
if err != nil {
http.Error(w, fmtf.Sprintf("Failed to get proxy: %v", err), http.StatusInternalServerError)
return
}

client := &http.Client{}

// 检查是否有有效的代理地址
Expand Down
10 changes: 7 additions & 3 deletions applogic/ernie.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ func (app *App) ChatHandlerErnie(w http.ResponseWriter, r *http.Request) {
// 添加用户历史到总历史中
history = append(history, userHistory...)
} else {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
var systemHistory []structs.Message
if promptstr != "" {
systemHistory, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
history = append(history, systemHistory...)
}
}

Expand Down
10 changes: 7 additions & 3 deletions applogic/hunyuan.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,13 @@ func (app *App) ChatHandlerHunyuan(w http.ResponseWriter, r *http.Request) {
// 添加用户历史到总历史中
history = append(history, userHistory...)
} else {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
var systemHistory []structs.Message
if promptstr != "" {
systemHistory, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
history = append(history, systemHistory...)
}
}

Expand Down
10 changes: 7 additions & 3 deletions applogic/rwkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,13 @@ func (app *App) ChatHandlerRwkv(w http.ResponseWriter, r *http.Request) {
// 添加用户历史到总历史中
history = append(history, userHistory...)
} else {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
var systemHistory []structs.Message
if promptstr != "" {
systemHistory, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
history = append(history, systemHistory...)
}
}

Expand Down
10 changes: 7 additions & 3 deletions applogic/tongyiqianwen.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {
// 添加用户历史到总历史中
history = append(history, userHistory...)
} else {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
var systemHistory []structs.Message
if promptstr != "" {
systemHistory, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
history = append(history, systemHistory...)
}
}

Expand Down
10 changes: 7 additions & 3 deletions applogic/yuanqi.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ func (app *App) ChatHandlerYuanQi(w http.ResponseWriter, r *http.Request) {
// 添加用户历史到总历史中
history = append(history, userHistory...)
} else {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
var systemHistory []structs.Message
if promptstr != "" {
systemHistory, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
history = append(history, systemHistory...)
}
}

Expand Down
70 changes: 70 additions & 0 deletions docs/在telegram快速部署的教程.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 在 Telegram 部署 LLM 聊天机器人教程

本教程将指导你使用 `gensokyo-telegram``gensokyo-llm` 在 Telegram 上部署一个 LLM 聊天机器人。

## 准备工作

### 下载 gensokyo-telegram

首先,下载 `gensokyo-telegram`
- [gensokyo-telegram GitHub 仓库](https://github.com/Hoshinonyaruko/gensokyo-telegram)

### 创建 Telegram 机器人

1. 打开 Telegram 应用。
2. 搜索 `BotFather`
3. 创建一个新的机器人,并按照 `BotFather` 提供的指引完成设置。

你将收到如下消息:

```
Done! Congratulations on your new bot. You will find it at t.me/Txxx. You can now add a description, about section, and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.
```

**重要**:保护好你的 HTTP API Token,它将用于接下来的步骤。

### 访问和配置机器人

- 访问你的机器人链接:[t.me/Txxx](t.me/Txxx)
- 使用收到的 `<<Your Token>>` 作为你的 `botToken`

## 配置 gensokyo-telegram

1. 首次运行 `.exe` 文件,按提示释放脚本。
2. 运行 `.bat` 文件。
3. 打开 `config.yml` 配置文件,进行以下设置:
- `botToken`: 填入你的 `botToken`
- `useNgrok`: 设置为 `true`
- `webHookPath`: 保持为空 (`""`)。
- `customcert`: 设置为 `false`

### 配置 ngrok

1. 访问 [ngrok 官网](https://dashboard.ngrok.com/get-started/setup/windows),并注册或登录。
2. 在获取开始(getting started)部分找到 `your authtoken`
3.`authtoken` 输入到 `ngrokKey` 配置中。
4. 设置 `highway``true`
5. 设置 `sendDirectResponse``true`

## 配置 gensokyo-llm

1.`docs/中级-轻松对接豆包大模型.md` 完成豆包模型的配置。
2. 确保 `gensokyo-llm``iPWhiteList` 包含 `127.0.0.1`
3. 使用默认端口 `46233`

### 连接 gensokyo-telegram 和 gensokyo-llm

1. 打开 `gensokyo-telegram``yml` 配置文件。
2. 添加 `gensokyo-llm` 的反向 WebSocket 地址到 `ws_address` 配置:
```yaml
ws_address: ["ws://127.0.0.1:46233"]
```
3. 在 `config.yml` 的 `systemPrompt` 配置项中配置好提示词。

### 运行和测试

1. 双击运行 `gensokyo-llm`。
2. 双击运行你已配置好的 `gensokyo-telegram`。
3. 发送信息给你的 bot,检查是否能成功接收信息。

![](/pic/5.png)
2 changes: 2 additions & 0 deletions docs/常见问题.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Received response:access denied
请检查iPWhiteList,或者设置accessKey并且在http请求增加参数access_token=xxxx
Binary file added pic/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ _✨ 适用于Gensokyo以及Onebotv11的大模型一键端 ✨_

[中级-大模型api配置示例-国际篇](/docs/中级-大模型api配置示例-国际篇.md)

[上手即用-在Telegram快速部署](/docs/在telegram快速部署的教程.md)

---

## 特性
Expand Down
4 changes: 2 additions & 2 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ settings:
lotus : "" #当填写另一个gensokyo-llm的http地址时,将请求另一个的conversation端点,实现多个llm不需要多次配置,简化配置,单独使用请忽略留空.例:http://192.168.0.1:12345(包含http头和端口)
pathToken : "" #gensokyo正向http-api的access_token(是onebotv11标准的)
apiType : 0 #0=混元 1=文心(文心平台包含了N种模型...) 2=gpt 3=rwkv 4=通义千问 5=智谱AI 6=腾讯元器
iPWhiteList : ["192.168.0.102"] #接口调用,安全ip白名单,gensokyo的ip地址,或调用api的程序的ip地址
iPWhiteList : ["192.168.0.101","127.0.0.1"] #接口调用,安全ip白名单,gensokyo的ip地址,或调用api的程序的ip地址
accessKey : "" #白名单ip未符合时,校验url参数&access_token=xxxx是否匹配
systemPrompt : [""] #人格提示词,或多个随机
systemPrompt : ["我是一个助手."] #人格提示词,或多个随机
firstQ : [""] #强化思想钢印,在每次对话的system之前固定一个QA,需都填写内容,会增加token消耗,可一定程度提高人格提示词效果,或抵抗催眠
firstA : [""] #强化思想钢印,在每次对话的system之前固定一个QA,需都填写内容,会增加token消耗,可一定程度提高人格提示词效果,或抵抗催眠
secondQ : [""] #可空
Expand Down

0 comments on commit c88f87a

Please sign in to comment.