Skip to content

Commit

Permalink
enh: refactor and improve doc tracker code (#8182)
Browse files Browse the repository at this point in the history
Co-authored-by: Henry Fontanier <[email protected]>
  • Loading branch information
fontanierh and Henry Fontanier authored Oct 23, 2024
1 parent c0389c2 commit 0deb4d3
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
export async function callDocTrackerSuggestChangesAction(
auth: Authenticator,
sourceDocument: string,
targetDocument: string
): Promise<t.TypeOf<typeof DocTrackerSuggestChangesActionValueSchema>> {
trackedDocument: string
): Promise<DocTrackerSuggestChangesActionResult> {
const action = DustProdActionRegistry["doc-tracker-suggest-changes"];

const model = getLargeWhitelistedModel(auth.getNonNullableWorkspace());
Expand All @@ -28,8 +28,11 @@ export async function callDocTrackerSuggestChangesAction(
const res = await callAction(auth, {
action,
config,
input: { source_document: sourceDocument, target_document: targetDocument },
responseValueSchema: DocTrackerSuggestChangesActionValueSchema,
input: {
modified_document_diff: sourceDocument,
tracked_document: trackedDocument,
},
responseValueSchema: DocTrackerSuggestChangesActionResultSchema,
});

if (res.isErr()) {
Expand All @@ -39,14 +42,12 @@ export async function callDocTrackerSuggestChangesAction(
return res.value;
}

const DocTrackerSuggestChangesActionValueSchema = t.union([
t.type({
match: t.literal(false),
reason: t.string,
}),
t.type({
match: t.literal(true),
suggested_changes: t.string,
reason: t.string,
}),
]);
const DocTrackerSuggestChangesActionResultSchema = t.partial({
thinking: t.union([t.string, t.null, t.undefined]),
confidence_score: t.union([t.number, t.null, t.undefined]),
suggestion: t.union([t.string, t.null, t.undefined]),
});

type DocTrackerSuggestChangesActionResult = t.TypeOf<
typeof DocTrackerSuggestChangesActionResultSchema
>;
Loading

0 comments on commit 0deb4d3

Please sign in to comment.