Skip to content
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

Improve automatic CSV format detection and simplify data definition in browse-text feature #674

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Aug 29, 2024

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 function haveSameKeysAndSimpleValues 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 in haveSameKeysAndSimpleValues 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 the createDefData 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". 🛠️

generated by pr-describe

Copy link

The changes in the GIT_DIFF show a new function haveSameKeysAndSimpleValues being introduced. This function appears to check if an array of objects all share the same set of keys, and if the values for these keys are of a simple type, such as a string, number, boolean, null, or undefined.

In the createDefData function, the logic for setting the format to "csv" has been updated. Previously, the format would be set to "csv" if headers was defined and data was an array. Now, the format will be set to "csv" if data is an array, data is not empty, and either headers is defined or haveSameKeysAndSimpleValues(data) returns true.

The changes seem to be well-implemented. They will allow the "csv" format to be chosen more dynamically, depending on the structure and type of the data being passed.

LGTM 🚀

generated by pr-review

@pelikhan pelikhan merged commit f0fc69a into main Aug 29, 2024
11 checks passed
@pelikhan pelikhan deleted the csv-on-same-keys-object branch August 29, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant