-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: more robust parser to get suggested actions #65
feat: more robust parser to get suggested actions #65
Conversation
Signed-off-by: SuZhou-Joe <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## feature/agent-framework #65 +/- ##
============================================================
+ Coverage 58.67% 71.26% +12.58%
============================================================
Files 46 43 -3
Lines 1089 1023 -66
Branches 252 245 -7
============================================================
+ Hits 639 729 +90
+ Misses 441 292 -149
+ Partials 9 2 -7 ☔ View full report in Codecov by Sentry. |
@@ -13,19 +13,79 @@ const sanitize = (content: string) => { | |||
return DOMPurify.sanitize(content, { FORBID_TAGS: ['img'] }).replace(/!+\[/g, '['); | |||
}; | |||
|
|||
const isEveryItemString = (array?: unknown) => | |||
!!(Array.isArray(array) && array.every((item) => typeof item === 'string')); |
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.
seems don't need !!
as the result is boolean already
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.
Done.
const isEveryItemString = (array?: unknown) => | ||
!!(Array.isArray(array) && array.every((item) => typeof item === 'string')); | ||
|
||
export const parseSuggestedActions = (string: string): string[] => { |
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.
Nit: maybe rename string: string
-> value: string
? as it sounds a bit odd that the variable name and type are the same.
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.
Sure, done.
@@ -13,19 +13,79 @@ const sanitize = (content: string) => { | |||
return DOMPurify.sanitize(content, { FORBID_TAGS: ['img'] }).replace(/!+\[/g, '['); | |||
}; | |||
|
|||
const isEveryItemString = (array?: unknown) => |
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.
const isEveryItemString = (array?: unknown) => | |
const isEveryItemString = (array?: unknown): array is string[] => |
Maybe we can call it isStringArray
?
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.
Yeah, it stuck me when naming this function and you get the point of this. Change to isStringArray
.
const matchedResult = match && match[0]; | ||
|
||
if (!matchedResult) { | ||
return []; |
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.
Maybe add a test case to cover this line? When the output doesn't contain any json-like content.
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.
Done and thanks for catching.
Signed-off-by: SuZhou-Joe <[email protected]>
621b914
into
opensearch-project:feature/agent-framework
is there some prompt difference that causes agent framework to not output a consistent format for suggestions? |
) * feat: more robust parser to get suggested actions Signed-off-by: SuZhou-Joe <[email protected]> * feat: optimize code and optimize performance Signed-off-by: SuZhou-Joe <[email protected]> --------- Signed-off-by: SuZhou-Joe <[email protected]>
Will this be merged to main? |
Yeah, it has already. |
Description
The suggested actions tool may output a response like
We need a more robust parser to get the json inside the response and make it as our suggestions.
Issues Resolved
List any issues this PR will resolve, e.g. Closes [...].
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.