Improve automatic CSV format detection and simplify data definition in browse-text feature #674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request improves the automatic CSV format detection in the browse-text feature. It simplifies the data definition by checking if the data has the same keys and simple values. Additionally, it removes the need to specify the format as "csv" when using the
defData
function.In the file
packages/core/src/promptdom.ts
, a new functionhaveSameKeysAndSimpleValues
has been introduced. It checks if all objects within the provided array have the same structure (same keys) and simple values (string, number, boolean, null, undefined). 👀In the same file, the function
createDefData
has been modified. Now, if no format is specified, but the data is an array and has either a length or matches the conditions defined inhaveSameKeysAndSimpleValues
function, it will default to the 'csv' format. This adds a new layer of intelligence to the format determination process! 🤖In the file
packages/sample/genaisrc/browse-text.genai.mts
, a line of code has been changed that defines the format of the data. Earlier, the format "csv" was explicitly defined for the data, but now it relies on the improved logic in thecreateDefData
function mentioned above. Less redundancy, more reliance on core functions! ✨Note: These changes seem to primarily improve the handling and default formatting of data arrays, particularly with regard to CSV formatting. How that changes the user experience really depends on the impact of these changes to any public APIs in "packages/core/src/prompt_template.d.ts" and "packages/core/src/prompt_type.ts". 🛠️