Skip to content

Commit

Permalink
Merge pull request #323 from harmony-one/vertex-bard-integration
Browse files Browse the repository at this point in the history
collection session object + pdf collection upload
  • Loading branch information
sunwavesun authored Oct 2, 2023
2 parents 8618ef9 + f4a60e3 commit ce9b9cb
Show file tree
Hide file tree
Showing 13 changed files with 392 additions and 236 deletions.
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ function createInitialSessionData (): BotSessionData {
languages: [],
enable: false
},
collections: {
activeCollections: [],
collectionRequestQueue: [],
isProcessingQueue: false
},
llms: {
model: config.llms.model,
isEnabled: config.llms.isEnabled,
Expand Down
25 changes: 22 additions & 3 deletions src/modules/document-handler/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type OnMessageContext, type PayableBot, type RefundCallback, RequestState } from '../types'
import * as Sentry from '@sentry/node'
import { now } from '../../utils/perf'
import { llmAddUrlDocument } from '../llms/api/llmApi'

const SupportedDocuments = { PDF: 'application/pdf' }

Expand All @@ -14,12 +15,16 @@ export class DocumentHandler implements PayableBot {
ctx.transient.analytics.module = this.module
try {
const file = await ctx.getFile()
const documentType = ctx.message.document?.mime_type
if (documentType === 'application/pdf' && ctx.chat.id) {
const pdfUrl = file.getUrl()
const fileName = ctx.message.document?.file_name ?? file.file_id
await this.addDocToCollection(ctx, ctx.chat.id, fileName, pdfUrl)
}
console.log(file)
await ctx.reply('you did it kid')
ctx.transient.analytics.sessionState = RequestState.Success
} catch (ex) {
Sentry.captureException(ex)
await ctx.reply('you failed kid')
ctx.transient.analytics.sessionState = RequestState.Error
} finally {
ctx.transient.analytics.actualResponseTime = now()
Expand All @@ -32,7 +37,21 @@ export class DocumentHandler implements PayableBot {
if (documentType !== undefined) {
return Object.values(SupportedDocuments).includes(documentType)
}

return false
}

private async addDocToCollection (ctx: OnMessageContext, chatId: number, fileName: string, pdfUrl: string): Promise<void> {
const collectionName = await llmAddUrlDocument({
chatId,
pdfUrl,
fileName
})
ctx.session.collections.collectionRequestQueue.push({
collectionName,
collectionType: 'PDF',
fileName,
url: pdfUrl
})
ctx.session.collections.isProcessingQueue = true
}
}
53 changes: 0 additions & 53 deletions src/modules/llms/api/liteLlm.ts

This file was deleted.

Loading

0 comments on commit ce9b9cb

Please sign in to comment.