Spaces:
Running
Running
muxi feng
commited on
Commit
·
6df0f04
1
Parent(s):
1d5e404
修复lemur回答中断的bug,增加输入回答禁用
Browse files- app/api/lemur/route.ts +5 -3
- app/components/chat.tsx +5 -2
app/api/lemur/route.ts
CHANGED
@@ -103,15 +103,17 @@ async function createStream(res: Response) {
|
|
103 |
controller.enqueue(queue);
|
104 |
return;
|
105 |
}
|
106 |
-
// https://beta.openai.com/docs/api-reference/completions/create#completions/create-stream
|
107 |
try {
|
108 |
const json = JSON.parse(data);
|
109 |
-
// console.log(json)
|
110 |
if (data.indexOf("content") == -1) {
|
111 |
controller.close();
|
112 |
return;
|
113 |
}
|
114 |
-
|
|
|
|
|
|
|
|
|
115 |
const queue = encoder.encode(text);
|
116 |
controller.enqueue(queue);
|
117 |
} catch (e) {
|
|
|
103 |
controller.enqueue(queue);
|
104 |
return;
|
105 |
}
|
|
|
106 |
try {
|
107 |
const json = JSON.parse(data);
|
|
|
108 |
if (data.indexOf("content") == -1) {
|
109 |
controller.close();
|
110 |
return;
|
111 |
}
|
112 |
+
var str=json.data.split("data:")
|
113 |
+
let text=""
|
114 |
+
for(let i=1;i<str.length;i++){
|
115 |
+
text=text+JSON.parse(str[i]).choices[0].delta.content
|
116 |
+
}
|
117 |
const queue = encoder.encode(text);
|
118 |
controller.enqueue(queue);
|
119 |
} catch (e) {
|
app/components/chat.tsx
CHANGED
@@ -608,6 +608,8 @@ export function Chat() {
|
|
608 |
const location = useLocation();
|
609 |
const isChat = location.pathname === Path.Chat;
|
610 |
const autoFocus = !isMobileScreen || isChat; // only focus in chat page
|
|
|
|
|
611 |
useCommand({
|
612 |
fill: setUserInput,
|
613 |
submit: (text) => {
|
@@ -691,12 +693,12 @@ export function Chat() {
|
|
691 |
}}
|
692 |
>
|
693 |
{messages.map((message, i) => {
|
694 |
-
|
695 |
const showActions =
|
696 |
!isUser &&
|
697 |
i > 0 &&
|
698 |
!(message.preview || message.content.length === 0);
|
699 |
-
|
700 |
|
701 |
return (
|
702 |
<div
|
@@ -806,6 +808,7 @@ export function Chat() {
|
|
806 |
onBlur={() => setAutoScroll(false)}
|
807 |
rows={inputRows}
|
808 |
autoFocus={autoFocus}
|
|
|
809 |
/>
|
810 |
<IconButton
|
811 |
icon={<SendWhiteIcon />}
|
|
|
608 |
const location = useLocation();
|
609 |
const isChat = location.pathname === Path.Chat;
|
610 |
const autoFocus = !isMobileScreen || isChat; // only focus in chat page
|
611 |
+
let isUser
|
612 |
+
let showTyping
|
613 |
useCommand({
|
614 |
fill: setUserInput,
|
615 |
submit: (text) => {
|
|
|
693 |
}}
|
694 |
>
|
695 |
{messages.map((message, i) => {
|
696 |
+
isUser = message.role === "user";
|
697 |
const showActions =
|
698 |
!isUser &&
|
699 |
i > 0 &&
|
700 |
!(message.preview || message.content.length === 0);
|
701 |
+
showTyping = message.preview || message.streaming;
|
702 |
|
703 |
return (
|
704 |
<div
|
|
|
808 |
onBlur={() => setAutoScroll(false)}
|
809 |
rows={inputRows}
|
810 |
autoFocus={autoFocus}
|
811 |
+
disabled={!isUser&&showTyping}
|
812 |
/>
|
813 |
<IconButton
|
814 |
icon={<SendWhiteIcon />}
|