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

Update defImages function to support multiple file types and handle Blob conversion #705

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/genaisrc/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"preview": "astro preview",
"astro": "astro",
"genai:test": "node ../packages/cli/built/genaiscript.cjs test src/**/*.md",
"genai:frontmatter": "node ../packages/cli/built/genaiscript.cjs run frontmatter \"src/**/*.md\" --apply-edits",
"genai:frontmatter": "node ../packages/cli/built/genaiscript.cjs run frontmatter \"src/**/*.{md,mdx}\" --apply-edits",
"genai:technical": "for file in \"src/**/*.md\"; do\nnode ../packages/cli/built/genaiscript.cjs run technical \"$file\" --apply-edits\ndone",
"genai:alt-text": "node scripts/image-alt-text.mjs"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ tags:
- Project Management
- Automation
- GenAIScript
description: Employ GenAIScript to automate GitHub issue triage with AI,
improving project management and issue resolution efficiency.
keywords: GitHub issues, AI, project management, automation, issue triage

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ tags:
- Automation
- Testing
- Deployment
description: Streamline your DevOps pipeline with GenAIScript by automating
testing and deployment through a tutorial script.
keywords: DevOps, automation, testing, deployment, scripting

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ tags:
- Programming
- Efficiency
draft: true
description: Leverage AI with GenAIScript to improve your debugging skills,
featuring a practical example for an efficient workflow.
keywords: AI, debugging, programming efficiency, developer tools, GenAIScript

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ tags:
- Dynamic Content Generation
- AI
- Automation
description: Discover how GenAIScript can automate dynamic content generation
using AI, with an easy-to-understand script example.
keywords: dynamic content, automation, AI, content generation, scripting

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ tags:
- Test Automation
- Software Development
- Best Practices
description: Explore test automation using GenAIScript to enhance and streamline
your testing processes with structured script breakdown.
keywords: test automation, scripting, software testing, streamlined process,
developer tools

---

Expand Down
5 changes: 4 additions & 1 deletion docs/src/content/docs/case-studies/release-notes.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
title: Release Notes
sidebar:
order: 7
order: 7
description: Generate comprehensive release notes combining commit history and code diffs
keywords: release notes, automation, commit history, code diffs, release management

---
import { Code } from '@astrojs/starlight/components';
import scriptSrc from "../../../../../packages/sample/genaisrc/git-release-notes.genai?raw"
Expand Down
9 changes: 6 additions & 3 deletions docs/src/content/docs/guides/auto-git-commit-message.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---
title: "Automated Git Commit Messages"
keywords: ["GenAI", "Git", "Automation"]
title: Automated Git Commit Messages
keywords: Git, commit automation, software development, CLI, husky
sidebar:
order: 15
order: 15
description: Streamline your Git workflow with an automation script for
generating commit messages

---

In the world of software development, making consistent and informative commit messages is crucial but often overlooked.
Expand Down
100 changes: 100 additions & 0 deletions docs/src/content/docs/guides/images-in-azure-blob-storage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: Images in Azure Blob Storage
sidebar:
order: 55
description: Leverage Azure SDK to handle image files in Blob Storage within prompts
keywords: Azure Blob Storage, Azure SDK, image handling, Node.js Buffer, inline prompts

---

import { Code } from '@astrojs/starlight/components';
import { Steps } from "@astrojs/starlight/components"
import source from "../../../../../packages/sample/genaisrc/azure-blobs.genai.mts?raw"

It is possible to use the Azure Node.JS SDK to download images from Azure Blog Storage

Check failure on line 14 in docs/src/content/docs/guides/images-in-azure-blob-storage.mdx

View workflow job for this annotation

GitHub Actions / build

Typo in the word "Blog", should be "Blob".

Choose a reason for hiding this comment

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

There is a typo in "Blog" which should be "Blob".

generated by pr-docs-review-commit typo

and use them in the prompt. The `defImages` function support the node.js [Buffer] type.

Check failure on line 15 in docs/src/content/docs/guides/images-in-azure-blob-storage.mdx

View workflow job for this annotation

