diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/docs/src/content/docs/guides/pull-request-reviewer.mdx b/docs/src/content/docs/guides/pull-request-reviewer.mdx index b3cedb168b..853341bd75 100644 --- a/docs/src/content/docs/guides/pull-request-reviewer.mdx +++ b/docs/src/content/docs/guides/pull-request-reviewer.mdx @@ -2,6 +2,8 @@ title: Pull Request Reviewer sidebar: order: 20 +description: Learn how to automate pull request reviews with a GenAIScript that provides feedback and code analysis in GitHub Actions. +keywords: pull request automation, code review, GitHub Actions, GenAIScript reviewer, PR feedback --- import { Code } from '@astrojs/starlight/components'; import importedCode from "../../../../../packages/sample/genaisrc/pr-review.genai?raw" diff --git a/docs/src/content/docs/reference/cli/test.mdx b/docs/src/content/docs/reference/cli/test.mdx index 8d8a2e126a..c48410d7bb 100644 --- a/docs/src/content/docs/reference/cli/test.mdx +++ b/docs/src/content/docs/reference/cli/test.mdx @@ -2,6 +2,8 @@ title: Test sidebar: order: 3.5 +description: Learn how to run tests for your scripts using GenAIScript CLI with support for multiple AI models. +keywords: CLI testing, script tests, AI model testing, test viewer, GenAIScript CLI --- Runs the tests in scripts using [promptfoo](https://www.promptfoo.dev/). diff --git a/docs/src/content/docs/slides.md b/docs/src/content/docs/slides.md index 8aade330be..cdfd74d78c 100644 --- a/docs/src/content/docs/slides.md +++ b/docs/src/content/docs/slides.md @@ -7,6 +7,7 @@ description: Slides - [msr-eng-may2024](/genaiscript/slides/msr-eng-may2024/) - [networking-apr2024](/genaiscript/slides/networking-apr2024/) +- [overview-june2024](/genaiscript/slides/overview-june2024/) - [overview-may2024](/genaiscript/slides/overview-may2024/) - [pnw-plse-may2024](/genaiscript/slides/pnw-plse-may2024/) - [default](/genaiscript/slides/default/) diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/core/src/promptcontext.ts b/packages/core/src/promptcontext.ts index 329cebbe62..8303d1b535 100644 --- a/packages/core/src/promptcontext.ts +++ b/packages/core/src/promptcontext.ts @@ -166,29 +166,6 @@ export function createPromptContext( }, } - const defImages = (files: StringLike, defOptions?: DefImagesOptions) => { - const { detail } = defOptions || {} - if (Array.isArray(files)) - files.forEach((file) => defImages(file, defOptions)) - else if (typeof files === "string") - appendPromptChild(createImageNode({ url: files, detail })) - else { - const file: WorkspaceFile = files - appendPromptChild( - createImageNode( - (async () => { - const url = await resolveFileDataUri(file, { trace }) - return { - url, - filename: file.filename, - detail, - } - })() - ) - ) - } - } - const defOutputProcessor = (fn: PromptOutputProcessorHandler) => { if (fn) appendPromptChild(createOutputProcessor(fn)) } @@ -231,7 +208,6 @@ export function createPromptContext( XML, retrieval, host: promptHost, - defImages, defOutputProcessor, defChatParticipant, defFileMerge: (fn) => { diff --git a/packages/core/src/runpromptcontext.ts b/packages/core/src/runpromptcontext.ts index 8e513efc96..639361748d 100644 --- a/packages/core/src/runpromptcontext.ts +++ b/packages/core/src/runpromptcontext.ts @@ -6,6 +6,7 @@ import { createDefDataNode, createDefNode, createFunctionNode, + createImageNode, createSchemaNode, createStringTemplateNode, createTextNode, @@ -27,6 +28,7 @@ import { promptParametersSchemaToJSONSchema } from "./parameters" import { isJSONSchema } from "./schema" import { consoleLogFormat } from "./logging" import { host } from "./host" +import { resolveFileDataUri } from "./file" export interface RunPromptContextNode extends RunPromptContext { node: PromptNode @@ -78,6 +80,30 @@ export function createRunPromptContext( return name } + const defImages = (files: StringLike, defOptions?: DefImagesOptions) => { + const { detail } = defOptions || {} + if (Array.isArray(files)) + files.forEach((file) => defImages(file, defOptions)) + else if (typeof files === "string") + appendChild(node, createImageNode({ url: files, detail })) + else { + const file: WorkspaceFile = files + appendChild( + node, + createImageNode( + (async () => { + const url = await resolveFileDataUri(file, { trace }) + return { + url, + filename: file.filename, + detail, + } + })() + ) + ) + } + } + const ctx = { node, writeText: (body, options) => { @@ -140,6 +166,7 @@ export function createRunPromptContext( }, defTool, defSchema, + defImages, fence(body, options?: DefOptions) { ctx.def("", body, options) return undefined diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index 3e344fa8b5..f0bc4752cd 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -1233,6 +1233,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1495,7 +1496,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/genaisrc/describe-image-run-prompt.genai.js b/packages/sample/genaisrc/describe-image-run-prompt.genai.js new file mode 100644 index 0000000000..099544eb61 --- /dev/null +++ b/packages/sample/genaisrc/describe-image-run-prompt.genai.js @@ -0,0 +1,26 @@ +script({ + title: "Describe objects in each image", + model: "gpt-3.5-turbo", + maxTokens: 4000, + system: [], + tests: { + files: "src/robots.jpg", + keywords: "robot", + }, +}) + +for (const file of env.files) { + const res = await runPrompt( + (_) => { + _.$`Return the list of objects in the images.` + _.defImages(file, { detail: "low" }) + }, + { + model: "gpt-4-turbo-v", + maxTokens: 4000, + } + ) + def("OBJECTS", res.text) +} + +$`Summarize the objects in images.` diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText( diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index bf6432d9f5..5a4b02ac5a 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -1267,6 +1267,7 @@ interface RunPromptContext { generator: string | RunPromptGenerator, options?: RunPromptOptions ): Promise + defImages(files: StringLike, options?: DefImagesOptions): void defTool( name: string, description: string, @@ -1529,7 +1530,6 @@ interface ContainerHost extends ShellHost { interface PromptContext extends RunPromptContext { script(options: PromptArgs): void system(options: PromptSystemArgs): void - defImages(files: StringLike, options?: DefImagesOptions): void defFileMerge(fn: FileMergeHandler): void defOutputProcessor(fn: PromptOutputProcessorHandler): void fetchText(