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

Add mustache template rendering support to parsers #685

Merged
merged 2 commits into from
Sep 4, 2024
Merged

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Sep 3, 2024

This pull request adds support for rendering mustache templates in the parsers module. It includes changes to the parsers.ts file, where a new mustache function is added. This function takes a text string or a WorkspaceFile and data as input and returns the rendered template as a string. This feature enhances the functionality of the parsers module by allowing the rendering of dynamic content using mustache templates.

  • 📝 A new constant, mustacheRender, is exported from the module located at packages/core/src/mustache.ts. This seems to be wrapping the render function of Mustache, a logic-less template syntax.

  • 🧩 In packages/core/src/parsers.ts, mustacheRender is imported from the mustache module. This adds a new functionality to the createParsers function. Specifically, it introduces the ability to render mustache templates. The function utilizes mustacheRender, applied on the content of a file (f) with supplied args.

  • 👥 From a user perspective, a new method has been defined in the public API packages/core/src/types/prompt_template.d.ts. The method, mustache, allows users to render mustache templates by passing a string or a file as a template and a record object as data. This change enhances the public API, giving more flexibility and tools to the users.

These changes show the focus on enhancing the template rendering capabilities of the system. By incorporating Mustache, template rendering becomes more flexible and powerful. 🚀

generated by pr-describe

Copy link

github-actions bot commented Sep 3, 2024

The changes in the GIT_DIFF seem reasonable at a glance. A new functionality is added to render mustache templates. These changes include:

  1. mustacheRender function is exported in mustache.ts.

  2. In parsers.ts, the createParsers function is extended with a new mustache method, which uses the mustacheRender function to render the content of a file with provided arguments.

  3. prompt_template.d.ts is updated with a new mustache method in the Parsers interface.

However, there are some concerns:

  1. In parsers.ts, filenameOrFileToContent function is called to convert file to its content, but the function is not imported or defined anywhere in the same file. This might result in a runtime error.
-import { unzip } from "./zip"
+import { unzip, filenameOrFileToContent } from "./zip"
  1. The space between mustacheRender and { is missing on mustacheRender{ in parsers.ts.
-import { mustacheRender} from "./mustache"
+import { mustacheRender } from "./mustache"

Please consider these suggestions.

generated by pr-review

* @param text
* @param data
*/
mustache(text: string | WorkspaceFile, data: Record<string, any>): string
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing parameter description for text and data in the function mustache. It's a good practice to provide descriptions for all parameters in a function to improve code readability and maintainability. 📘

generated by pr-review-commit missing_param_desc

@pelikhan pelikhan merged commit 927306d into main Sep 4, 2024
10 checks passed
@pelikhan pelikhan deleted the mustacheparser branch September 4, 2024 11:43
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