Spaces:
Running
Running
muxi feng
commited on
Commit
·
2de6930
1
Parent(s):
bf55e19
增加通义千问和文言千帆支持
Browse files- app/requests.ts +21 -12
- app/store/config.ts +24 -14
app/requests.ts
CHANGED
@@ -242,10 +242,6 @@ export async function requestChatStream(
|
|
242 |
}, 3000);
|
243 |
return
|
244 |
}
|
245 |
-
if(!updateWallet()){
|
246 |
-
options?.onMessage("积分不足请购买积分或会员卡密!", true);
|
247 |
-
return
|
248 |
-
}
|
249 |
if (Bot == "Lemur"){
|
250 |
const req = makeRevChatRequestParam(messages);
|
251 |
|
@@ -313,6 +309,10 @@ export async function requestChatStream(
|
|
313 |
return
|
314 |
}
|
315 |
}
|
|
|
|
|
|
|
|
|
316 |
if (Bot == "OpenAI (VIP)") {
|
317 |
const req = makeRequestParam(messages, {
|
318 |
stream: true,
|
@@ -486,7 +486,7 @@ export async function requestChatStream(
|
|
486 |
console.error("NetWork Error", err);
|
487 |
options?.onMessage("请换一个问题试试吧", true);
|
488 |
}
|
489 |
-
} else if (Bot == "必应绘画") {
|
490 |
console.log("[Request] ", messages[messages.length - 1].content);
|
491 |
const req = makeImageRequestParam(messages);
|
492 |
chatMessage(messages[messages.length - 1].content,"文字","user")
|
@@ -516,16 +516,20 @@ export async function requestChatStream(
|
|
516 |
options?.onMessage("请换一个问题试试吧", true);
|
517 |
}
|
518 |
}else{
|
519 |
-
const req =
|
|
|
|
|
|
|
520 |
|
|
|
521 |
console.log("[Request] ", req);
|
522 |
-
chatMessage(req.messages,"文字","user")
|
523 |
|
524 |
const controller = new AbortController();
|
525 |
const reqTimeoutId = setTimeout(() => controller.abort(), TIME_OUT_MS);
|
526 |
|
527 |
try {
|
528 |
-
const
|
|
|
529 |
method: "POST",
|
530 |
headers: {
|
531 |
"Content-Type": "application/json",
|
@@ -534,6 +538,7 @@ export async function requestChatStream(
|
|
534 |
body: JSON.stringify(req),
|
535 |
signal: controller.signal,
|
536 |
});
|
|
|
537 |
clearTimeout(reqTimeoutId);
|
538 |
|
539 |
let responseText = "";
|
@@ -551,14 +556,18 @@ export async function requestChatStream(
|
|
551 |
options?.onController?.(controller);
|
552 |
|
553 |
while (true) {
|
554 |
-
// handle time out, will stop if no response in 10 secs
|
555 |
const resTimeoutId = setTimeout(() => finish(), TIME_OUT_MS);
|
556 |
const content = await reader?.read();
|
557 |
clearTimeout(resTimeoutId);
|
558 |
-
|
|
|
|
|
|
|
|
|
|
|
559 |
responseText += text;
|
560 |
|
561 |
-
const done =
|
562 |
options?.onMessage(responseText, false);
|
563 |
|
564 |
if (done) {
|
@@ -575,7 +584,7 @@ export async function requestChatStream(
|
|
575 |
}
|
576 |
} catch (err) {
|
577 |
console.error("NetWork Error", err);
|
578 |
-
options?.
|
579 |
}
|
580 |
}
|
581 |
}
|
|
|
242 |
}, 3000);
|
243 |
return
|
244 |
}
|
|
|
|
|
|
|
|
|
245 |
if (Bot == "Lemur"){
|
246 |
const req = makeRevChatRequestParam(messages);
|
247 |
|
|
|
309 |
return
|
310 |
}
|
311 |
}
|
312 |
+
if(!updateWallet()){
|
313 |
+
options?.onMessage("积分不足请购买积分或会员卡密!", true);
|
314 |
+
return
|
315 |
+
}
|
316 |
if (Bot == "OpenAI (VIP)") {
|
317 |
const req = makeRequestParam(messages, {
|
318 |
stream: true,
|
|
|
486 |
console.error("NetWork Error", err);
|
487 |
options?.onMessage("请换一个问题试试吧", true);
|
488 |
}
|
489 |
+
} else if (Bot == "必应绘画(VIP)") {
|
490 |
console.log("[Request] ", messages[messages.length - 1].content);
|
491 |
const req = makeImageRequestParam(messages);
|
492 |
chatMessage(messages[messages.length - 1].content,"文字","user")
|
|
|
516 |
options?.onMessage("请换一个问题试试吧", true);
|
517 |
}
|
518 |
}else{
|
519 |
+
const req = makeRequestParam(messages, {
|
520 |
+
stream: true,
|
521 |
+
overrideModel: options?.overrideModel,
|
522 |
+
});
|
523 |
|
524 |
+
chatMessage(JSON.stringify(req.messages),"文字","user")
|
525 |
console.log("[Request] ", req);
|
|
|
526 |
|
527 |
const controller = new AbortController();
|
528 |
const reqTimeoutId = setTimeout(() => controller.abort(), TIME_OUT_MS);
|
529 |
|
530 |
try {
|
531 |
+
const openaiUrl = useAccessStore.getState().openaiUrl;
|
532 |
+
const res = await fetch(openaiUrl + "v1/chat/completions", {
|
533 |
method: "POST",
|
534 |
headers: {
|
535 |
"Content-Type": "application/json",
|
|
|
538 |
body: JSON.stringify(req),
|
539 |
signal: controller.signal,
|
540 |
});
|
541 |
+
|
542 |
clearTimeout(reqTimeoutId);
|
543 |
|
544 |
let responseText = "";
|
|
|
556 |
options?.onController?.(controller);
|
557 |
|
558 |
while (true) {
|
|
|
559 |
const resTimeoutId = setTimeout(() => finish(), TIME_OUT_MS);
|
560 |
const content = await reader?.read();
|
561 |
clearTimeout(resTimeoutId);
|
562 |
+
|
563 |
+
if (!content || !content.value) {
|
564 |
+
break;
|
565 |
+
}
|
566 |
+
|
567 |
+
const text = decoder.decode(content.value, { stream: true });
|
568 |
responseText += text;
|
569 |
|
570 |
+
const done = content.done;
|
571 |
options?.onMessage(responseText, false);
|
572 |
|
573 |
if (done) {
|
|
|
584 |
}
|
585 |
} catch (err) {
|
586 |
console.error("NetWork Error", err);
|
587 |
+
options?.onError(err as Error);
|
588 |
}
|
589 |
}
|
590 |
}
|
app/store/config.ts
CHANGED
@@ -50,40 +50,42 @@ export type ChatConfigStore = ChatConfig & {
|
|
50 |
|
51 |
export type ModelConfig = ChatConfig["modelConfig"];
|
52 |
|
53 |
-
const ENABLE_GPT4 = true;
|
54 |
-
|
55 |
export const ALL_MODELS = [
|
56 |
{
|
57 |
name: "gpt-4",
|
58 |
-
available:
|
59 |
},
|
60 |
{
|
61 |
name: "gpt-4-0314",
|
62 |
-
available:
|
63 |
},
|
64 |
{
|
65 |
name: "gpt-4-32k",
|
66 |
-
available:
|
67 |
},
|
68 |
{
|
69 |
name: "gpt-4-32k-0314",
|
70 |
-
available:
|
71 |
},
|
72 |
{
|
73 |
name: "gpt-3.5-turbo",
|
74 |
-
available:
|
75 |
},
|
76 |
{
|
77 |
name: "gpt-3.5-turbo-0301",
|
78 |
-
available:
|
79 |
},
|
80 |
{
|
81 |
name: "qwen-v1", // 通义千问
|
82 |
-
available:
|
83 |
},
|
84 |
{
|
85 |
-
name: "
|
86 |
-
available:
|
|
|
|
|
|
|
|
|
87 |
},
|
88 |
{
|
89 |
name: "spark", // 讯飞星火
|
@@ -102,18 +104,18 @@ export const ALL_MODELS = [
|
|
102 |
export const ALL_BOT = [
|
103 |
{
|
104 |
name: "OpenAI (VIP)",
|
105 |
-
available:
|
106 |
},
|
107 |
{
|
108 |
name: "OpenAI绘画 (VIP)",
|
109 |
-
available:
|
110 |
},
|
111 |
{
|
112 |
name: "必应 (VIP)",
|
113 |
available: false,
|
114 |
},
|
115 |
{
|
116 |
-
name: "必应绘画",
|
117 |
available: false,
|
118 |
},
|
119 |
{
|
@@ -124,6 +126,14 @@ export const ALL_BOT = [
|
|
124 |
name: "Lemur",
|
125 |
available: true,
|
126 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
];
|
128 |
|
129 |
export type BotType = (typeof ALL_BOT)[number]["name"];
|
|
|
50 |
|
51 |
export type ModelConfig = ChatConfig["modelConfig"];
|
52 |
|
|
|
|
|
53 |
export const ALL_MODELS = [
|
54 |
{
|
55 |
name: "gpt-4",
|
56 |
+
available: false,
|
57 |
},
|
58 |
{
|
59 |
name: "gpt-4-0314",
|
60 |
+
available: false,
|
61 |
},
|
62 |
{
|
63 |
name: "gpt-4-32k",
|
64 |
+
available: false,
|
65 |
},
|
66 |
{
|
67 |
name: "gpt-4-32k-0314",
|
68 |
+
available: false,
|
69 |
},
|
70 |
{
|
71 |
name: "gpt-3.5-turbo",
|
72 |
+
available: false,
|
73 |
},
|
74 |
{
|
75 |
name: "gpt-3.5-turbo-0301",
|
76 |
+
available: false,
|
77 |
},
|
78 |
{
|
79 |
name: "qwen-v1", // 通义千问
|
80 |
+
available: true,
|
81 |
},
|
82 |
{
|
83 |
+
name: "qwen-plus-v1", // 通义千问
|
84 |
+
available: true,
|
85 |
+
},
|
86 |
+
{
|
87 |
+
name: "ERNIE-Bot-turbo", // 文心一言
|
88 |
+
available: true,
|
89 |
},
|
90 |
{
|
91 |
name: "spark", // 讯飞星火
|
|
|
104 |
export const ALL_BOT = [
|
105 |
{
|
106 |
name: "OpenAI (VIP)",
|
107 |
+
available: false,
|
108 |
},
|
109 |
{
|
110 |
name: "OpenAI绘画 (VIP)",
|
111 |
+
available: false,
|
112 |
},
|
113 |
{
|
114 |
name: "必应 (VIP)",
|
115 |
available: false,
|
116 |
},
|
117 |
{
|
118 |
+
name: "必应绘画(VIP)",
|
119 |
available: false,
|
120 |
},
|
121 |
{
|
|
|
126 |
name: "Lemur",
|
127 |
available: true,
|
128 |
},
|
129 |
+
{
|
130 |
+
name: "通义千问(VIP)",
|
131 |
+
available: true,
|
132 |
+
},
|
133 |
+
{
|
134 |
+
name: "百度文心千帆(VIP)",
|
135 |
+
available: true,
|
136 |
+
},
|
137 |
];
|
138 |
|
139 |
export type BotType = (typeof ALL_BOT)[number]["name"];
|