-
Notifications
You must be signed in to change notification settings - Fork 132
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
Importtemplate #684
Importtemplate #684
Conversation
…ile mustache.ts and update imports in promptdom.ts
…for improved template interpolation
The changes seem to introduce a new feature to the underlying software. Here's a summary of the changes:
However, there are a few areas of concern:
Here's a possible improvement: @@ -0,0 +1,29 @@
+import { splitMarkdown } from "./frontmatter"
+import Mustache from "mustache"
+
+/**
+ * Applies mustache to the content of a markdown file.
+ * @param md
+ * @param data
+ * @returns
+ */
+export async function interpolateVariables(
+ md: string,
+ data: Record<string, any>
+): Promise<string> {
+ if (!md || !data) return md
+
+ // Validate the data to avoid misinterpretation of user data
+ if (!validateData(data)) {
+ throw new Error('Invalid data provided')
+ }
+
+ // remove frontmatter
+ let { content } = splitMarkdown(md)
+
+ content = Mustache.render(content, data ?? {})
+
+ return content
+}
|
``` | ||
|
||
```js title="tool.genai.mjs" | ||
importTemplate("cot.md"); |
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.
Incorrect code usage; importTemplate
is not a valid function or method in the provided context.
generated by pr-docs-review-commit
incorrect_code_usage
``` | ||
|
||
```js title="tool.genai.mjs" | ||
importTemplate("time.md", { time: "12:00" }); |
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.
Incorrect code usage; importTemplate
is not a valid function or method in the provided context.
generated by pr-docs-review-commit
incorrect_code_usage
Mustache supports arguments as functions. This allows you to pass dynamic values to the template. | ||
|
||
```js title="tool.genai.mjs" | ||
importTemplate("time.md", { time: () => Date.now() }); |
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.
Incorrect code usage; importTemplate
is not a valid function or method in the provided context.
generated by pr-docs-review-commit
incorrect_code_usage
You can specify an array of files or glob patterns. | ||
|
||
```js | ||
importTemplate("*.prompt") |
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.
Incorrect code usage; importTemplate
is not a valid function or method in the provided context.
generated by pr-docs-review-commit
incorrect_code_usage
``` | ||
|
||
```js title="tool.genai.mjs" | ||
importTemplate("basic.prompty", { question: "what is the capital of France?" }); |
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.
Incorrect code usage; importTemplate
is not a valid function or method in the provided context.
generated by pr-docs-review-commit
incorrect_code_usage
--- | ||
system: | ||
You are an AI assistant who helps people find information. | ||
As the assistant, you answer questions briefly, succinctly. |
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.
The sentence "As the assistant, you answer questions briefly, succinctly." could be clearer if rephrased to "As the assistant, you should answer questions briefly and succinctly."
generated by pr-docs-review-commit
content_clarity
importTemplate( | ||
files: string | string[], | ||
arguments?: Record<string | number | boolean | (() => string | number | boolean)>, | ||
options?: ImportTemplateOptions |
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.
The type of arguments
in the importTemplate
function is incorrect. It should be Record<string, string | number | boolean | (() => string | number | boolean)>
.
generated by pr-review-commit
incorrect_type
arguments?: Record< | ||
string | number | boolean | (() => string | number | boolean) | ||
>, | ||
options?: ImportTemplateOptions |
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.
The ImportTemplateOptions
type is used but not defined. This could lead to confusion and potential errors in the future.
generated by pr-review-commit
missing_type_definition
🆕 Added ability to import template prompts using
importTemplate
function in the genai context (found inpackages/core/src/runpromptcontext.ts
). This function dynamically loads and interpolates markdown files (found inimport-template.genai.mts
,basic.prompty
).🧩 Introduced a new
importTemplate
feature in theChatTurnGenerationContext
interface (found inpackages/core/src/types/prompt_template.d.ts
).📄Created new markdown files
basic.prompty
(underpackages/sample/src/
) andimport-template.genai.mts
(underpackages/sample/genaisrc/
) as part of the testing for the new function.🌟Updated function
createPromptContext
inpackages/core/src/promptcontext.ts
andrenderPromptNode
inpackages/core/src/promptdom.ts
to accommodate the newimportTemplate
feature.📚 In
packages/core/src/promptdom.ts
, updatedPromptNodeVisitor
andPromptNode
to manage import templates and their resolutions.🔄 Updated various package versions in
docs/package.json
,package.json
,packages/cli/package.json
andpackages/core/package.json
.📁 Added a new type interface for the import template in
packages/core/src/types/prompt_type.d.ts
.💡 Added test cases for the new interpolation feature in
packages/core/src/mustache.test.ts
.📦 Included mustache.js library for template manipulation in
packages/core/package.json
and created new usage inpackages/core/src/mustache.ts
.🤏 Minor method renaming in
packages/core/src/promptdom.ts
andpackages/core/src/promptcontext.ts
(fromcreateFileMergeNode
tocreateFileMerge
).Overall, these changes enhance the ability to dynamically handle and import templates, and improves the flexibility and usability of the API.