style: fix formatting issues in chat.tsx
This commit is contained in:
parent
05b16f54ab
commit
83f948239c
|
@ -1038,7 +1038,7 @@ function _Chat() {
|
||||||
}
|
}
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
chatStore
|
chatStore
|
||||||
.onUserInput(userInput, attachImages)
|
.onUserInput(userInput, attachImages, attachFiles)
|
||||||
.then(() => setIsLoading(false));
|
.then(() => setIsLoading(false));
|
||||||
setAttachImages([]);
|
setAttachImages([]);
|
||||||
chatStore.setLastInput(userInput);
|
chatStore.setLastInput(userInput);
|
||||||
|
|
|
@ -153,6 +153,21 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const readFileContent = async (url: string): Promise<string> => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to fetch content from ${url}: ${response.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return await response.text();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error reading file content:", error);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const DEFAULT_CHAT_STATE = {
|
const DEFAULT_CHAT_STATE = {
|
||||||
sessions: [createEmptySession()],
|
sessions: [createEmptySession()],
|
||||||
currentSessionIndex: 0,
|
currentSessionIndex: 0,
|
||||||
|
@ -326,10 +341,22 @@ export const useChatStore = createPersistStore(
|
||||||
get().summarizeSession();
|
get().summarizeSession();
|
||||||
},
|
},
|
||||||
|
|
||||||
async onUserInput(content: string, attachImages?: string[]) {
|
async onUserInput(
|
||||||
|
content: string,
|
||||||
|
attachImages?: string[],
|
||||||
|
attachFiles?: string[],
|
||||||
|
) {
|
||||||
const session = get().currentSession();
|
const session = get().currentSession();
|
||||||
const modelConfig = session.mask.modelConfig;
|
const modelConfig = session.mask.modelConfig;
|
||||||
|
|
||||||
|
//read file content from the url
|
||||||
|
if (attachFiles && attachFiles.length > 0) {
|
||||||
|
content += " file content: \n";
|
||||||
|
for (let i = 0; i < attachFiles.length; i++) {
|
||||||
|
content += await readFileContent(attachFiles[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const userContent = fillTemplateWith(content, modelConfig);
|
const userContent = fillTemplateWith(content, modelConfig);
|
||||||
console.log("[User Input] after template: ", userContent);
|
console.log("[User Input] after template: ", userContent);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue