Skip to content

Commit

Permalink
Merge branch 'main' into commentprovifer
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan authored Sep 24, 2024
2 parents fb64388 + 65e6ba9 commit 4838865
Show file tree
Hide file tree
Showing 61 changed files with 1,454 additions and 371 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"file-icons.file-icons",
"GitHub.vscode-pull-request-github",
"johnpapa.vscode-peacock",
"usernamehw.errorlens"
"usernamehw.errorlens",
"goessner.mdmath"
]
}
},
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ jobs:
with:
node-version: "20.x"
registry-url: "https://npm.pkg.github.com"
scope: "genaiscript"
cache: yarn
- run: yarn install
- run: yarn compile
- run: npm publish
- run: yarn publish
working-directory: packages/cli
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"ms-toolsai.prompty",
"unifiedjs.vscode-mdx",
"johnpapa.vscode-peacock",
"usernamehw.errorlens"
"usernamehw.errorlens",
"goessner.mdmath"
]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"demux",
"devcontainers",
"dockerode",
"docstrings",
"doptions",
"Entra",
"Evals",
Expand Down Expand Up @@ -53,6 +54,7 @@
"quoteify",
"socketserver",
"stringifying",
"structurify",
"sysr",
"tabletojson",
"Textify",
Expand Down Expand Up @@ -91,5 +93,6 @@
"titleBar.inactiveBackground": "#110f0099",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.remoteColor": "#110f00"
"peacock.remoteColor": "#110f00",
"mdmath.delimiters": "brackets"
}
4 changes: 4 additions & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export default defineConfig({
label: "Case Studies",
autogenerate: { directory: "case-studies" },
},
{
label: "Samples",
autogenerate: { directory: "samples" },
},
{
label: "Guides",
autogenerate: { directory: "guides" },
Expand Down
10 changes: 7 additions & 3 deletions docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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.
139 changes: 8 additions & 131 deletions docs/src/content/docs/blog/search-transform-genai.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Original file line number Diff line number Diff line change
Expand Up @@ -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](<https://en.wikipedia.org/wiki/Glob_(programming)>) patterns to match files in the workspace.

```bash sh
npx genaiscript run <script> "**/*.md" "**/*.ts"
Expand Down Expand Up @@ -150,7 +150,7 @@ permissions:
pull-requests: write
```

- set the `GITHUB_TOKEN` secret in the `env` when running the cli
- set the `GITHUB_TOKEN` secret in the `env` when running the cli

```yaml
- run: npx --yes genaiscript run ... -prc --out-trace $GITHUB_STEP_SUMMARY
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ index N in the above snippets, and then be prefixed with exactly the same whites
the original snippets above. See also the following examples of the expected response format.
CHANGELOG:
\`\`\`
\`\`\`changelog
ChangeLog:1@<file>
Description: <summary>.
OriginalCode@4-6:
Expand Down
Loading

0 comments on commit 4838865

Please sign in to comment.