GitHub Actions / build

Typo in the function name "defImages", should be "defImage".

Choose a reason for hiding this comment

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

The function name defImages should be defImage to match the function used in the other documentation file.

generated by pr-docs-review-commit typo


## Configuration

Install the [@azure/storage-blob](https://www.npmjs.com/package/@azure/storage-blob) and [@azure/identity](https://www.npmjs.com/package/@azure/identity) packages.

```sh
npm install -D @azure/storage-blob @azure/identity
```

Make sure to login with the Azure CLI and set the subscription.

```sh
az login
```

## Reading blobs

Open a connection to the Azure Blob Storage and get a client to the container.
We deconstruct the `account` and `container` from the `env.vars` object
so that they can be set through the [cli](/genaiscript/reference/cli).

Choose a reason for hiding this comment

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

The link provided for [cli] is incorrect or broken, it should be a valid URL or path to the CLI reference.

generated by pr-docs-review-commit broken_link


```ts
import { BlobServiceClient } from "@azure/storage-blob"
import { DefaultAzureCredential } from "@azure/identity"

const { account = "myblobs", container = "myimages" } = env.vars
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
new DefaultAzureCredential()
)
const containerClient = blobServiceClient.getContainerClient(container)
```

If you do not have a specific blob in mind, you can iterate through the blobs,
and download them into a buffer (`buf`).

```ts "image"

Choose a reason for hiding this comment

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

The code fence "image" is incorrect or unnecessary, it should be removed.

generated by pr-docs-review-commit incorrect_code_fence

Choose a reason for hiding this comment

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

The code comment "image" seems to be misplaced or incorrect.

generated by pr-docs-review-commit incorrect_code_comment

import { buffer } from "node:stream/consumers"

for await (const blob of containerClient.listBlobsFlat()) {
const blockBlobClient = containerClient.getBlockBlobClient(blob.name)
const downloadBlockBlobResponse = await blockBlobClient.download(0)
const body = await downloadBlockBlobResponse.readableStreamBody
const image = await buffer(body)
...
```

## Using images in the prompt

The `image` buffer can be passed in `defImages` to be used in the prompt.

```ts
defImages(image, { detail: "low" })
```

However since images can be "heavy", you will most likely have to use

Choose a reason for hiding this comment

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

The sentence "However since images can be 'heavy', you will most likely have to use" could be clarified to specify that "heavy" refers to large file sizes which may require more processing time or resources.

generated by pr-docs-review-commit clarity

[inline prompts](/genaiscript/reference/prompts/inline-prompts) to split into smaller queries. (Note the use of `_.`)

```ts 'await runPrompt(_ =>' '_.'

Choose a reason for hiding this comment

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

There is a syntax error in the code snippet, the single quotes and backticks are not correctly paired.

generated by pr-docs-review-commit syntax_error

Choose a reason for hiding this comment

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

The code fence 'await runPrompt(_ =>' ' _.' is incorrect or unnecessary, it should be removed.

generated by pr-docs-review-commit incorrect_code_fence

for await (const blob of containerClient.listBlobsFlat()) {
...
const res = await runPrompt(_ => {
_.defImages(image, { detail: "low" })
_.$`Describe the image.`
})
// res contains the LLM response for the inner prompt
...
```

## Summarizing results

To summarize all images, we store each image summary using the `def` function and
add prompting to summarize the descriptions.

```ts
...
def("IMAGES_SUMMARY", { filename: blob.name, content: res.text })
}
$`Summarize IMAGES_SUMMARY.`
```

## Full source

<Code code={source} wrap={true} lang="js" title="azure-blobs.genai.mts" />

Choose a reason for hiding this comment

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

The variable source is used but not defined in the document, which might confuse readers. It should be clearly defined or explained.

generated by pr-docs-review-commit missing_reference


5 changes: 4 additions & 1 deletion docs/src/content/docs/guides/llm-as-tool.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
title: LLM as a tool
sidebar:
order: 60
order: 60
description: Create tools and inline prompts using LLM models for executing various tasks
keywords: LLM, inline prompts, tools, gpt-3.5-turbo, task automation

---

It is possible [tools](/genaiscript/reference/scripts/tools)
Expand Down
7 changes: 6 additions & 1 deletion docs/src/content/docs/guides/transformers-js.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
---
title: Transformer.js
sidebar:
order: 20
order: 20
description: Implement summarization with Transformers.js and leverage local
hardware acceleration
keywords: Transformers.js, summarization, onnxruntime, CPU/GPU acceleration,
pretrained models

---
import { Code } from "@astrojs/starlight/components"
import sampleSrc from "../../../../../packages/sample/genaisrc/summary-with-transformers.genai?raw"
Expand Down
3 changes: 3 additions & 0 deletions docs/src/content/docs/guides/using-secrets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
title: Using Secrets
sidebar:
order: 20
description: Utilize secrets to augment documents with TypeScript and REST APIs
keywords: TypeScript, secrets, REST API, document augmentation, web search

---
import { Code } from '@astrojs/starlight/components';
import tavilyCode from "../../../../../packages/sample/genaisrc/tavily.mjs?raw"
Expand Down
3 changes: 3 additions & 0 deletions docs/src/content/docs/guides/zod-schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
title: Zod Schema
sidebar:
order: 80
description: Learn how to define and convert TypeScript-first Zod schemas to JSON schema
keywords: TypeScript, Zod schema, JSON schema, schema validation, type inference

---

[zod](https://zod.dev/) is a TypeScript-first schema validation with static type inference.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
title: Chat Participants
sidebar:
order: 50
order: 50
description: Create multi-turn chats or simulate conversations with multiple
chat participants
keywords: chat, multi-turn, conversation, chat participant, engagement

---
import { Code } from '@astrojs/starlight/components';
import scriptSource from "../../../../../../packages/sample/genaisrc/multi-turn.genai.js?raw"
Expand Down
26 changes: 26 additions & 0 deletions docs/src/content/docs/reference/scripts/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,29 @@
```

Read more about [OpenAI Vision](https://platform.openai.com/docs/guides/vision/limitations).

## URLs

Public URLs (that do not require authentication) will be passed directly to OpenAI.

```js
defImages(
"https://github.com/microsoft/genaiscript/blob/main/docs/public/images/logo.png?raw=true"
)
```

Local files are loaded and encoded as a data uri.

## Buffer, Blob

The `defImages` function also supports [Buffer](https://nodejs.org/api/buffer.html)
and [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob).


This example takes a screenshot of bing.com and adds it to the images.

Check failure on line 37 in docs/src/content/docs/reference/scripts/images.md

View workflow job for this annotation

GitHub Actions / build

Typo in the word "bing.com", should be "Bing.com" as it is a proper noun.

Choose a reason for hiding this comment

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

Typo in the word "bing.com", should be "Bing.com" as it is a proper noun.

generated by pr-docs-review-commit typo


```js
const page = await host.browse("https://bing.com")
const screenshot = await page.screenshot() // returns a node.js Buffer

Choose a reason for hiding this comment

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

The function 'page.screenshot' is used but not defined in the documentation. There should be a definition or reference for it.

generated by pr-docs-review-commit missing_function_definition

defImages(screenshot)

Choose a reason for hiding this comment

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

The function 'host.browse' is used but not defined in the documentation. There should be a definition or reference for it.

generated by pr-docs-review-commit missing_function_definition

```
6 changes: 5 additions & 1 deletion docs/src/content/docs/reference/scripts/prompty.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
title: Prompty
sidebar:
order: 51
order: 51
description: Learn about the .prompty file format for parameterized prompts and
its integration with GenAIScript for AI scripting.
keywords: prompty, scripts, AI, parameterized prompts, automation

---

GenAIScript supports running [.prompty](https://prompty.ai/) files as scripts (with some limitations).
Expand Down
6 changes: 4 additions & 2 deletions genaisrc/genaiscript.d.ts

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

6 changes: 4 additions & 2 deletions packages/core/src/genaisrc/genaiscript.d.ts

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

Loading