-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Introduced a new job `uploadDocumentLogsJob` to handle bulk uploads of document logs from CSV files. - Added `createDocumentLogJob` to create individual document logs from parsed CSV data. - Updated `messageSchema` and `messagesSchema` to validate message structures. - Implemented `bulkUploadDocumentLogs` service to parse CSV files and enqueue jobs for processing. - Modified `ProviderLogsRepository` to include additional joins for better data retrieval. - Enhanced `createProviderLog` to handle optional fields and avoid errors when certain data is missing. - Updated various components to handle nullable fields and provide default values where necessary. - Added new constants for delimiter values and maximum upload size. - Updated SDK to include a new `log` method for logging messages and responses. These changes enable users to upload large sets of document logs in bulk, improving efficiency and user experience. The new job definitions and services ensure that the logs are processed asynchronously, reducing the load on the main application.
- Loading branch information
Showing
73 changed files
with
1,157 additions
and
555 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
3 changes: 1 addition & 2 deletions
3
apps/gateway/src/routes/api/v1/conversations/[conversationUuid]/index.ts
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import ROUTES from '$/common/routes' | ||
import { Hono } from 'hono' | ||
|
||
import { chatHandler } from './handlers/chat' | ||
|
||
export const chatsRouter = new Hono() | ||
|
||
chatsRouter.post(ROUTES.Api.V1.Conversations.Chat, ...chatHandler) | ||
chatsRouter.post('/:conversationUuid/chat', ...chatHandler) |
7 changes: 4 additions & 3 deletions
7
.../gateway/src/routes/api/v1/projects/[projectId]/versions/[versionUuid]/documents/index.ts
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import ROUTES from '$/common/routes' | ||
import { Hono } from 'hono' | ||
|
||
import { getHandler } from './handlers/get' | ||
import { runHandler } from './handlers/run' | ||
import { logsRouterV1 } from './logs' | ||
|
||
const router = new Hono() | ||
|
||
router.get(ROUTES.Api.V1.Documents.Get, ...getHandler) | ||
router.post(ROUTES.Api.V1.Documents.Run, ...runHandler) | ||
router.get('/:documentPath{.+}', ...getHandler) | ||
router.post('/run', ...runHandler) | ||
router.route('/logs', logsRouterV1) | ||
|
||
export { router as documentsRouter } |
8 changes: 8 additions & 0 deletions
8
...way/src/routes/api/v1/projects/[projectId]/versions/[versionUuid]/documents/logs/index.ts
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,8 @@ | ||
import { postHandler } from '$/routes/api/v2/projects/[projectId]/versions/[versionUuid]/documents/logs/handlers/post' | ||
import { Hono } from 'hono' | ||
|
||
const router = new Hono() | ||
|
||
router.post('/', ...postHandler) | ||
|
||
export { router as logsRouterV1 } |
3 changes: 1 addition & 2 deletions
3
apps/gateway/src/routes/api/v2/conversations/[conversationUuid]/index.ts
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import ROUTES from '$/common/routes' | ||
import { chatHandler } from '$/routes/api/v1/conversations/[conversationUuid]/handlers/chat' | ||
import { Hono } from 'hono' | ||
|
||
export const chatsRouter = new Hono() | ||
|
||
chatsRouter.post(ROUTES.Api.V2.Conversations.Chat, ...chatHandler) | ||
chatsRouter.post('/:conversationUuid/chat', ...chatHandler) |
7 changes: 4 additions & 3 deletions
7
.../gateway/src/routes/api/v2/projects/[projectId]/versions/[versionUuid]/documents/index.ts
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import ROUTES from '$/common/routes' | ||
import { getHandler } from '$/routes/api/v1/projects/[projectId]/versions/[versionUuid]/documents/handlers/get' | ||
import { Hono } from 'hono' | ||
|
||
import { runHandler } from './handlers/run' | ||
import { logsRouterV2 } from './logs' | ||
|
||
const router = new Hono() | ||
|
||
router.get(ROUTES.Api.V2.Documents.Get, ...getHandler) | ||
router.post(ROUTES.Api.V2.Documents.Run, ...runHandler) | ||
router.get('/:documentPath{.+}', ...getHandler) | ||
router.post('/run', ...runHandler) | ||
router.route('/logs', logsRouterV2) | ||
|
||
export { router as documentsRouter } |
50 changes: 50 additions & 0 deletions
50
...routes/api/v2/projects/[projectId]/versions/[versionUuid]/documents/logs/handlers/post.ts
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,50 @@ | ||
import { zValidator } from '@hono/zod-validator' | ||
import { LogSources, messagesSchema } from '@latitude-data/core/browser' | ||
import { generateUUIDIdentifier } from '@latitude-data/core/lib/generateUUID' | ||
import { createDocumentLog } from '@latitude-data/core/services/documentLogs/create' | ||
import { getData } from '$/routes/api/v1/projects/[projectId]/versions/[versionUuid]/documents/handlers/_shared' | ||
import { Factory } from 'hono/factory' | ||
import { z } from 'zod' | ||
|
||
const factory = new Factory() | ||
|
||
const schema = z.object({ | ||
path: z.string(), | ||
messages: messagesSchema, | ||
response: z.string().optional(), | ||
}) | ||
|
||
export const postHandler = factory.createHandlers( | ||
zValidator('json', schema), | ||
async (c) => { | ||
const { projectId, versionUuid } = c.req.param() | ||
const { path, messages, response } = c.req.valid('json') | ||
const workspace = c.get('workspace') | ||
const { document, commit } = await getData({ | ||
workspace, | ||
projectId: Number(projectId!), | ||
commitUuid: versionUuid!, | ||
documentPath: path!, | ||
}).then((r) => r.unwrap()) | ||
|
||
const documentLog = await createDocumentLog({ | ||
data: { | ||
uuid: generateUUIDIdentifier(), | ||
documentUuid: document.documentUuid, | ||
resolvedContent: document.content, | ||
source: LogSources.API, | ||
parameters: {}, | ||
providerLog: { | ||
messages, | ||
responseText: | ||
response ?? | ||
(messages[messages.length - 1].content?.text || | ||
messages[messages.length - 1].content), | ||
}, | ||
}, | ||
commit, | ||
}).then((r) => r.unwrap()) | ||
|
||
return c.json(documentLog) | ||
}, | ||
) |
9 changes: 9 additions & 0 deletions
9
...way/src/routes/api/v2/projects/[projectId]/versions/[versionUuid]/documents/logs/index.ts
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,9 @@ | ||
import { Hono } from 'hono' | ||
|
||
import { postHandler } from './handlers/post' | ||
|
||
const router = new Hono() | ||
|
||
router.post('/', ...postHandler) | ||
|
||
export { router as logsRouterV2 } |
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 was deleted.
Oops, something went wrong.
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,50 @@ | ||
'use server' | ||
|
||
import { | ||
DELIMITERS_KEYS, | ||
MAX_SIZE, | ||
MAX_UPLOAD_SIZE_IN_MB, | ||
} from '@latitude-data/core/browser' | ||
import { CommitsRepository } from '@latitude-data/core/repositories' | ||
import { bulkUploadDocumentLogs } from '@latitude-data/core/services/documentLogs/bulkUpload' | ||
import { z } from 'zod' | ||
|
||
import { withDocument } from '../procedures' | ||
|
||
export const uploadDocumentLogsAction = withDocument | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
csvDelimiter: z.enum(DELIMITERS_KEYS, { | ||
message: 'Choose a valid delimiter option', | ||
}), | ||
logsFile: z | ||
.instanceof(File) | ||
.refine((file) => { | ||
return !file || file.size <= MAX_UPLOAD_SIZE_IN_MB | ||
}, `Your file must be less than ${MAX_SIZE}MB in size`) | ||
.refine( | ||
(file) => file.type === 'text/csv', | ||
'Your file must be a CSV file', | ||
), | ||
}), | ||
) | ||
.handler(async ({ ctx, input }) => { | ||
const commitsScope = new CommitsRepository(ctx.workspace.id) | ||
const commit = await commitsScope | ||
.getCommitByUuid({ | ||
projectId: ctx.project.id, | ||
uuid: ctx.currentCommitUuid, | ||
}) | ||
.then((r) => r.unwrap()) | ||
|
||
await bulkUploadDocumentLogs({ | ||
workspace: ctx.workspace, | ||
document: ctx.document, | ||
commit, | ||
csvDelimiter: input.csvDelimiter, | ||
logsFile: input.logsFile, | ||
}) | ||
|
||
return { success: true } | ||
}) |
Oops, something went wrong.