From cb63718743d43a7967a1a7d78c7b6e5bf1f5d464 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Wed, 14 Jun 2023 22:59:58 -0700 Subject: [PATCH] fix: JSON utils unit tests --- src/human-feedback/feedback.ts | 7 ++++++- src/task.ts | 1 - src/utils.ts | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/human-feedback/feedback.ts b/src/human-feedback/feedback.ts index c82bf5c8..3ae3c55d 100644 --- a/src/human-feedback/feedback.ts +++ b/src/human-feedback/feedback.ts @@ -1,3 +1,4 @@ +import * as types from '@/types' import { Agentic } from '@/agentic' import { BaseTask } from '@/task' @@ -257,7 +258,11 @@ export abstract class HumanFeedbackMechanism< } } -export function withHumanFeedback( +export function withHumanFeedback< + TInput extends void | types.JsonObject, + TOutput extends types.JsonObject, + V extends HumanFeedbackType +>( task: BaseTask, options: HumanFeedbackOptions = {} ) { diff --git a/src/task.ts b/src/task.ts index 864f6b03..de8b9a03 100644 --- a/src/task.ts +++ b/src/task.ts @@ -4,7 +4,6 @@ import { ZodType } from 'zod' import * as errors from './errors' import * as types from './types' import type { Agentic } from './agentic' -import { defaultLogger } from './logger' import { defaultIDGeneratorFn, isValidTaskIdentifier } from './utils' /** diff --git a/src/utils.ts b/src/utils.ts index 075c9968..d5954a71 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,7 +9,7 @@ import * as types from './types' * @returns extracted JSON object string, or `undefined` if no JSON object is found */ export function extractJSONObjectFromString(text: string): string | undefined { - return text.match(/\{(.|\n)*\}/gm)?.[0] + return text.match(/\{([^}]|\n)*\}/gm)?.[0] } /** @@ -19,7 +19,7 @@ export function extractJSONObjectFromString(text: string): string | undefined { * @returns extracted JSON array string, or `undefined` if no JSON array is found */ export function extractJSONArrayFromString(text: string): string | undefined { - return text.match(/\[(.|\n)*\]/gm)?.[0] + return text.match(/\[([^\]]|\n)*\]/gm)?.[0] } /**