From 64364755961072640e4f03bed921a07ad25cd8c9 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 23 Sep 2024 14:31:11 +0000 Subject: [PATCH 01/11] removed scope --- .github/workflows/npm-publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index c07dc9e1a1..22b0d7a717 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -15,7 +15,6 @@ jobs: with: node-version: "20.x" registry-url: "https://npm.pkg.github.com" - scope: "genaiscript" cache: yarn - run: yarn install - run: yarn compile From c9ec7da5f93853e41d00a29b0487b63c04188f17 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 23 Sep 2024 14:37:04 +0000 Subject: [PATCH 02/11] Add npm login and whoami steps to npm-publish workflow --- .github/workflows/npm-publish.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 22b0d7a717..6107b310f1 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -18,6 +18,14 @@ jobs: cache: yarn - run: yarn install - run: yarn compile + - run: npm login --registry=https://npm.pkg.github.com + working-directory: packages/cli + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: npm whoami + working-directory: packages/cli + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: npm publish working-directory: packages/cli env: From 3ef6da55d3ac52a17d9e89bff7b4af8b283fdffb Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 23 Sep 2024 14:48:08 +0000 Subject: [PATCH 03/11] Update npm-publish.yml to streamline publish process and add git type to package.json --- .github/workflows/npm-publish.yml | 10 +--------- packages/cli/package.json | 1 + 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 6107b310f1..1ea7cef40c 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -18,15 +18,7 @@ jobs: cache: yarn - run: yarn install - run: yarn compile - - run: npm login --registry=https://npm.pkg.github.com - working-directory: packages/cli - env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - run: npm whoami - working-directory: packages/cli - env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - run: npm publish + - run: npm publish --userconfig ../../.npmrc working-directory: packages/cli env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/packages/cli/package.json b/packages/cli/package.json index 4fa92dd12d..6eb2b35a53 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -11,6 +11,7 @@ ], "publisher": "Microsoft", "repository": { + "type": "git", "url": "git+https://github.com/microsoft/genaiscript.git" }, "homepage": "https://microsoft.github.io/genaiscript", From 31ce9d5a1741d1fa45ad48f80e16f299bc4aa597 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 23 Sep 2024 14:53:22 +0000 Subject: [PATCH 04/11] use yarn publish --- .github/workflows/npm-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 1ea7cef40c..0999962418 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -18,7 +18,7 @@ jobs: cache: yarn - run: yarn install - run: yarn compile - - run: npm publish --userconfig ../../.npmrc + - run: yarn publish working-directory: packages/cli env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From ab66aa54fb07ab4b4e792235702a3fce2e2c59fe Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 23 Sep 2024 16:14:56 +0000 Subject: [PATCH 05/11] add reread sample, assistant helper --- .devcontainer/devcontainer.json | 3 ++- .vscode/extensions.json | 3 ++- .vscode/settings.json | 4 +++- docs/genaisrc/genaiscript.d.ts | 4 ++++ genaisrc/genaiscript.d.ts | 4 ++++ packages/auto/genaiscript.d.ts | 4 ++++ packages/core/src/genaisrc/genaiscript.d.ts | 4 ++++ packages/core/src/runpromptcontext.ts | 8 +++---- packages/core/src/types/prompt_template.d.ts | 4 ++++ .../sample/genaisrc/blog/genaiscript.d.ts | 4 ++++ packages/sample/genaisrc/genaiscript.d.ts | 4 ++++ .../sample/genaisrc/node/genaiscript.d.ts | 4 ++++ .../sample/genaisrc/python/genaiscript.d.ts | 4 ++++ packages/sample/genaisrc/reread.genai.mts | 21 +++++++++++++++++++ .../sample/genaisrc/style/genaiscript.d.ts | 4 ++++ packages/sample/src/aici/genaiscript.d.ts | 4 ++++ packages/sample/src/errors/genaiscript.d.ts | 4 ++++ packages/sample/src/genaiscript.d.ts | 4 ++++ packages/sample/src/makecode/genaiscript.d.ts | 4 ++++ packages/sample/src/tla/genaiscript.d.ts | 4 ++++ packages/sample/src/vision/genaiscript.d.ts | 4 ++++ packages/vscode/genaisrc/genaiscript.d.ts | 4 ++++ slides/genaisrc/genaiscript.d.ts | 4 ++++ 23 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 packages/sample/genaisrc/reread.genai.mts diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fec383a1dc..3095c445b9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,7 +15,8 @@ "file-icons.file-icons", "GitHub.vscode-pull-request-github", "johnpapa.vscode-peacock", - "usernamehw.errorlens" + "usernamehw.errorlens", + "goessner.mdmath" ] } }, diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 9374ae2bde..137035d640 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -12,6 +12,7 @@ "ms-toolsai.prompty", "unifiedjs.vscode-mdx", "johnpapa.vscode-peacock", - "usernamehw.errorlens" + "usernamehw.errorlens", + "goessner.mdmath" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 705f646724..7704b36272 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -53,6 +53,7 @@ "quoteify", "socketserver", "stringifying", + "structurify", "sysr", "tabletojson", "Textify", @@ -91,5 +92,6 @@ "titleBar.inactiveBackground": "#110f0099", "titleBar.inactiveForeground": "#e7e7e799" }, - "peacock.remoteColor": "#110f00" + "peacock.remoteColor": "#110f00", + "mdmath.delimiters": "brackets" } diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/auto/genaiscript.d.ts b/packages/auto/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/auto/genaiscript.d.ts +++ b/packages/auto/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/core/src/runpromptcontext.ts b/packages/core/src/runpromptcontext.ts index 928db284b1..6bd8dadaae 100644 --- a/packages/core/src/runpromptcontext.ts +++ b/packages/core/src/runpromptcontext.ts @@ -58,6 +58,8 @@ export function createChatTurnGenerationContext( ) } }, + assistant: (body, options) => + ctx.writeText(body, { ...options, assistant: true }), $(strings, ...args) { const current = createStringTemplateNode(strings, args) appendChild(node, current) @@ -105,11 +107,7 @@ export function createChatTurnGenerationContext( throw new Error(`def ${name} is empty`) appendChild( node, - createDef( - name, - { filename: "", content: body }, - doptions - ) + createDef(name, { filename: "", content: body }, doptions) ) } else if ( typeof body === "object" && diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index 5ce744e8db..97b7a8af73 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -1523,6 +1523,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/genaisrc/blog/genaiscript.d.ts b/packages/sample/genaisrc/blog/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/genaisrc/blog/genaiscript.d.ts +++ b/packages/sample/genaisrc/blog/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/genaisrc/reread.genai.mts b/packages/sample/genaisrc/reread.genai.mts new file mode 100644 index 0000000000..5aa26736f0 --- /dev/null +++ b/packages/sample/genaisrc/reread.genai.mts @@ -0,0 +1,21 @@ +// https://arxiv.org/abs/2309.06275 + +// math preview: goessner.mdmath +export async function reread( + question: string, + options?: PromptGeneratorOptions +) { + return await runPrompt((_) => { + _.writeText(question) + _.$`Read the question again:` + _.writeText(question) + _.assistant(`Let’s think step by step.`) + }, options) +} + +const res = + await reread(`Roger has 5 tennis balls. He buys 2 more cans of tennis +balls. Each can has 3 tennis balls. How many tennis balls +does he have now?`) + +console.log(res.text) diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/src/genaiscript.d.ts b/packages/sample/src/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/src/genaiscript.d.ts +++ b/packages/sample/src/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/packages/vscode/genaisrc/genaiscript.d.ts b/packages/vscode/genaisrc/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/packages/vscode/genaisrc/genaiscript.d.ts +++ b/packages/vscode/genaisrc/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index df355fd9fa..cebccd0b26 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -1556,6 +1556,10 @@ interface ChatTurnGenerationContext { options?: ImportTemplateOptions ): void writeText(body: Awaitable, options?: WriteTextOptions): void + assistant( + text: Awaitable, + options?: Omit + ): void $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString fence(body: StringLike, options?: FenceOptions): void def( From edd905fb093ced3228a33e884dc24358ec84eeda Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 23 Sep 2024 16:39:11 +0000 Subject: [PATCH 06/11] Add mixtureOfAgents function for multi-agent response generation and critique --- .../genaisrc/mixture-of-agents.genai.mts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 packages/sample/genaisrc/mixture-of-agents.genai.mts diff --git a/packages/sample/genaisrc/mixture-of-agents.genai.mts b/packages/sample/genaisrc/mixture-of-agents.genai.mts new file mode 100644 index 0000000000..bb1ba30289 --- /dev/null +++ b/packages/sample/genaisrc/mixture-of-agents.genai.mts @@ -0,0 +1,65 @@ +// https://github.com/codelion/optillm/blob/main/optillm/moa.py + +export async function mixtureOfAgents( + query: string, + options?: PromptGeneratorOptions & { agents: PromptGeneratorOptions[] } +) { + const { + agents = [ + { model: "gpt-4o" }, + { model: "gpt-4" }, + { model: "gpt-35-turbo" }, + ], + } = options ?? {} + + // compute agent responses + const agentResponses = [] + for (const agent of agents) { + const res = await runPrompt( + (ctx) => { + ctx.writeText(query) + ctx.assistant(`What do you think?`) + }, + { ...agent, label: agent.label || agent.model } + ) + agentResponses.push(res.text) + } + + // critique + const { text: critique } = await runPrompt( + async (_) => { + _.$`Original query:` + _.fence(query) + _.$`I will present you with ${agents.length} candidate responses to the original query. + Please analyze and critique each response, discussing their strengths and weaknesses. Provide your analysis for each candidate separately.` + for (let i = 0; i < agents.length; ++i) { + const ar = agentResponses[i] + _.def(`Candidate ${i + 1}`, ar) + } + _.$`Please provide your critique for each candidate:` + }, + { ...(options ?? {}), label: "critique" } + ) + + // final prompt + const { text: result } = await runPrompt( + async (_) => { + _.$`Original query:` + _.fence(query) + _.$`Based on the following candidate responses and their critiques, generate a final response to the original query.` + for (let i = 0; i < agents.length; ++i) { + const ar = agentResponses[i] + _.def(`Candidate ${i + 1}`, ar) + } + _.def(`Critique`, critique) + _.$`Please provide a final, optimized response to the original query:` + }, + { ...(options ?? {}), label: "final" } + ) + return result +} + +const res = await mixtureOfAgents( + `Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?` +) +console.log(res) From 7e491fef44c1311a654e9e5d05a1073223563675 Mon Sep 17 00:00:00 2001 From: pelikhan Date: Tue, 24 Sep 2024 09:08:21 +0000 Subject: [PATCH 07/11] [genai] generated blog posts --- ...-feedback-integration-from-user-testing.md | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 docs/src/content/docs/blog/drafts/enhancing-ui-ux-development-with-genaiscript-automating-feedback-integration-from-user-testing.md diff --git a/docs/src/content/docs/blog/drafts/enhancing-ui-ux-development-with-genaiscript-automating-feedback-integration-from-user-testing.md b/docs/src/content/docs/blog/drafts/enhancing-ui-ux-development-with-genaiscript-automating-feedback-integration-from-user-testing.md new file mode 100644 index 0000000000..0ce4c8086f --- /dev/null +++ b/docs/src/content/docs/blog/drafts/enhancing-ui-ux-development-with-genaiscript-automating-feedback-integration-from-user-testing.md @@ -0,0 +1,85 @@ +--- +title: "Enhancing UI/UX Development with GenAIScript: Automating Feedback + Integration from User Testing" +date: 2024-09-24 +authors: genaiscript +draft: true +tags: + - AI + - UI/UX + - Automation + - User Testing + - Feedback Integration + +--- + +In the rapidly evolving world of software development, feedback from users is invaluable. It not only helps in enhancing the product but also in refining user interfaces and experiences (UI/UX). However, manually collecting and integrating this feedback can be tedious and error-prone. Enter GenAIScript, a tool that automates this process seamlessly. In this blog post, we'll dive into how to set up a GenAIScript to automate the feedback integration process from user testing. + +### Define a Data Structure for User Feedback + +The first step in automating the feedback process is to define a structured format to store the feedback data. Here's how you can do it: + +```javascript +const feedbackData = defData({ + type: 'array', + items: { + type: 'object', + properties: { + userId: { type: 'string' }, + feedback: { type: 'string' }, + timestamp: { type: 'string', format: 'date-time' } + }, + required: ['userId', 'feedback', 'timestamp'] + } +}, "Feedback Data"); +``` + +This code snippet defines a data structure for storing feedback as an array of objects, where each object represents individual feedback from a user. The `defData` function is used to ensure that the data adheres to a specific schema. Each feedback object includes a `userId`, `feedback`, and a `timestamp`, all of which are required fields. + +### Fetch User Feedback from a Database or API + +Once the data structure is in place, the next step is to fetch the user feedback: + +```javascript +async function fetchFeedback() { + // Simulated fetch call + return [ + { userId: 'user1', feedback: 'Need more contrast in buttons', timestamp: '2023-10-01T12:00:00Z' }, + { userId: 'user2', feedback: 'Add more intuitive navigation', timestamp: '2023-10-02T12:00:00Z' } + ]; +} +``` + +This function simulates an asynchronous fetch call that retrieves feedback from users. In a real-world scenario, this function would interact with a database or an external API to fetch the feedback data. + +### Integrate Feedback into the Development Process + +After fetching the feedback, the next step is to integrate it into the development process: + +```javascript +function integrateFeedback(feedbackArray) { + feedbackArray.forEach(feedback => { + console.log(`Integrating feedback from user ${feedback.userId}: ${feedback.feedback}`); + // Here you would typically update the UI/UX based on the feedback + }); +} +``` + +This function takes an array of feedback and logs each piece of feedback to the console. The idea is to simulate the integration of feedback into the development process. In practice, this function would likely trigger updates to UI/UX elements based on the feedback received. + +### Main Execution Function + +Finally, we have the main function where everything comes together: + +```javascript +async function main() { + const feedback = await fetchFeedback(); + integrateFeedback(feedback); +} + +main(); +``` + +This async function orchestrates the whole process. It waits for the feedback to be fetched and then passes it to the `integrateFeedback` function. By calling `main()`, we kick off the script. + +By automating the feedback integration process, developers can quickly and efficiently make informed decisions to enhance their applications, leading to a better overall user experience. This script not only saves time but also ensures that user feedback is systematically integrated into the development lifecycle. \ No newline at end of file From d4ce41bc86ea8400ffe1e5c17dfecf24c48340da Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 24 Sep 2024 11:24:19 +0000 Subject: [PATCH 08/11] Update blog post to streamline content and reference new Search And Transform guide --- .../docs/blog/search-transform-genai.md | 139 +----------------- 1 file changed, 8 insertions(+), 131 deletions(-) diff --git a/docs/src/content/docs/blog/search-transform-genai.md b/docs/src/content/docs/blog/search-transform-genai.md index f7692fd442..cf51084f4e 100644 --- a/docs/src/content/docs/blog/search-transform-genai.md +++ b/docs/src/content/docs/blog/search-transform-genai.md @@ -6,142 +6,19 @@ tags: ["genai", "scripting", "automation"] canonical_url: https://microsoft.github.io/genaiscript/blog/search-transform-genai --- -## Introduction - Have you ever found yourself in a situation where you need to search through multiple files in your project, find a specific pattern, and then apply a transformation to it? It can be a tedious task, but fear not! In this blog post, I'll walk you through a GenAIScript that does just that, automating the process and saving you time. πŸ•’πŸ’‘ -The script we'll be examining is a powerful tool that can search for text patterns in files using regular expressions and apply a transformation to each match using language models. We will look at the script step-by-step to understand how it works. Let's get started! - -## The Script Explained - -First things first, you can find the script on GitHub at [st.genai.mts](https://github.com/microsoft/genaiscript/blob/main/packages/vscode/genaisrc/st.genai.mts). Now, let's break down the script. - -### Setting Up the Script - -```ts -script({ - title: "Search and transform", - description: - "Search for a pattern in files and apply a LLM transformation the match", - parameters: { - glob: { - type: "string", - description: "The glob pattern to filter files", - default: "*", - }, - pattern: { - type: "string", - description: "The text pattern (regular expression) to search for", - }, - transform: { - type: "string", - description: "The LLM transformation to apply to the match", - }, - }, -}) -``` - -The script starts by defining its purpose and parameters using the `script` function. Here, we define the title, description, and the three parameters the script will need: `glob` to specify the files, `pattern` for the text to search for, and `transform` for the desired transformation. - -### Extracting and Validating Parameters - -```ts -const { pattern, glob, transform } = env.vars -if (!pattern) cancel("pattern is missing") -const patternRx = new RegExp(pattern, "g") - -if (!transform) cancel("transform is missing") -``` - -Next, we extract the `pattern`, `glob`, and `transform` parameters from the environment variables and validate them. If `pattern` or `transform` are missing, the script will cancel execution. We then compile the `pattern` into a regular expression object for later use. - -### Searching for Files and Matches - -```ts -const { files } = await workspace.grep(patternRx, glob) -``` - -Here, we use the `grep` function from the `workspace` API to search for files that match the `glob` pattern and contain the regex pattern. - -### Transforming Matches +For example, when GenAIScript added the ability to use a string command string in +the `exec` command, we needed to convert all script using -```ts -// cached computed transformations -const patches = {} -for (const file of files) { - console.log(file.filename) - const { content } = await workspace.readText(file.filename) - // skip binary files - if (!content) continue - // compute transforms - for (const match of content.matchAll(patternRx)) { - console.log(` ${match[0]}`) - if (patches[match[0]]) continue +```js +host.exec("cmd", ["arg0", "arg1", "arg2"]) ``` -We initialize an object called `patches` to store the transformations. Then, we loop through each file, read its content, and skip binary files. For each match found in the file's content, we check if we've already computed a transformation for this match to avoid redundant work. +to -### Generating Prompts for Transformations - -```ts - const res = await runPrompt( - (_) => { - _.$` - ## Task - - Your task is to transform the MATCH with the following TRANSFORM. - Return the transformed text. - - do NOT add enclosing quotes. - - ## Context - ` - _.def("MATCHED", match[0]) - _.def("TRANSFORM", transform) - }, - { label: match[0], system: [], cache: "search-and-transform" } - ) -``` - -For each unique match, we generate a prompt using the `runPrompt` function. In the prompt, we define the task and context for the transformation, specifying that the transformed text should be returned without enclosing quotes. We also define the matched text and the transformation to apply. - -### Applying the Transformation - -```ts - const transformed = res.fences?.[0].content ?? res.text - if (transformed) patches[match[0]] = transformed - console.log(` ${match[0]} -> ${transformed ?? "?"}`) - } - // apply transforms - const newContent = content.replace( - patternRx, - (match) => patches[match] ?? match - ) -``` - -We then extract the transformed text from the prompt result and store it in the `patches` object. Finally, we apply the transformations to the file content using `String.prototype.replace`. - -### Saving the Changes - -```ts - if (content !== newContent) - await workspace.writeText(file.filename, newContent) -} +```js +host.exec(`cmd arg0 arg1 arg2`)` ``` -If the file content has changed after applying the transformations, we save the updated content back to the file. - -## Running the Script - -To run this script, you'll need the GenAIScript CLI. Check out the [installation guide](https://microsoft.github.io/genaiscript/getting-started/installation) if you need to set it up. Once you have the CLI, run the script by executing: - -```bash -genaiscript run st -``` - -Be sure to replace `st` with the actual name of your script if you've named it differently. - -## Conclusion - -This script is a fantastic example of how GenAIScript can simplify complex tasks like searching and transforming text across multiple files. By following the steps outlined, you can create your own scripts to automate your workflows and boost your productivity. Happy scripting! πŸš€ - -Remember to check out the script on GitHub and tweak it to suit your needs. If you have any questions or want to share your own scripting experiences, feel free to leave a comment below! +The [Search And Transform guide](/genaiscript/guides/search-and-transform) covers the detail on this new approach... From 938abb78f66c612ecdb3cba8a497c9db5a289d40 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 24 Sep 2024 07:26:57 -0700 Subject: [PATCH 09/11] Commentor (#723) * Add comments and logging improvements, enhance cache handling, and support multiple glob patterns * Add comments for code clarity and update script configurations * Improve comments and add validation for non-comment changes in chatcache and documentor files * Enhance TOML parsing and refactor code with improved comment handling and formatting * Refactor systems resolution and enhance comment generator script logic * Add comments, docstrings, and enhance code readability across multiple files * Remove defaultBranch parameter and dynamically resolve default branch from git configuration * Add header comment to cmt.genai.mts file * Remove CLI run documentation, add VSCode commenter sample, and improve counting.py comments * Add documentation for running genai scripts with CLI options and configurations * Add Samples section and adjust paths in docs for better organization --- .vscode/settings.json | 1 + docs/astro.config.mjs | 4 + docs/genaisrc/genaiscript.d.ts | 6 +- .../docs/reference/cli/{run.md => run.mdx} | 4 +- .../content/docs/reference/scripts/system.mdx | 2 +- docs/src/content/docs/samples/cmt.mdx | 79 +++++++ .../{reference/vscode => }/samples/gcm.mdx | 4 +- .../{reference/vscode => }/samples/iat.mdx | 4 +- .../{reference/vscode => }/samples/prd.mdx | 4 +- .../{reference/vscode => }/samples/rv.mdx | 4 +- .../{reference/vscode => }/samples/st.mdx | 4 +- genaisrc/genaiscript.d.ts | 6 +- packages/auto/genaiscript.d.ts | 6 +- packages/core/src/cache.ts | 29 ++- packages/core/src/cancellation.ts | 9 + packages/core/src/changelog.test.ts | 115 ++++++++++ packages/core/src/chatcache.ts | 9 + packages/core/src/chatencoder.ts | 28 ++- packages/core/src/chatrender.ts | 73 +++++-- packages/core/src/diff.test.ts | 199 ++++++++++++++++++ packages/core/src/diff.ts | 7 +- packages/core/src/genaisrc/genaiscript.d.ts | 6 +- .../src/genaisrc/system.changelog.genai.js | 2 +- packages/core/src/glob.ts | 11 +- packages/core/src/promptrunner.ts | 7 +- packages/core/src/runpromptcontext.ts | 9 +- packages/core/src/systems.ts | 26 ++- packages/core/src/toml.ts | 10 + packages/core/src/types/prompt_template.d.ts | 4 +- packages/core/src/types/prompt_type.d.ts | 2 +- .../sample/genaisrc/blog/genaiscript.d.ts | 6 +- packages/sample/genaisrc/genaiscript.d.ts | 6 +- .../sample/genaisrc/node/genaiscript.d.ts | 6 +- .../sample/genaisrc/python/genaiscript.d.ts | 6 +- .../sample/genaisrc/style/genaiscript.d.ts | 6 +- packages/sample/src/aici/genaiscript.d.ts | 6 +- packages/sample/src/counting.py | 24 ++- packages/sample/src/errors/genaiscript.d.ts | 6 +- packages/sample/src/genaiscript.d.ts | 6 +- packages/sample/src/makecode/genaiscript.d.ts | 6 +- packages/sample/src/tla/genaiscript.d.ts | 6 +- packages/sample/src/vision/genaiscript.d.ts | 6 +- packages/vscode/genaisrc/cmt.genai.mts | 100 +++++++++ packages/vscode/genaisrc/genaiscript.d.ts | 6 +- packages/vscode/genaisrc/prd.genai.mts | 15 +- slides/genaisrc/genaiscript.d.ts | 6 +- 46 files changed, 775 insertions(+), 116 deletions(-) rename docs/src/content/docs/reference/cli/{run.md => run.mdx} (96%) create mode 100644 docs/src/content/docs/samples/cmt.mdx rename docs/src/content/docs/{reference/vscode => }/samples/gcm.mdx (96%) rename docs/src/content/docs/{reference/vscode => }/samples/iat.mdx (97%) rename docs/src/content/docs/{reference/vscode => }/samples/prd.mdx (97%) rename docs/src/content/docs/{reference/vscode => }/samples/rv.mdx (97%) rename docs/src/content/docs/{reference/vscode => }/samples/st.mdx (97%) create mode 100644 packages/vscode/genaisrc/cmt.genai.mts diff --git a/.vscode/settings.json b/.vscode/settings.json index 7704b36272..bde2173f0b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,6 +15,7 @@ "demux", "devcontainers", "dockerode", + "docstrings", "doptions", "Entra", "Evals", diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index d19da02e95..8d0f2705ab 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -54,6 +54,10 @@ export default defineConfig({ label: "Case Studies", autogenerate: { directory: "case-studies" }, }, + { + label: "Samples", + autogenerate: { directory: "samples" }, + }, { label: "Guides", autogenerate: { directory: "guides" }, diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index cebccd0b26..a0a2d39fdf 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -1512,7 +1512,7 @@ interface FileOutputOptions { } interface FileOutput { - pattern: string + pattern: string[] description?: string options?: FileOutputOptions } @@ -1609,7 +1609,7 @@ interface ChatGenerationContext extends ChatTurnGenerationContext { options?: ChatParticipantOptions ): void defFileOutput( - pattern: string, + pattern: string | string[], description?: string, options?: FileOutputOptions ): void @@ -2453,7 +2453,7 @@ declare function def( * @param options expectations about the generated file content */ declare function defFileOutput( - pattern: string, + pattern: string | string[], description?: string, options?: FileOutputOptions ): void diff --git a/docs/src/content/docs/reference/cli/run.md b/docs/src/content/docs/reference/cli/run.mdx similarity index 96% rename from docs/src/content/docs/reference/cli/run.md rename to docs/src/content/docs/reference/cli/run.mdx index efd620fde6..897cab567f 100644 --- a/docs/src/content/docs/reference/cli/run.md +++ b/docs/src/content/docs/reference/cli/run.mdx @@ -34,7 +34,7 @@ See [configuration](/genaiscript/getting-started/configuration). ## Files -`run` takes one or more [glob](https://en.wikipedia.org/wiki/Glob_(programming)) patterns to match files in the workspace. +`run` takes one or more [glob]() patterns to match files in the workspace. ```bash sh npx genaiscript run