chore: update dependencies and enhance document schema
- Updated package.json and package-lock.json to include the new dependency 'quill-to-pdf' for improved document export functionality. - Modified DocumentSchema to introduce a new 'DocumentExportObject' type, facilitating document export operations. - Cleaned up commented-out code in document.service.ts and minio.service.ts for better readability and maintainability. - Adjusted quiz schema to expose user input and questions as JSON types, enhancing data flexibility. - Updated workshop subscription logic to maintain accurate participant counts upon new subscriptions. These changes improve the overall functionality and maintainability of the project, ensuring better document handling and schema consistency.
This commit is contained in:
@@ -98,50 +98,51 @@ export class DocumentService {
|
||||
}
|
||||
|
||||
// check grammar for a page by parallely send each sentence to OpenAI service as text and get the result, after that return the result as delta and publish the result to the document
|
||||
async checkGrammarForPage(documentId: string, pageId: number): Promise<void> {
|
||||
const sentenceDelta = await this.pageToSentence(documentId, pageId)
|
||||
// async checkGrammarForPage(documentId: string, pageId: number): Promise<void> {
|
||||
// const sentenceDelta = await this.pageToSentence(documentId, pageId)
|
||||
|
||||
// Extract the entire page content as a single text
|
||||
const pageText = sentenceDelta.ops
|
||||
.filter((op) => typeof op.insert === 'string')
|
||||
.map((op) => op.insert as string)
|
||||
.join(' ')
|
||||
// // Extract the entire page content as a single text
|
||||
// const pageText = sentenceDelta.ops
|
||||
// .filter((op) => typeof op.insert === 'string')
|
||||
// .map((op) => op.insert as string)
|
||||
// .join(' ')
|
||||
|
||||
// Create a unique cache key for the entire page
|
||||
const cacheKey = `grammar_check:${documentId}:${pageId}`
|
||||
// // Create a unique cache key for the entire page
|
||||
// const cacheKey = `grammar_check:${documentId}:${pageId}`
|
||||
|
||||
// Try to get cached result first
|
||||
const cachedResult = await this.redis.get(cacheKey)
|
||||
// // Try to get cached result first
|
||||
// const cachedResult = await this.redis.get(cacheKey)
|
||||
|
||||
if (cachedResult) {
|
||||
Logger.log('Cached grammar check result exists', 'Grammar Check')
|
||||
return
|
||||
}
|
||||
// if (cachedResult) {
|
||||
// Logger.log('Cached grammar check result exists', 'Grammar Check')
|
||||
// return
|
||||
// }
|
||||
|
||||
// Process the entire page text
|
||||
const grammarCheckResult = await this.openai.processText(pageText, 0, PromptType.CHECK_GRAMMAR)
|
||||
// // Process the entire page text
|
||||
// const grammarCheckResult = await this.openai.processText(pageText, 0, PromptType.CHECK_GRAMMAR)
|
||||
|
||||
if (!grammarCheckResult.result) {
|
||||
return
|
||||
}
|
||||
// if (!grammarCheckResult.result) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// Cache the result
|
||||
await this.redis.setPermanent(cacheKey, JSON.stringify(grammarCheckResult))
|
||||
// // Cache the result
|
||||
// await this.redis.setPermanent(cacheKey, JSON.stringify(grammarCheckResult))
|
||||
|
||||
// Calculate diff between original page and corrected page
|
||||
const diff = await this.diff(pageText, grammarCheckResult.result)
|
||||
// // Calculate diff between original page and corrected page
|
||||
// const diff = await this.diff(pageText, grammarCheckResult.result)
|
||||
|
||||
// Build payload
|
||||
// // Build payload
|
||||
|
||||
|
||||
// Publish the result to the subscriber
|
||||
this.pubSub.publish(`${DocumentEvent.AI_SUGGESTION}.${documentId}.${pageId}`, payload)
|
||||
}
|
||||
// // Publish the result to the subscriber
|
||||
// this.pubSub.publish(`${DocumentEvent.AI_SUGGESTION}.${documentId}.${pageId}`, payload)
|
||||
// }
|
||||
|
||||
async diff(original: string, corrected: string): Promise<Delta> {
|
||||
const originalDelta = new Delta().insert(original)
|
||||
const correctedDelta = new Delta().insert(corrected)
|
||||
const diff = originalDelta.diff(correctedDelta)
|
||||
Logger.log(diff, 'diff')
|
||||
return diff
|
||||
}
|
||||
// async diff(original: string, corrected: string): Promise<Delta> {
|
||||
// const originalDelta = new Delta().insert(original)
|
||||
// const correctedDelta = new Delta().insert(corrected)
|
||||
// const diff = originalDelta.diff(correctedDelta)
|
||||
// Logger.log(diff, 'diff')
|
||||
// return diff
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user