-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for JSON file uploads
- Loading branch information
Showing
5 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { QSource } from "../type"; | ||
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter"; | ||
import { DialoqbaseVectorStore } from "../../utils/store"; | ||
import { embeddings } from "../../utils/embeddings"; | ||
import { PrismaClient } from "@prisma/client"; | ||
import { getModelInfo } from "../../utils/get-model-info"; | ||
import * as fs from "fs/promises" | ||
|
||
export const jsonQueueController = async ( | ||
source: QSource, | ||
prisma: PrismaClient | ||
) => { | ||
console.log("loading json"); | ||
|
||
const location = source.location!; | ||
|
||
const json = await fs.readFile(location, "utf-8"); | ||
|
||
const textSplitter = new RecursiveCharacterTextSplitter({ | ||
chunkSize: source.chunkSize, | ||
chunkOverlap: source.chunkOverlap, | ||
}); | ||
|
||
const chunks = await textSplitter.splitDocuments([ | ||
{ | ||
pageContent: json, | ||
metadata: { | ||
source: location, | ||
}, | ||
}, | ||
]); | ||
|
||
const embeddingInfo = await getModelInfo({ | ||
model: source.embedding, | ||
prisma, | ||
type: "embedding", | ||
}); | ||
|
||
if (!embeddingInfo) { | ||
throw new Error("Embedding not found. Please verify the embedding id"); | ||
} | ||
|
||
await DialoqbaseVectorStore.fromDocuments( | ||
chunks, | ||
embeddings( | ||
embeddingInfo.model_provider!.toLowerCase(), | ||
embeddingInfo.model_id, | ||
embeddingInfo?.config | ||
), | ||
{ | ||
botId: source.botId, | ||
sourceId: source.id, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters