fix: 🐛 check if llm is available for labeling request
This commit is contained in:
parent
a29752a3e5
commit
fa3d55cd1b
@ -131,58 +131,62 @@ function Organizrr() {
|
|||||||
const handleFileDrop = (files: FileWithPath[]) => {
|
const handleFileDrop = (files: FileWithPath[]) => {
|
||||||
if (files.length < 1) return;
|
if (files.length < 1) return;
|
||||||
|
|
||||||
files.forEach((f) => {
|
if (engine.current) {
|
||||||
const id = Math.random().toString(36).replace("0.", "doc_");
|
files.forEach((f) => {
|
||||||
const fileId = Math.random().toString(36).replace("0.", "file_");
|
if (!engine.current) return;
|
||||||
|
|
||||||
form.insertListItem("documents", { id, file: f });
|
const id = Math.random().toString(36).replace("0.", "doc_");
|
||||||
form.insertListItem("files", {
|
const fileId = Math.random().toString(36).replace("0.", "file_");
|
||||||
id: fileId,
|
|
||||||
documents: [{ id }],
|
|
||||||
suffix: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
const messages: ChatCompletionMessageParam[] = [
|
form.insertListItem("documents", { id, file: f });
|
||||||
systemMessage,
|
form.insertListItem("files", {
|
||||||
{ role: "user", content: "The file name is: " + f.name },
|
id: fileId,
|
||||||
];
|
documents: [{ id }],
|
||||||
|
suffix: "",
|
||||||
setGeneratingFilenames((fns) => [...fns, fileId]);
|
|
||||||
|
|
||||||
engine.current?.chat.completions
|
|
||||||
.create({
|
|
||||||
messages,
|
|
||||||
})
|
|
||||||
.then((reply) => {
|
|
||||||
if (
|
|
||||||
reply &&
|
|
||||||
reply.choices[0].message.content &&
|
|
||||||
!reply?.choices[0].message.content?.includes(
|
|
||||||
"Unable to label file"
|
|
||||||
) &&
|
|
||||||
!reply?.choices[0].message.content?.includes("I'm sorry")
|
|
||||||
) {
|
|
||||||
console.log(reply?.choices[0].message.content);
|
|
||||||
form.getValues().files.forEach((f, idx) => {
|
|
||||||
if (f.id === fileId) {
|
|
||||||
form.setFieldValue(
|
|
||||||
`files.${idx}.suffix`,
|
|
||||||
reply?.choices[0].message.content?.split("\n")[0]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.warn(reply?.choices[0].message.content);
|
|
||||||
}
|
|
||||||
|
|
||||||
setGeneratingFilenames((fns) => fns.filter((fn) => fn !== fileId));
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.error(e);
|
|
||||||
|
|
||||||
setGeneratingFilenames((fns) => fns.filter((fn) => fn !== fileId));
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
const messages: ChatCompletionMessageParam[] = [
|
||||||
|
systemMessage,
|
||||||
|
{ role: "user", content: "The file name is: " + f.name },
|
||||||
|
];
|
||||||
|
|
||||||
|
setGeneratingFilenames((fns) => [...fns, fileId]);
|
||||||
|
|
||||||
|
engine.current.chat.completions
|
||||||
|
.create({
|
||||||
|
messages,
|
||||||
|
})
|
||||||
|
.then((reply) => {
|
||||||
|
if (
|
||||||
|
reply &&
|
||||||
|
reply.choices[0].message.content &&
|
||||||
|
!reply?.choices[0].message.content?.includes(
|
||||||
|
"Unable to label file"
|
||||||
|
) &&
|
||||||
|
!reply?.choices[0].message.content?.includes("I'm sorry")
|
||||||
|
) {
|
||||||
|
console.log(reply?.choices[0].message.content);
|
||||||
|
form.getValues().files.forEach((f, idx) => {
|
||||||
|
if (f.id === fileId) {
|
||||||
|
form.setFieldValue(
|
||||||
|
`files.${idx}.suffix`,
|
||||||
|
reply?.choices[0].message.content?.split("\n")[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn(reply?.choices[0].message.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
setGeneratingFilenames((fns) => fns.filter((fn) => fn !== fileId));
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
|
||||||
|
setGeneratingFilenames((fns) => fns.filter((fn) => fn !== fileId));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setActiveFile(form.getValues().files.length - 1);
|
setActiveFile(form.getValues().files.length - 1);
|
||||||
setActiveDocumentId(
|
setActiveDocumentId(
|
||||||
|
Loading…
Reference in New Issue
Block a user