Skip to content

Commit 5a31849

Browse files
committed
get model when create new conversation
fix send second message
1 parent 490f5cc commit 5a31849

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

components/Chat/Chat.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const Chat = memo(({stopConversationRef}: Props) => {
129129
if (!queryDoneRef.current) {
130130
await delay(textListRef.current.length > 10 ? 300 : 100)
131131
} else {
132-
await delay(20)
132+
// await delay(20)
133133
}
134134
}
135135
}
@@ -139,10 +139,6 @@ export const Chat = memo(({stopConversationRef}: Props) => {
139139

140140
const whileShowText = async () => {
141141
while (textListRef.current.length !== 0) {
142-
if (textListRef.current.length > 0) {
143-
console.log(textListRef.current)
144-
console.log("show")
145-
}
146142
await showText();
147143
}
148144
}
@@ -219,6 +215,7 @@ export const Chat = memo(({stopConversationRef}: Props) => {
219215
messagesToSend = [message, ...messagesToSend];
220216
}
221217
if (isStream) {
218+
queryDoneRef.current = false;
222219
let response: ReadableStream<Uint8Array> | null = await ChatStream(model, promptToSend, temperatureToUse, api, key, messagesToSend);
223220
if (response) {
224221
let notFinishData = "";
@@ -227,7 +224,6 @@ export const Chat = memo(({stopConversationRef}: Props) => {
227224
while (!queryDoneRef.current) {
228225
const {value, done} = await reader.read();
229226
if (done) {
230-
console.log("done-221")
231227
queryDoneRef.current = true;
232228
}
233229
let chunkValue = decoder.decode(value);
@@ -240,7 +236,6 @@ export const Chat = memo(({stopConversationRef}: Props) => {
240236
part = part.substring(6).trim();
241237
}
242238
if (part === "[DONE]") {
243-
console.log("done-234")
244239
queryDoneRef.current = true;
245240
} else {
246241
if (!part.startsWith('{')) {

pages/api/home/home.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {getSettings} from '@/utils/app/settings';
1818
import {Conversation} from '@/types/chat';
1919
import {KeyValuePair} from '@/types/data';
2020
import {FolderInterface, FolderType} from '@/types/folder';
21-
import {fallbackModelID, OpenAIModelID} from '@/types/openai';
21+
import {fallbackModelID, OpenAIModel, OpenAIModelID} from '@/types/openai';
2222
import {Prompt} from '@/types/prompt';
2323

2424
import {Chat} from '@/components/Chat/Chat';
@@ -181,14 +181,24 @@ const Home = ({
181181

182182
// CONVERSATION OPERATIONS --------------------------------------------
183183

184-
const handleNewConversation = () => {
184+
function checkObjectExistence(objectList: OpenAIModel[], object: OpenAIModel): boolean {
185+
for (let obj of objectList) {
186+
if (obj.id === object.id) {
187+
return true;
188+
}
189+
}
190+
return false;
191+
}
192+
193+
const handleNewConversation = async () => {
194+
await getData()
185195
const lastConversation = conversations[conversations.length - 1];
186196
if (models && models.length > 0) {
187197
const newConversation: Conversation = {
188198
id: uuidv4(),
189199
name: t('New Conversation'),
190200
messages: [],
191-
model: lastConversation?.model || models[0],
201+
model: (lastConversation?.model && checkObjectExistence(models, lastConversation?.model) && lastConversation?.model) || models[0],
192202
prompt: promptsList.find(prompt =>
193203
prompt.id?.toLowerCase() === models[0].name?.toLowerCase()
194204
)?.content || "",

0 commit comments

Comments
 (0)