refactor(api): update file_url field in MultimodalContent interface
This commit is contained in:
parent
83f948239c
commit
10f6ef0fb1
|
@ -29,11 +29,14 @@ export const TTSModels = ["tts-1", "tts-1-hd"] as const;
|
||||||
export type ChatModel = ModelType;
|
export type ChatModel = ModelType;
|
||||||
|
|
||||||
export interface MultimodalContent {
|
export interface MultimodalContent {
|
||||||
type: "text" | "image_url";
|
type: "text" | "image_url" | "file_url";
|
||||||
text?: string;
|
text?: string;
|
||||||
image_url?: {
|
image_url?: {
|
||||||
url: string;
|
url: string;
|
||||||
};
|
};
|
||||||
|
file_url?: {
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RequestMessage {
|
export interface RequestMessage {
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
//row-gap: 11px;
|
//row-gap: 11px;
|
||||||
height: 64px;
|
max-height: 64px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.attach-file {
|
.attach-file {
|
||||||
|
|
|
@ -1041,6 +1041,7 @@ function _Chat() {
|
||||||
.onUserInput(userInput, attachImages, attachFiles)
|
.onUserInput(userInput, attachImages, attachFiles)
|
||||||
.then(() => setIsLoading(false));
|
.then(() => setIsLoading(false));
|
||||||
setAttachImages([]);
|
setAttachImages([]);
|
||||||
|
setAttachFiles([]);
|
||||||
chatStore.setLastInput(userInput);
|
chatStore.setLastInput(userInput);
|
||||||
setUserInput("");
|
setUserInput("");
|
||||||
setPromptHints([]);
|
setPromptHints([]);
|
||||||
|
|
|
@ -350,20 +350,26 @@ export const useChatStore = createPersistStore(
|
||||||
const modelConfig = session.mask.modelConfig;
|
const modelConfig = session.mask.modelConfig;
|
||||||
|
|
||||||
//read file content from the url
|
//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);
|
||||||
|
|
||||||
let mContent: string | MultimodalContent[] = userContent;
|
let mContent: string | MultimodalContent[] = userContent;
|
||||||
|
let displayContent: string | MultimodalContent[] = userContent;
|
||||||
|
|
||||||
|
if (attachFiles && attachFiles.length > 0) {
|
||||||
|
let fileContent = userContent + " file content: \n";
|
||||||
|
for (let i = 0; i < attachFiles.length; i++) {
|
||||||
|
fileContent += await readFileContent(attachFiles[i]);
|
||||||
|
}
|
||||||
|
|
||||||
if (attachImages && attachImages.length > 0) {
|
if (attachImages && attachImages.length > 0) {
|
||||||
mContent = [
|
mContent = [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: fileContent,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
displayContent = [
|
||||||
{
|
{
|
||||||
type: "text",
|
type: "text",
|
||||||
text: userContent,
|
text: userContent,
|
||||||
|
@ -379,7 +385,22 @@ export const useChatStore = createPersistStore(
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
displayContent = displayContent.concat(
|
||||||
|
attachFiles.map((url) => {
|
||||||
|
return {
|
||||||
|
type: "file_url",
|
||||||
|
file_url: {
|
||||||
|
url: url,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
mContent = fileContent;
|
||||||
|
displayContent = userContent;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let userMessage: ChatMessage = createMessage({
|
let userMessage: ChatMessage = createMessage({
|
||||||
role: "user",
|
role: "user",
|
||||||
content: mContent,
|
content: mContent,
|
||||||
|
@ -400,7 +421,8 @@ export const useChatStore = createPersistStore(
|
||||||
get().updateCurrentSession((session) => {
|
get().updateCurrentSession((session) => {
|
||||||
const savedUserMessage = {
|
const savedUserMessage = {
|
||||||
...userMessage,
|
...userMessage,
|
||||||
content: mContent,
|
//content: mContent,
|
||||||
|
content: displayContent,
|
||||||
};
|
};
|
||||||
session.messages = session.messages.concat([
|
session.messages = session.messages.concat([
|
||||||
savedUserMessage,
|
savedUserMessage,
|
||||||
|
|
Loading…
Reference in New Issue