Skip to content

Commit b165370

Browse files
committed
2.0.2 fix
1 parent d3e73e2 commit b165370

File tree

5 files changed

+265
-0
lines changed

5 files changed

+265
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ THChatUI V2 是一个专为**数据敏感型个人/组织/公司**设计的**开
3636
- 讯飞星火
3737
- 智谱AI
3838
- OpenAI(包括类OpenAI式服务)
39+
- 火山方舟(DeepSeek R1)
3940
- 系统主题切换:支持浅色、深色、毛玻璃三种主题,支持自定义背景图片
4041
- 响应式设计:支持PC、移动端
4142
- 多模态:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @fileoverview 火山方舟平台的HTTP调用。
3+
* 接口采用SSE请求方式,直接调会跨域,需要配代理,部署在服务器上之后也需要配置代理,详情可以参考本项目的文档
4+
*/
5+
import { fetchEventSource } from "@microsoft/fetch-event-source";
6+
import { preProcess } from "@/util/config"
7+
import store from '../../store';
8+
9+
// 火山方舟平台的接口地址 在项目内部设置了跨域 所以拼接了字符串"/ali/remote" 对应项目里面的代理配置 vue.config.js
10+
const API_URLS = {
11+
llm: "/tt/remote/api/v3/chat/completions",
12+
vim: "",
13+
igm: "" // 预留阿里平台的绘图模型
14+
};
15+
16+
/**
17+
* 调用火山方舟平台的接口
18+
* @param {string} prompt - 用户输入的问题
19+
* @param {Array} history - 历史对话消息
20+
* @param {Array} files - 文件列表 图片
21+
* @param {AbortController} controller - 控制请求的取消
22+
* @param {Function} onopen - 连接成功回调
23+
* @param {Function} onmessage - 接收消息回调
24+
* @param {Function} onclose - 连接关闭回调
25+
* @param {Function} onerror - 错误处理回调
26+
*/
27+
export async function fetchAPI({
28+
prompt,
29+
history,
30+
files,
31+
controller,
32+
onopen,
33+
onmessage,
34+
onclose,
35+
onerror
36+
}) {
37+
const { setting } = store.state;
38+
const { model_config, web_search_enabled } = setting;
39+
const { version, pre_method, type, can_web_search } = model_config;
40+
const api_key = setting.api_key_map[setting.platform];
41+
42+
const url = API_URLS[type] || API_URLS.llm;
43+
const is_search = (can_web_search !== undefined && can_web_search) && web_search_enabled;
44+
45+
const requestConfig = {
46+
method: "POST",
47+
headers: {
48+
"Authorization": `Bearer ${api_key}`,
49+
'Content-Type': 'application/json',
50+
'Accept': 'text/event-stream',
51+
'X-DashScope-SSE': 'enable'
52+
},
53+
body: JSON.stringify(preProcess(version, prompt, history, pre_method, files, is_search)),
54+
signal: controller.signal,
55+
onopen,
56+
onmessage,
57+
onclose,
58+
onerror,
59+
openWhenHidden: true
60+
};
61+
62+
return await fetchEventSource(url, requestConfig);
63+
}
64+
17.4 KB
Loading
2.54 KB
Loading

0 commit comments

Comments
 (0)