From 239f3af6bd26d299c44ec02c163fd86458cdeb88 Mon Sep 17 00:00:00 2001 From: pelikhan Date: Tue, 10 Dec 2024 09:46:33 -0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E2=9E=95=20Add=20Markdown=20and=20?= =?UTF-8?q?plaintext=20output=20systems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/docs/reference/scripts/system.mdx | 20 ++++++++++++++++--- packages/core/src/genaisrc/system.genai.mjs | 4 +--- .../genaisrc/system.output_markdown.genai.mjs | 3 +++ .../src/genaisrc/system.output_plaintext.mjs | 4 ++++ packages/core/src/mcp.ts | 1 - packages/core/src/systems.ts | 1 + 6 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 packages/core/src/genaisrc/system.output_markdown.genai.mjs create mode 100644 packages/core/src/genaisrc/system.output_plaintext.mjs diff --git a/docs/src/content/docs/reference/scripts/system.mdx b/docs/src/content/docs/reference/scripts/system.mdx index 3b88d76829..2f444c68d5 100644 --- a/docs/src/content/docs/reference/scripts/system.mdx +++ b/docs/src/content/docs/reference/scripts/system.mdx @@ -88,9 +88,7 @@ Base system prompt `````js wrap title="system" system({ title: "Base system prompt" }) -$`- You are concise. -- Answer in markdown. -` +$`- You are concise.` ````` @@ -2567,6 +2565,22 @@ defTool( ````` +### `system.output_markdown` + +Base system prompt + + + + + +`````js wrap title="system.output_markdown" +system({ title: "Base system prompt" }) +$`## Markdown Output +Respond in Markdown (GitHub Flavored Markdown also supported).` + +````` + + ### `system.planner` Instruct to make a plan diff --git a/packages/core/src/genaisrc/system.genai.mjs b/packages/core/src/genaisrc/system.genai.mjs index 861abc9af4..0d2b6532fd 100644 --- a/packages/core/src/genaisrc/system.genai.mjs +++ b/packages/core/src/genaisrc/system.genai.mjs @@ -1,4 +1,2 @@ system({ title: "Base system prompt" }) -$`- You are concise. -- Answer in markdown. -` +$`- You are concise.` diff --git a/packages/core/src/genaisrc/system.output_markdown.genai.mjs b/packages/core/src/genaisrc/system.output_markdown.genai.mjs new file mode 100644 index 0000000000..d2da20b8ff --- /dev/null +++ b/packages/core/src/genaisrc/system.output_markdown.genai.mjs @@ -0,0 +1,3 @@ +system({ title: "Base system prompt" }) +$`## Markdown Output +Respond in Markdown (GitHub Flavored Markdown also supported).` diff --git a/packages/core/src/genaisrc/system.output_plaintext.mjs b/packages/core/src/genaisrc/system.output_plaintext.mjs new file mode 100644 index 0000000000..389a7c896b --- /dev/null +++ b/packages/core/src/genaisrc/system.output_plaintext.mjs @@ -0,0 +1,4 @@ +system({ title: "Plain text output" }) +$`## Plain Text Output +Respond in plain text. Do not wrap result in Markdown code fences or XML tags. +` diff --git a/packages/core/src/mcp.ts b/packages/core/src/mcp.ts index 25753f5d16..58563fa4d7 100644 --- a/packages/core/src/mcp.ts +++ b/packages/core/src/mcp.ts @@ -5,7 +5,6 @@ import type { ImageContent, EmbeddedResource, } from "@modelcontextprotocol/sdk/types.js" -import { YAMLStringify } from "./yaml" export async function startMcpServer( serverConfig: McpServerConfig, diff --git a/packages/core/src/systems.ts b/packages/core/src/systems.ts index 14acb09819..8bd3ec18f0 100644 --- a/packages/core/src/systems.ts +++ b/packages/core/src/systems.ts @@ -36,6 +36,7 @@ export function resolveSystems( // Default systems if no responseType is specified if (!script.responseType) { systems.push("system") + systems.push("system.output_markdown") systems.push("system.explanations") systems.push("system.safety_jailbreak") systems.push("system.safety_harmful_content") From 745b4568e431a37445cd696597659dbb085a8015 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 10 Dec 2024 19:47:33 +0000 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20plaintext=20outpu?= =?UTF-8?q?t=20script=20and=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/docs/reference/scripts/system.mdx | 17 +++++++++++++++++ ...xt.mjs => system.output_plaintext.genai.mjs} | 0 packages/sample/genaisrc/plaintext.genai.mjs | 5 +++++ 3 files changed, 22 insertions(+) rename packages/core/src/genaisrc/{system.output_plaintext.mjs => system.output_plaintext.genai.mjs} (100%) create mode 100644 packages/sample/genaisrc/plaintext.genai.mjs diff --git a/docs/src/content/docs/reference/scripts/system.mdx b/docs/src/content/docs/reference/scripts/system.mdx index 2f444c68d5..cd3533e640 100644 --- a/docs/src/content/docs/reference/scripts/system.mdx +++ b/docs/src/content/docs/reference/scripts/system.mdx @@ -2581,6 +2581,23 @@ Respond in Markdown (GitHub Flavored Markdown also supported).` ````` +### `system.output_plaintext` + +Plain text output + + + + + +`````js wrap title="system.output_plaintext" +system({ title: "Plain text output" }) +$`## Plain Text Output +Respond in plain text. Do not wrap result in Markdown code fences or XML tags. +` + +````` + + ### `system.planner` Instruct to make a plan diff --git a/packages/core/src/genaisrc/system.output_plaintext.mjs b/packages/core/src/genaisrc/system.output_plaintext.genai.mjs similarity index 100% rename from packages/core/src/genaisrc/system.output_plaintext.mjs rename to packages/core/src/genaisrc/system.output_plaintext.genai.mjs diff --git a/packages/sample/genaisrc/plaintext.genai.mjs b/packages/sample/genaisrc/plaintext.genai.mjs new file mode 100644 index 0000000000..ad64a8e4a7 --- /dev/null +++ b/packages/sample/genaisrc/plaintext.genai.mjs @@ -0,0 +1,5 @@ +script({ + system: ["system", "system.output_plaintext"] +}) + +$`Generate a random recipe.` \ No newline at end of file From 81ca956e3a0a88a0a85319a550ac9e90523c1bf3 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 10 Dec 2024 20:55:14 +0000 Subject: [PATCH 3/5] fix basic test --- docs/src/content/docs/reference/scripts/prompty.md | 2 +- packages/core/src/constants.ts | 3 --- packages/sample/src/templates/basic.prompty | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/src/content/docs/reference/scripts/prompty.md b/docs/src/content/docs/reference/scripts/prompty.md index 79383f5158..be80b13804 100644 --- a/docs/src/content/docs/reference/scripts/prompty.md +++ b/docs/src/content/docs/reference/scripts/prompty.md @@ -58,7 +58,7 @@ This is what the `basic.prompty` file compiles to: ```js wrap title="basic.prompty.genai.mts" script({ - model: "azure:gpt-4o", + model: "openai:gpt-4o", title: "Basic Prompt", description: "A basic prompt that uses the chat API to answer questions", parameters: { diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index 29fc475679..098334ca39 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -57,7 +57,6 @@ export const VISION_MODEL_ID = "vision" export const DEFAULT_FENCE_FORMAT: FenceFormat = "xml" export const DEFAULT_MODEL = "openai:gpt-4o" export const DEFAULT_MODEL_CANDIDATES = [ - "azure:gpt-4o", "azure_serverless:gpt-4o", DEFAULT_MODEL, "google:gemini-1.5-pro-latest", @@ -68,7 +67,6 @@ export const DEFAULT_MODEL_CANDIDATES = [ ] export const DEFAULT_VISION_MODEL = "openai:gpt-4o" export const DEFAULT_VISION_MODEL_CANDIDATES = [ - "azure:gpt-4o", "azure_serverless:gpt-4o", DEFAULT_MODEL, "google:gemini-1.5-flash-latest", @@ -77,7 +75,6 @@ export const DEFAULT_VISION_MODEL_CANDIDATES = [ ] export const DEFAULT_SMALL_MODEL = "openai:gpt-4o-mini" export const DEFAULT_SMALL_MODEL_CANDIDATES = [ - "azure:gpt-4o-mini", "azure_serverless:gpt-4o-mini", DEFAULT_SMALL_MODEL, "google:gemini-1.5-flash-latest", diff --git a/packages/sample/src/templates/basic.prompty b/packages/sample/src/templates/basic.prompty index 565dfe32fa..88f73a7cdf 100644 --- a/packages/sample/src/templates/basic.prompty +++ b/packages/sample/src/templates/basic.prompty @@ -5,7 +5,7 @@ model: api: chat configuration: type: azure_openai - azure_deployment: gpt-4o + azure_deployment: gpt-4o_2024-08-06 parameters: max_tokens: 128 temperature: 0.2 From 42db415f5085e8e91a944f318870bc43978f4756 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 10 Dec 2024 21:01:05 +0000 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=F0=9F=8D=B0=20update=20recipe=20ge?= =?UTF-8?q?neration=20with=20carrot=20focus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/sample/genaisrc/plaintext.genai.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/sample/genaisrc/plaintext.genai.mjs b/packages/sample/genaisrc/plaintext.genai.mjs index ad64a8e4a7..33a7b6b2fa 100644 --- a/packages/sample/genaisrc/plaintext.genai.mjs +++ b/packages/sample/genaisrc/plaintext.genai.mjs @@ -1,5 +1,9 @@ script({ - system: ["system", "system.output_plaintext"] + model: "small", + system: ["system", "system.output_plaintext"], + tests: { + keywords: "carrots", + }, }) -$`Generate a random recipe.` \ No newline at end of file +$`Generate a random recipe with carrots.` From b80aa5c6edba2eb4866571842927aa4b6dc3909d Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 10 Dec 2024 21:07:59 +0000 Subject: [PATCH 5/5] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20rename=20syste?= =?UTF-8?q?m=20prompt=20and=20add=20automation=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/docs/reference/scripts/system.mdx | 22 ++++++++++++++++--- packages/core/bundleprompts.js | 22 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/docs/src/content/docs/reference/scripts/system.mdx b/docs/src/content/docs/reference/scripts/system.mdx index cd3533e640..8590444c21 100644 --- a/docs/src/content/docs/reference/scripts/system.mdx +++ b/docs/src/content/docs/reference/scripts/system.mdx @@ -12,7 +12,7 @@ System prompts are scripts that are executed and injected before the main prompt - system prompts must use the `system` instead of `script` - system prompts are executed with the same environment as the main prompt -```js title="system.zscot.genai.js" "system" +```js title="system.zero_shot_cot.genai.js" "system" system({ title: "Zero-shot Chain of Thought", }) @@ -22,10 +22,10 @@ $`Let's think step by step.` To use system prompts in script, populate the `system` field with script identifiers. -```js title="myscript.genai.js" 'system: ["system.zscot"]' +```js title="myscript.genai.js" 'system: ["system.zero_shot_cot"]' script({ ..., - system: ["system.zscot"] + system: ["system.zero_shot_cot"] }) $`Let's think step by step.` ``` @@ -73,6 +73,22 @@ script({ ..., }) ``` +## Automated System Prompts + +When unspecified, GenAIScript inspects the source code of the script +to determine a reasonable set of system prompts ([source code](https://github.com/microsoft/genaiscript/blob/main/packages/core/src/systems.ts)). + +The default mix is + +- system +- system.output_markdown +- system.explanations +- system.safety_jailbreak +- system.safety_harmful_content +- system.safety_protected_material + +On top of the default, injects other system scripts based on keyword matching. + ## Builtin System Prompts GenAIScript comes with a number of system prompt that support features like creating files, extracting diffs or diff --git a/packages/core/bundleprompts.js b/packages/core/bundleprompts.js index 16b22ab4b4..99d2e15adc 100644 --- a/packages/core/bundleprompts.js +++ b/packages/core/bundleprompts.js @@ -135,7 +135,7 @@ System prompts are scripts that are executed and injected before the main prompt - system prompts must use the \`system\` instead of \`script\` - system prompts are executed with the same environment as the main prompt -\`\`\`js title="system.zscot.genai.js" "system" +\`\`\`js title="system.zero_shot_cot.genai.js" "system" system({ title: "Zero-shot Chain of Thought", }) @@ -145,10 +145,10 @@ $\`Let's think step by step.\` To use system prompts in script, populate the \`system\` field with script identifiers. -\`\`\`js title="myscript.genai.js" 'system: ["system.zscot"]' +\`\`\`js title="myscript.genai.js" 'system: ["system.zero_shot_cot"]' script({ ..., - system: ["system.zscot"] + system: ["system.zero_shot_cot"] }) $\`Let's think step by step.\` \`\`\` @@ -196,6 +196,22 @@ script({ ..., }) \`\`\` +## Automated System Prompts + +When unspecified, GenAIScript inspects the source code of the script +to determine a reasonable set of system prompts ([source code](https://github.com/microsoft/genaiscript/blob/main/packages/core/src/systems.ts)). + +The default mix is + +- system +- system.output_markdown +- system.explanations +- system.safety_jailbreak +- system.safety_harmful_content +- system.safety_protected_material + +On top of the default, injects other system scripts based on keyword matching. + ## Builtin System Prompts GenAIScript comes with a number of system prompt that support features like creating files, extracting diffs or