From f979f59def27440c54e953883b71e26e4bde89f2 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 7 Nov 2024 11:22:46 -0800 Subject: [PATCH] Add ad hoc tool call system message support (#833) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adding ad hoc tool call system message * feat: enhance tool call documentation and functionality ✨ * adding tool calls system prompt * more tuning * more tool calls * feat: ✨ add disable model tools option * feat: ✨ Add tests and enhance tool documentation * maintain list of models without tools support * updated flag name * filter o1 models * refactor: 🔧 update system prompt handling logic * auto-detect unsupported tools * feat: 🔧 rename `--disable-model-tools` to `--fallback-tools` * refactor: 🛠️ update tool call syntax and add GitHub models * more docs --- .vscode/settings.json | 3 + README.md | 5 +- docs/src/content/docs/index.mdx | 1 + .../content/docs/reference/cli/commands.md | 7 +- .../content/docs/reference/scripts/system.mdx | 70 ++++++++++- .../content/docs/reference/scripts/tools.mdx | 75 +++++++++--- packages/cli/src/cli.ts | 13 ++- packages/cli/src/run.ts | 2 + packages/core/src/chat.ts | 97 ++++++++++++---- packages/core/src/expander.ts | 24 ++-- packages/core/src/genaisrc/system.genai.js | 1 - .../src/genaisrc/system.tool_calls.genai.mjs | 56 +++++++++ packages/core/src/generation.ts | 1 + packages/core/src/openai.ts | 2 +- packages/core/src/parameters.test.ts | 109 ++++++++++++++++++ packages/core/src/parameters.ts | 39 ++++--- packages/core/src/promptrunner.ts | 4 +- packages/core/src/runpromptcontext.ts | 24 ++-- packages/core/src/schema.ts | 24 ++-- packages/core/src/server/messages.ts | 1 + packages/core/src/systems.ts | 23 +++- packages/core/src/tools.ts | 46 ++++++++ packages/core/src/types/prompt_template.d.ts | 12 +- packages/sample/genaisrc/tool-calls.genai.mjs | 41 +++++++ 24 files changed, 581 insertions(+), 99 deletions(-) create mode 100644 packages/core/src/genaisrc/system.tool_calls.genai.mjs create mode 100644 packages/core/src/parameters.test.ts create mode 100644 packages/core/src/tools.ts create mode 100644 packages/sample/genaisrc/tool-calls.genai.mjs diff --git a/.vscode/settings.json b/.vscode/settings.json index 8fd26d7632..bde0af6918 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -39,6 +39,7 @@ "hostpath", "huggingface", "icontains", + "Jamba", "labelledby", "limitrows", "LITELLM", @@ -57,6 +58,7 @@ "nomic", "ollama", "openai", + "OPENROUTER", "optillm", "pelikhan", "promptdom", @@ -66,6 +68,7 @@ "quoteify", "qwen", "RIPGREP", + "smsg", "socketserver", "spinbutton", "stringifying", diff --git a/README.md b/README.md index 4fc2f43101..3433c5fca2 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,8 @@ const { files } = await workspace.grep(/[a-z][a-z0-9]+/, { globs: "*.md" }) ### LLM Tools -Register JavaScript functions as **tools**. +Register JavaScript functions as [tools](https://microsoft.github.io/genaiscript/reference/scripts/tools) +(with fallback for models that don't support tools). ```js defTool( @@ -310,7 +311,7 @@ npx genaiscript ... --pull-request-reviews Build reliable prompts using [tests and evals](https://microsoft.github.io/genaiscript/reference/scripts/tests) powered by [promptfoo](https://promptfoo.dev/). -```js wrap +```js wrap script({ ..., tests: { files: "penguins.csv", rubric: "is a data analysis report", diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx index 5a0467011f..67ad5b664e 100644 --- a/docs/src/content/docs/index.mdx +++ b/docs/src/content/docs/index.mdx @@ -127,6 +127,7 @@ or with a [command line](/genaiscript/getting-started/installation). Register JavaScript functions as [LLM tools](/genaiscript/reference/scripts/tools/) +(with fallback for models that don't support tools). ```js wrap defTool("weather", "live weather", diff --git a/docs/src/content/docs/reference/cli/commands.md b/docs/src/content/docs/reference/cli/commands.md index 0983efe6fe..6658cec618 100644 --- a/docs/src/content/docs/reference/cli/commands.md +++ b/docs/src/content/docs/reference/cli/commands.md @@ -16,8 +16,11 @@ Usage: genaiscript run [options]