Skip to content

Commit

Permalink
Merge pull request #100 from Cassius0924/feat-spark
Browse files Browse the repository at this point in the history
feat:支持Spark星火认知LLM
  • Loading branch information
Ashesttt authored Nov 18, 2024
2 parents 14ec532 + 567ff6a commit a176a17
Show file tree
Hide file tree
Showing 17 changed files with 769 additions and 189 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ docker-compose -f docker-compose.yml up
- [x] GitHub 趋势
- [x] 单词词语翻译(不支持定时任务)
- [x] 少数派早报
- [x] 历史上的今天
- [x] 每日环球视野
- [x] 二维码生成
- [x] 待办清单(不支持定时任务)
- [x] 人民日报 PDF
Expand Down Expand Up @@ -152,11 +152,25 @@ docker-compose -f docker-compose.yml up

### ⚙️ LLM 配置

#### 1.OpenAi

| 配置项 | 解释 | 备注 |
| --- | --- | --- |
| `openai_base_api` | OpenAI 服务的 BaseAPI | 默认为 `https://api.openai.com` |
| `openai_token` | OpenAI Token(Key) |`sk_` 开头的字符串密钥 |

#### 2.Spark(讯飞星火大模型)

##### 现免费领取Spark 4.0 Ultra,tokens: 200万,有效期:1年

