Skip to content

Commit e4d2d3f

Browse files
committed
fix:添加了应用签名,添加支持了deepseek平台的api.
1 parent 827c5f6 commit e4d2d3f

File tree

11 files changed

+155
-92
lines changed

11 files changed

+155
-92
lines changed

README.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ Smart Work&Life Mate
77
- 以调用各个云平台部署的在线大模型 API 为基底的“**AI 智能助手**”,(简称“工具”)。
88
- 2025-02-26 大模型 API 调用**只保留其 HTTP API 兼容 openAI API 结构的**平台和模型,不再兼容其他平台自己定义的 API 结构,具体如下:
99
- 对话模型:
10-
- [百度](https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Fm2vrveyu)
1110
- [阿里](https://help.aliyun.com/zh/model-studio/developer-reference/compatibility-of-openai-with-dashscope)
11+
- [百度](https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Fm2vrveyu)
1212
- [腾讯](https://console.cloud.tencent.com/hunyuan/start)
1313
- [智谱](https://open.bigmodel.cn/dev/api/normal-model/glm-4)
14+
- [深度求索](https://api-docs.deepseek.com/zh-cn/)
1415
- [零一万物](https://platform.lingyiwanwu.com/docs/api-reference)
1516
- [无问芯穹](https://docs.infini-ai.com/gen-studio/api/maas.html#/operations/chatCompletions)
1617
- [硅基流动](https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions)
@@ -105,24 +106,32 @@ AI 绘图/视频结构和操作类似,所以放在一起说。
105106

106107
#### 平台密钥 json 结构
107108

109+
导入平台的密钥的 key 一定要和这个文件中 key 一样,不然匹配不上:
110+
108111
```json
109112
{
110-
"USER_LINGYIWANWU_AK": "xxx",
111-
"USER_ZHIPU_AK": "xxx",
112-
"USER_SILICON_CLOUD_AK": "sk-xxx",
113-
"USER_INFINI_GEN_STUDIO_AK": "sk-xxx",
114113
"USER_ALIYUN_API_KEY": "sk-xxx",
115114
"USER_BAIDU_API_KEY_V2": "xxx",
116115
"USER_TENCENT_API_KEY": "xxx",
117116

117+
"USER_DEEPSEEK_API_KEY": "sk-xxx",
118+
"USER_LINGYIWANWU_API_KEY": "xxx",
119+
"USER_ZHIPU_API_KEY": "xxx",
120+
121+
"USER_SILICON_CLOUD_API_KEY": "sk-xxx",
122+
"USER_INFINI_GEN_STUDIO_API_KEY": "sk-xxx",
123+
118124
// 讯飞, 语音转写需要
119125
"USER_XFYUN_APP_ID": "xxx",
120-
"USER_XFYUN_API_SECRET": "xxx",
121126
"USER_XFYUN_API_KEY": "xxx",
127+
"USER_XFYUN_API_SECRET": "xxx",
122128

123129
// 生活工具中 NUTRITIONIX 食品数据查询需要
124130
"USER_NUTRITIONIX_APP_ID": "xxx",
125-
"USER_NUTRITIONIX_APP_KEY": "xxx"
131+
"USER_NUTRITIONIX_APP_KEY": "xxx",
132+
133+
// newsapi新闻需要
134+
"USER_NEWS_API_KEY": "xxx"
126135
}
127136
```
128137

@@ -180,6 +189,7 @@ enum ApiPlatform {
180189
lingyiwanwu, // 零一万物
181190
zhipu, // 智谱 AI
182191
infini, // 无问芯穹的 genStudio
192+
deepseek, // 深度求索
183193
}
184194
```
185195

android/app/build.gradle

+21-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ if (flutterVersionName == null) {
2323
flutterVersionName = "1.0"
2424
}
2525

26+
// 配置 Gradle 来使用自己的上传密钥
27+
def keystoreProperties = new Properties()
28+
def keystorePropertiesFile = rootProject.file('key.properties')
29+
if (keystorePropertiesFile.exists()) {
30+
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
31+
}
32+
33+
2634
android {
2735
namespace = "com.swm.swmate"
2836
compileSdk = flutter.compileSdkVersion
@@ -79,11 +87,23 @@ android {
7987
versionName = flutterVersionName
8088
}
8189

90+
// 在 android 属性块内的 buildTypes 属性块前面添加签名配置。
91+
signingConfigs {
92+
release {
93+
keyAlias = keystoreProperties['keyAlias']
94+
keyPassword = keystoreProperties['keyPassword']
95+
storeFile = keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
96+
storePassword = keystoreProperties['storePassword']
97+
}
98+
}
99+
82100
buildTypes {
83101
release {
84102
// TODO: Add your own signing config for the release build.
85103
// Signing with the debug keys for now, so `flutter run --release` works.
86-
signingConfig = signingConfigs.debug
104+
// signingConfig = signingConfigs.debug
105+
106+
signingConfig = signingConfigs.release
87107
}
88108
}
89109
}

android/app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<!-- =语音录制 -->
1414
<uses-permission android:name="android.permission.RECORD_AUDIO" />
1515
<application
16-
android:label="思文智能助手"
16+
android:label="思文"
1717
android:name="${applicationName}"
1818
android:icon="@mipmap/ic_launcher">
1919
<activity

lib/common/llm_spec/constant_llm_enum.dart

+27-10
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,51 @@
99
/// 因为零一万物的API兼容openAI的api,后续付费的应该都是这样的,而不是之前免费的三大平台乱七八糟的
1010
///
1111
enum ApiPlatform {
12+
aliyun,
1213
baidu,
1314
tencent,
14-
aliyun,
15-
siliconCloud,
15+
16+
deepseek,
1617
lingyiwanwu,
17-
xfyun, // 讯飞云,官网就是这样写的
18-
zhipu, // 智谱AI
19-
infini, // 无问芯穹的genStudio
18+
zhipu,
19+
20+
siliconCloud,
21+
infini,
22+
}
23+
24+
// 用户自行导入密钥时,json文件的key
25+
enum ApiPlatformAKLabel {
26+
// 传统主流多模型平台(自研+第三方)
27+
USER_ALIYUN_API_KEY,
28+
USER_BAIDU_API_KEY_V2,
29+
USER_TENCENT_API_KEY,
30+
31+
// 自平台(只有自研)
32+
USER_DEEPSEEK_API_KEY, // 深度求索
33+
USER_LINGYIWANWU_API_KEY, // 零一万物
34+
USER_ZHIPU_API_KEY, // 智谱AI
35+
36+
// 第三方多模型平台(只有第三方)
37+
USER_SILICON_CLOUD_API_KEY, // 硅基流动
38+
USER_INFINI_GEN_STUDIO_API_KEY, // 无问芯穹的genStudio
2039
}
2140

2241
// 模型对应的中文名
2342
final Map<ApiPlatform, String> CP_NAME_MAP = {
43+
ApiPlatform.aliyun: '阿里',
2444
ApiPlatform.baidu: '百度',
2545
ApiPlatform.tencent: '腾讯',
26-
ApiPlatform.aliyun: '阿里',
27-
ApiPlatform.siliconCloud: '硅动科技',
46+
ApiPlatform.deepseek: '深度求索',
2847
ApiPlatform.lingyiwanwu: '零一万物',
29-
ApiPlatform.xfyun: '讯飞',
3048
ApiPlatform.zhipu: '智谱',
49+
ApiPlatform.siliconCloud: '硅基流动',
3150
ApiPlatform.infini: '无问芯穹',
3251
};
3352

3453
// 大模型的分类,在不同页面可以用作模型的筛选
3554
enum LLModelType {
3655
cc, // Chat Completions
3756
vision, // 视觉大模型
38-
tti_word, // 生成艺术字图片
3957
voice, // 语音大模型
4058

4159
// 图片生成大模型分3种: 单独文生图、单独图生图、文生图生都可以
@@ -53,7 +71,6 @@ enum LLModelType {
5371
final Map<LLModelType, String> MT_NAME_MAP = {
5472
LLModelType.cc: '文本对话',
5573
LLModelType.vision: '图片解读',
56-
LLModelType.tti_word: '创意文字',
5774
LLModelType.voice: '语音对话',
5875
LLModelType.tti: '文本生图',
5976
LLModelType.iti: '图片生图',

lib/common/llm_spec/cus_brief_llm_model.g.dart

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/models/brief_ai_tools/chat_competion/com_cc_state.g.dart

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/models/brief_ai_tools/media_generation_history/media_generation_history.g.dart

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/services/chat_service.dart

+42-45
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import '../apis/chat_completion/openai_compatible_apis.dart';
1616
/// 2025-02-13 改版后所有平台都使用open API兼容的版本,不兼容的就不用了。
1717
/// 讯飞每个模型的AK都单独的,太麻烦了,而且效果并不出类拔萃,放弃支持它平台的调用了
1818
/// 当前文档地址:
19-
/// 百度 https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Fm2vrveyu
2019
/// 阿里 https://help.aliyun.com/zh/model-studio/developer-reference/compatibility-of-openai-with-dashscope
20+
/// 百度 https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Fm2vrveyu
2121
/// 腾讯 https://console.cloud.tencent.com/hunyuan/start
2222
/// 智谱 https://open.bigmodel.cn/dev/api/normal-model/glm-4
23+
/// 深度求索 https://api-docs.deepseek.com/zh-cn/
2324
/// 零一万物 https://platform.lingyiwanwu.com/docs/api-reference
24-
/// 无问芯穹 https://docs.infini-ai.com/gen-studio/api/maas.html#/operations/chatCompletions
2525
/// 硅基流动 https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions
26+
/// 无问芯穹 https://docs.infini-ai.com/gen-studio/api/maas.html#/operations/chatCompletions
2627
2728
class ChatService {
2829
// 暴露出去
@@ -34,6 +35,14 @@ class ChatService {
3435
// 私有方法
3536
static String _getBaseUrl(ApiPlatform platform) {
3637
switch (platform) {
38+
case ApiPlatform.aliyun:
39+
return 'https://dashscope.aliyuncs.com/compatible-mode/v1';
40+
case ApiPlatform.baidu:
41+
return 'https://qianfan.baidubce.com/v2';
42+
case ApiPlatform.tencent:
43+
return 'https://api.hunyuan.cloud.tencent.com/v1/';
44+
case ApiPlatform.deepseek:
45+
return 'https://api.deepseek.com/v1';
3746
case ApiPlatform.lingyiwanwu:
3847
return 'https://api.lingyiwanwu.com/v1';
3948
case ApiPlatform.zhipu:
@@ -42,12 +51,6 @@ class ChatService {
4251
return 'https://api.siliconflow.cn/v1';
4352
case ApiPlatform.infini:
4453
return 'https://cloud.infini-ai.com/maas/v1';
45-
case ApiPlatform.aliyun:
46-
return 'https://dashscope.aliyuncs.com/compatible-mode/v1';
47-
case ApiPlatform.baidu:
48-
return 'https://qianfan.baidubce.com/v2';
49-
case ApiPlatform.tencent:
50-
return 'https://api.hunyuan.cloud.tencent.com/v1/';
5154
default:
5255
throw Exception('不支持的平台');
5356
}
@@ -56,21 +59,18 @@ class ChatService {
5659
static Future<String> _getApiKey(CusBriefLLMSpec model) async {
5760
if (model.cusLlmSpecId?.endsWith('_builtin') ?? false) {
5861
// 使用内置的 API Key
62+
// (有免费的模型我才使用自己的ak,自用收费的也自己导入)
5963
switch (model.platform) {
60-
case ApiPlatform.baidu:
61-
return DefaultApiKeys.baiduApiKey;
62-
case ApiPlatform.siliconCloud:
63-
return DefaultApiKeys.siliconCloudAK;
64-
case ApiPlatform.lingyiwanwu:
65-
return DefaultApiKeys.lingyiAK;
66-
case ApiPlatform.zhipu:
67-
return DefaultApiKeys.zhipuAK;
68-
case ApiPlatform.infini:
69-
return DefaultApiKeys.infiniAK;
7064
case ApiPlatform.aliyun:
7165
return DefaultApiKeys.aliyunApiKey;
66+
case ApiPlatform.baidu:
67+
return DefaultApiKeys.baiduApiKey;
7268
case ApiPlatform.tencent:
7369
return DefaultApiKeys.tencentApiKey;
70+
case ApiPlatform.zhipu:
71+
return DefaultApiKeys.zhipuAK;
72+
case ApiPlatform.siliconCloud:
73+
return DefaultApiKeys.siliconCloudAK;
7474
default:
7575
throw Exception('不支持的平台');
7676
}
@@ -80,26 +80,32 @@ class ChatService {
8080
String? apiKey;
8181

8282
switch (model.platform) {
83+
case ApiPlatform.aliyun:
84+
apiKey = userKeys[ApiPlatformAKLabel.USER_ALIYUN_API_KEY.name];
85+
break;
8386
case ApiPlatform.baidu:
84-
apiKey = userKeys['USER_BAIDU_API_KEY_V2'];
87+
apiKey = userKeys[ApiPlatformAKLabel.USER_BAIDU_API_KEY_V2.name];
8588
break;
86-
case ApiPlatform.siliconCloud:
87-
apiKey = userKeys['USER_SILICON_CLOUD_AK'];
89+
case ApiPlatform.tencent:
90+
apiKey = userKeys[ApiPlatformAKLabel.USER_TENCENT_API_KEY.name];
91+
break;
92+
93+
case ApiPlatform.deepseek:
94+
apiKey = userKeys[ApiPlatformAKLabel.USER_DEEPSEEK_API_KEY.name];
8895
break;
8996
case ApiPlatform.lingyiwanwu:
90-
apiKey = userKeys['USER_LINGYIWANWU_AK'];
97+
apiKey = userKeys[ApiPlatformAKLabel.USER_LINGYIWANWU_API_KEY.name];
9198
break;
9299
case ApiPlatform.zhipu:
93-
apiKey = userKeys['USER_ZHIPU_AK'];
100+
apiKey = userKeys[ApiPlatformAKLabel.USER_ZHIPU_API_KEY.name];
94101
break;
95-
case ApiPlatform.infini:
96-
apiKey = userKeys['USER_INFINI_GEN_STUDIO_AK'];
97-
break;
98-
case ApiPlatform.aliyun:
99-
apiKey = userKeys['USER_ALIYUN_API_KEY'];
102+
103+
case ApiPlatform.siliconCloud:
104+
apiKey = userKeys[ApiPlatformAKLabel.USER_SILICON_CLOUD_API_KEY.name];
100105
break;
101-
case ApiPlatform.tencent:
102-
apiKey = userKeys['USER_TENCENT_API_KEY'];
106+
case ApiPlatform.infini:
107+
apiKey =
108+
userKeys[ApiPlatformAKLabel.USER_INFINI_GEN_STUDIO_API_KEY.name];
103109
break;
104110
default:
105111
throw Exception('不支持的平台');
@@ -117,22 +123,13 @@ class ChatService {
117123
) async {
118124
final apiKey = await _getApiKey(model);
119125

120-
switch (model.platform) {
121-
case ApiPlatform.baidu ||
122-
ApiPlatform.siliconCloud ||
123-
ApiPlatform.lingyiwanwu ||
124-
ApiPlatform.zhipu ||
125-
ApiPlatform.infini ||
126-
ApiPlatform.aliyun ||
127-
ApiPlatform.tencent:
128-
return {
129-
'Content-Type': 'application/json',
130-
'Authorization': 'Bearer $apiKey',
131-
};
132-
// ... 其他平台的 headers
133-
default:
134-
throw Exception('不支持的平台');
126+
if (ApiPlatform.values.contains(model.platform)) {
127+
return {
128+
'Content-Type': 'application/json',
129+
'Authorization': 'Bearer $apiKey',
130+
};
135131
}
132+
throw Exception('不支持的平台');
136133
}
137134

138135
static Future<(Stream<ChatCompletionResponse>, VoidCallback)> sendMessage(

lib/services/image_generation_service.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ class ImageGenerationService {
5757
String? apiKey;
5858

5959
switch (model.platform) {
60-
case ApiPlatform.siliconCloud:
61-
apiKey = userKeys['USER_SILICON_CLOUD_AK'];
60+
case ApiPlatform.aliyun:
61+
apiKey = userKeys[ApiPlatformAKLabel.USER_ALIYUN_API_KEY.name];
6262
break;
6363
case ApiPlatform.zhipu:
64-
apiKey = userKeys['USER_ZHIPU_AK'];
64+
apiKey = userKeys[ApiPlatformAKLabel.USER_ZHIPU_API_KEY.name];
6565
break;
66-
case ApiPlatform.aliyun:
67-
apiKey = userKeys['USER_ALIYUN_API_KEY'];
66+
case ApiPlatform.siliconCloud:
67+
apiKey = userKeys[ApiPlatformAKLabel.USER_SILICON_CLOUD_API_KEY.name];
6868
break;
6969

7070
default:

0 commit comments

Comments
 (0)