-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: trace completion types (PL-909) (#520)
Introduce completion trace types for use in LLM responses. The start trace will indicate which type of trace should be used, as well as any additional metadata it needs (voice for speak, delay for text). The end trace signals it is done. Co-authored-by: Tyler Stewart <git@tylerstewart.ca>
- Loading branch information
Showing
7 changed files
with
95 additions
and
7 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
18 changes: 18 additions & 0 deletions
18
packages/base-types/src/trace/completion/completion-continue-trace.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,18 @@ | ||
import type { BaseTraceFrame } from '@base-types/node/utils'; | ||
import { TraceType } from '@base-types/node/utils'; | ||
|
||
export interface CompletionContinueTrace extends BaseTraceFrame<CompletionContinueTracePayload> { | ||
type: TraceType.COMPLETION_CONTINUE; | ||
} | ||
|
||
export interface CompletionContinueTracePayload { | ||
completion: string; | ||
tokens?: { | ||
answer: number; | ||
query: number; | ||
total: number; | ||
}; | ||
} | ||
|
||
export const isCompletionContinueTrace = (trace: BaseTraceFrame): trace is CompletionContinueTrace => | ||
trace.type === TraceType.COMPLETION_CONTINUE; |
9 changes: 9 additions & 0 deletions
9
packages/base-types/src/trace/completion/completion-end-trace.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 type { BaseTraceFrame } from '@base-types/node/utils'; | ||
import { TraceType } from '@base-types/node/utils'; | ||
|
||
export interface CompletionEndTrace extends BaseTraceFrame { | ||
type: TraceType.COMPLETION_END; | ||
} | ||
|
||
export const isCompletionEndTrace = (trace: BaseTraceFrame): trace is CompletionEndTrace => | ||
trace.type === TraceType.COMPLETION_END; |
46 changes: 46 additions & 0 deletions
46
packages/base-types/src/trace/completion/completion-start-trace.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,46 @@ | ||
import type { BaseTraceFrame } from '@base-types/node/utils'; | ||
import { TraceType } from '@base-types/node/utils'; | ||
|
||
export interface CompletionStartTrace extends BaseTraceFrame<BaseCompletionStartTracePayload> { | ||
type: TraceType.COMPLETION_START; | ||
} | ||
|
||
export interface CompletionStartTraceSpeak extends CompletionStartTrace { | ||
payload: CompletionStartTraceSpeakPayload; | ||
} | ||
|
||
export interface CompletionStartTraceText extends CompletionStartTrace { | ||
payload: CompletionStartTraceTextPayload; | ||
} | ||
|
||
export type CompletionStartTracePayload = CompletionStartTraceSpeakPayload | CompletionStartTraceTextPayload; | ||
|
||
export interface CompletionStartTraceSpeakPayload extends BaseCompletionStartTracePayload { | ||
type: TraceType.SPEAK; | ||
voice?: string; | ||
} | ||
|
||
export interface CompletionStartTraceTextPayload extends BaseCompletionStartTracePayload { | ||
type: TraceType.TEXT; | ||
delay?: number; | ||
} | ||
|
||
export interface BaseCompletionStartTracePayload { | ||
type: TraceType.TEXT | TraceType.SPEAK; | ||
completion: string; | ||
tokens?: { | ||
model: string; | ||
answer: number; | ||
query: number; | ||
total: number; | ||
}; | ||
} | ||
|
||
export const isCompletionStartTrace = (trace: BaseTraceFrame): trace is CompletionStartTrace => | ||
trace.type === TraceType.COMPLETION_START; | ||
|
||
export const isCompletionStartTraceSpeak = (trace: CompletionStartTrace): trace is CompletionStartTraceSpeak => | ||
trace.payload.type === TraceType.SPEAK; | ||
|
||
export const isCompletionStartTraceText = (trace: CompletionStartTrace): trace is CompletionStartTraceText => | ||
trace.payload.type === TraceType.TEXT; |
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,3 @@ | ||
export * from './completion-continue-trace'; | ||
export * from './completion-end-trace'; | ||
export * from './completion-start-trace'; |
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