-
Notifications
You must be signed in to change notification settings - Fork 269
Improved dev tracing P1 #1993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Improved dev tracing P1 #1993
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,17 @@ import { database } from '../../../client' | |
| import { | ||
| ATTR_GEN_AI_REQUEST_PARAMETERS, | ||
| ATTR_GEN_AI_REQUEST_TEMPLATE, | ||
| ATTR_LATITUDE_PROMPT_PATH, | ||
| HEAD_COMMIT, | ||
| LogSources, | ||
| SPAN_SPECIFICATIONS, | ||
| SpanType, | ||
| } from '../../../constants' | ||
| import { Result } from '../../../lib/Result' | ||
| import { | ||
| CommitsRepository, | ||
| DocumentVersionsRepository, | ||
| } from '../../../repositories' | ||
| import { SpanProcessArgs } from './shared' | ||
|
|
||
| const specification = SPAN_SPECIFICATIONS[SpanType.Prompt] | ||
|
|
@@ -16,8 +22,8 @@ export const PromptSpanSpecification = { | |
| } | ||
|
|
||
| async function process( | ||
| { attributes }: SpanProcessArgs<SpanType.Prompt>, | ||
| _ = database, | ||
| { attributes, workspace }: SpanProcessArgs<SpanType.Prompt>, | ||
| db = database, | ||
| ) { | ||
| let parameters: Record<string, unknown> | ||
| try { | ||
|
|
@@ -28,17 +34,84 @@ async function process( | |
| parameters = {} | ||
| } | ||
|
|
||
| return Result.ok({ | ||
| // Get promptUuid from attributes, or try to resolve from promptPath | ||
| let promptUuid = attributes['latitude.documentUuid'] as string | undefined | ||
| const promptPath = attributes[ATTR_LATITUDE_PROMPT_PATH] as string | undefined | ||
| const projectId = attributes['latitude.projectId'] as number | undefined | ||
| const versionUuid = | ||
| (attributes['latitude.commitUuid'] as string) || HEAD_COMMIT | ||
|
|
||
| // If promptPath is provided but promptUuid is not, resolve it | ||
| if (promptPath && !promptUuid && projectId) { | ||
| const resolvedUuid = await resolvePromptPathToUuid({ | ||
| promptPath, | ||
| projectId, | ||
| versionUuid, | ||
| workspaceId: workspace.id, | ||
| db, | ||
| }) | ||
| if (resolvedUuid) promptUuid = resolvedUuid | ||
| } | ||
|
|
||
| const result = { | ||
| parameters, | ||
| template: attributes[ATTR_GEN_AI_REQUEST_TEMPLATE] as string, | ||
| externalId: attributes['latitude.externalId'] as string, | ||
|
|
||
| // References | ||
| experimentUuid: attributes['latitude.experimentUuid'] as string, | ||
| promptUuid: attributes['latitude.documentUuid'] as string, | ||
| versionUuid: attributes['latitude.commitUuid'] as string, | ||
| promptUuid, | ||
| promptPath, | ||
| versionUuid, | ||
| documentLogUuid: attributes['latitude.documentLogUuid'] as string, | ||
| projectId: attributes['latitude.projectId'] as number, | ||
| projectId, | ||
| source: attributes['latitude.source'] as LogSources, | ||
| }) | ||
| } | ||
|
|
||
| return Result.ok(result) | ||
| } | ||
|
|
||
| /** | ||
| * Resolves a prompt path to its document UUID by looking up the document | ||
| * in the specified project and version. | ||
| */ | ||
| async function resolvePromptPathToUuid({ | ||
| promptPath, | ||
| projectId, | ||
| versionUuid, | ||
| workspaceId, | ||
| db, | ||
| }: { | ||
| promptPath: string | ||
| projectId: number | ||
| versionUuid: string | ||
| workspaceId: number | ||
| db: typeof database | ||
| }): Promise<string | undefined> { | ||
| try { | ||
| // Get the commit | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for this comment, its self explanatory |
||
| const commitsRepo = new CommitsRepository(workspaceId, db) | ||
| const commitResult = await commitsRepo.getCommitByUuid({ | ||
| uuid: versionUuid, | ||
| projectId, | ||
| }) | ||
| if (commitResult.error) { | ||
| return undefined | ||
| } | ||
| const commit = commitResult.value | ||
|
|
||
| // Get the document by path | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| const docsRepo = new DocumentVersionsRepository(workspaceId, db) | ||
| const docResult = await docsRepo.getDocumentByPath({ | ||
| commit, | ||
| path: promptPath, | ||
| }) | ||
| if (docResult.error) { | ||
| return undefined | ||
| } | ||
|
|
||
| return docResult.value.documentUuid | ||
| } catch { | ||
| return undefined | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './processors' | ||
| export * from './sdk' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { NormalizingSpanProcessor } from './normalize' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to hace this barrel file? |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: instead of a comment and the logic in the if, create a constant with a readable name and add it to the if