获取途径:[讯飞星火大模型-AI大语言模型-星火大模型-科大讯飞](https://xinghuo.xfyun.cn/sparkapi?scr=price)

| 配置项 | 解释 | 备注 |
| ------------- | ------------------------ | ------------------------------------------------------------ |
| `spark_api` | 星火大模型服务的 BaseAPI | 默认为`https://spark-api-open.xf-yun.com/v1/chat/completions` |
| `spark_model` | 指定访问的模型版本 | lite指向Lite版本;4.0Ultra指向4.0 Ultra版本; |
| `spark_token` | 星火大模型的Token | 字符串密钥 |

### ⚙️ GitHub Webhook 配置

| 配置项 | 解释 | 备注 |
Expand Down Expand Up @@ -227,7 +241,7 @@ docker-compose -f docker-compose.yml up
日志文件存放在项目根目录下的 `logs/` 文件夹中。

默认的日志记录级别为 `INFO`,日志记录级别可选值有 `DEBUG``INFO``WARNING``ERROR``CRITICAL`

### Docker Compose 部署时

若需要调整日志记录级别,请修改 `docker-compose.yml` 文件中的 `WECHATTER_LOG_LEVEL` 环境变量。
Expand Down
6 changes: 5 additions & 1 deletion config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ ban_group_list: [ ]
openai_base_api: https://api.openai.com
openai_token: sk_your_openai_token

spark_api: https://spark-api-open.xf-yun.com/v1/chat/completions
spark_model: 4.0Ultra
spark_token: your_spark_token


# GitHub Webhook
github_webhook_enabled: True
Expand Down Expand Up @@ -99,4 +103,4 @@ discord_message_forwarding_rule_list:

# GPT Mode Person
gpt_mode_person_list: [ ]
gpt_mode_model: "gpt4"
gpt_mode_model: "gpt4"
6 changes: 3 additions & 3 deletions docs/command_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
- [食物热量](#食物热量)
- [中石化92号汽油指导价](#中石化92号汽油指导价)
- [冷知识](#冷知识)
- [历史上的今天](#历史上的今天)
- [每日环球视野](#每日环球视野)

## 游戏基本命令

Expand Down Expand Up @@ -155,6 +155,6 @@

![冷知识](./images/cmd_trivia.png)

## 历史上的今天
## 每日环球视野

![历史上的今天](./images/cmd_today_in_history.png)
![每日环球视野](./images/cmd_idaily.png)
2 changes: 1 addition & 1 deletion docs/custom_command_key_config_detail.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- TODO
- `todo`: 添加待办事项
- `todo-remove`: 删除待办事项
- `today-in-history`: 获取历史上的今天
- `idaily`: 获取每日环球视野
- `trivia`: 获取笑话
- `weather`: 查询天气预报
- `weibo-hot`: 获取微博热搜
Expand Down
Binary file added docs/images/cmd_idaily.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/cmd_today_in_history.png
Binary file not shown.
File renamed without changes.
86 changes: 86 additions & 0 deletions tests/commands/test_idaily/idaily_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[
{
"guid": 218572,
"type": 1,
"cat": "6",
"cover_thumb": "http://pic.yupoo.com/fotomag/7aa701a9/b54ad0d4.jpg",
"cover_sq": "http://pic.yupoo.com/fotomag/30d0f2dd/aff88815.jpg",
"cover_sq_hd": "http://pic.yupoo.com/fotomag/30d0f2dd/aff88815.jpg",
"cover_landscape": "http://pic.yupoo.com/fotomag/ceb7f2e4/4b506571.jpg",
"cover_landscape_hd": "http://pic.yupoo.com/fotomag/4600d642/c681b939.jpg",
"pubdate": "November 17, 2024",
"archive_timestamp": 1731772800,
"pubdate_timestamp": 1731842880,
"lastupdate_timestamp": 1731854888,
"ui_sets": {
"caption_subtitle": "泰国庆祝天灯节",
"cover_landscape_hd_4k": "http://pic.yupoo.com/fotomag/2f5642d1/b1a5daf7.jpg"
},
"title": "November 17, 2024",
"author": "",
"source": "",
"link_share": "https://m.idai.ly/se/8eeShU",
"link_wechat": "https://m.idai.ly/se/8eeShU",
"title_wechat_tml": "泰国庆祝天灯节 - November 17, 2024 | iDaily 每日全球最佳新闻图片",
"has_caption": 1,
"has_news": 1,
"latitude": 18.7964642,
"longitude": 98.6600586,
"geo_span": 0.25,
"location": "泰国 · 清迈",
"summary": "",
"content": "泰国民众放飞孔明灯庆祝「天灯节」(Yi Peng festival),清迈。「天灯节」是泰国北部地区的传统节日,历史可追溯至13世纪泰北兰纳王国时期,庆祝日期为每年泰国农历第12个月的满月日,人们会放飞孔明灯庆祝新一年即将开始。泰国旅游部数据显示2024年1至10月接待外国游客超过2900万人次,创造1.35万亿泰铢(约合393亿美元)旅游业收入,前5大游客来源国依次为中国、马来西亚、印度、韩国和俄罗斯。摄影师:Manan Vatsyayana",
"coordinate_sets": [],
"entry_imgs": [],
"tags": [
{
"id": "culture",
"name": "CULTURE · 人类文化",
"focus": 1
}
],
"news_count": 6
},
{
"guid": 218571,
"type": 1,
"cat": "6",
"cover_thumb": "http://pic.yupoo.com/fotomag/0fb2e5d0/790f0d7b.jpg",
"cover_sq": "http://pic.yupoo.com/fotomag/c1974685/8395c708.jpg",
"cover_sq_hd": "http://pic.yupoo.com/fotomag/c1974685/8395c708.jpg",
"cover_landscape": "http://pic.yupoo.com/fotomag/e960e6e1/b846d124.jpg",
"cover_landscape_hd": "http://pic.yupoo.com/fotomag/c8c52912/a379ccf6.jpg",
"pubdate": "November 17, 2024",
"archive_timestamp": 1731772800,
"pubdate_timestamp": 1731841140,
"lastupdate_timestamp": 1731854900,
"ui_sets": {
"caption_subtitle": "中美元首利马会晤",
"cover_landscape_hd_4k": "http://pic.yupoo.com/fotomag/dc420fab/e6a3dff6.jpg"
},
"title": "November 17, 2024",
"author": "",
"source": "",
"link_share": "https://m.idai.ly/se/8e7445",
"link_wechat": "https://m.idai.ly/se/8e7445",
"title_wechat_tml": "中美元首利马会晤 - November 17, 2024 | iDaily 每日全球最佳新闻图片",
"has_caption": 1,
"has_news": 1,
"latitude": -12.0466888,
"longitude": -77.0430886,
"geo_span": 0.25,
"location": "秘鲁 · 利马",
"summary": "",
"content": "中国国家主席习近平与美国总统 Joe Biden 在 APEC 峰会期间举行会晤,秘鲁利马。11月16日,中美两国领导人就双边关系、人工智能治理、地区及国际局势议题举行1小时45分钟会谈。习近平就台湾问题、中国南海、经贸科技、网络安全、乌克兰危机、朝鲜半岛局势等重大问题阐明中方立场。Biden 强调美国的一个中国政策保持不变,对中国支持俄罗斯国防工业深表关切,对中国不公平的贸易政策表示担忧。双方一致认为应以慎重负责的态度发展军事领域的人工智能技术,应维持由人类控制核武器使用的决定。美国总统 Biden 将于2025年1月正式卸任。摄影师:Leah Millis",
"coordinate_sets": [],
"entry_imgs": [],
"tags": [
{
"id": "spotnews",
"name": "SPOT NEWS · 全球焦点",
"focus": 1
}
],
"news_count": 7
}
]
26 changes: 26 additions & 0 deletions tests/commands/test_idaily/test_idaily.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import unittest

from wechatter.commands._commands import idaily


class TestIdailyCommand(unittest.TestCase):
def setUp(self):
with open(
"tests/commands/test_idaily/idaily_response.json"
) as f:
self.tih_response = json.load(f)
self.tih_list = self.tih_response

def test_extract_idaily_data_success(self):
result = idaily._extract_idaily_data(self.tih_response)
self.assertListEqual(result, self.tih_list)

def test_generate_idaily_message_success(self):
result = idaily._generate_idaily_message(self.tih_list)
true_result = "✨====每日环球视野====✨\n今天的iDaily还没更新,现在为您呈现的是:\n🗓️ 时间: November 17, 2024\n1. 🌎 泰国庆祝天灯节\n 🌪️ 泰国民众放飞孔明灯庆祝「天灯节」(Yi Peng festival),清迈。「天灯节」是泰国北部地区的传统节日,历史可追溯至13世纪泰北兰纳王国时期,庆祝日期为每年泰国农历第12个月的满月日,人们会放飞孔明灯庆祝新一年即将开始。泰国旅游部数据显示2024年1至10月接待外国游客超过2900万人次,创造1.35万亿泰铢(约合393亿美元)旅游业收入,前5大游客来源国依次为中国、马来西亚、印度、韩国和俄罗斯。摄影师:Manan Vatsyayana\n2. 🌎 中美元首利马会晤\n 🌪️ 中国国家主席习近平与美国总统 Joe Biden 在 APEC 峰会期间举行会晤,秘鲁利马。11月16日,中美两国领导人就双边关系、人工智能治理、地区及国际局势议题举行1小时45分钟会谈。习近平就台湾问题、中国南海、经贸科技、网络安全、乌克兰危机、朝鲜半岛局势等重大问题阐明中方立场。Biden 强调美国的一个中国政策保持不变,对中国支持俄罗斯国防工业深表关切,对中国不公平的贸易政策表示担忧。双方一致认为应以慎重负责的态度发展军事领域的人工智能技术,应维持由人类控制核武器使用的决定。美国总统 Biden 将于2025年1月正式卸任。摄影师:Leah Millis"
self.assertIn(true_result, result)

def test_generate_idaily_message_empty_list(self):
result = idaily._generate_idaily_message([])
self.assertEqual(result, "暂无每日环球视野")
30 changes: 0 additions & 30 deletions tests/commands/test_today_in_history/test_today_in_history.py

This file was deleted.

This file was deleted.

Loading

0 comments on commit a176a17

Please sign in to comment.