From 19622b74bc75e2d1b51c216c9141f6ad4ada5e24 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Sun, 22 Dec 2024 04:29:52 +0000 Subject: [PATCH] fix duplicate git_diff tool --- docs/src/components/BuiltinAgents.mdx | 2 +- docs/src/components/BuiltinTools.mdx | 1 - .../content/docs/reference/scripts/system.mdx | 55 +------------------ package.json | 1 + packages/core/src/anthropic.ts | 2 +- packages/core/src/chat.ts | 10 +++- .../src/genaisrc/system.agent_web.genai.mjs | 2 +- .../core/src/genaisrc/system.git.genai.mjs | 52 ------------------ packages/core/src/llms.json | 6 +- packages/core/src/openai.ts | 2 +- 10 files changed, 18 insertions(+), 115 deletions(-) diff --git a/docs/src/components/BuiltinAgents.mdx b/docs/src/components/BuiltinAgents.mdx index 590d5a5124..7303c90ab0 100644 --- a/docs/src/components/BuiltinAgents.mdx +++ b/docs/src/components/BuiltinAgents.mdx @@ -13,4 +13,4 @@ import { LinkCard } from '@astrojs/starlight/components'; - + diff --git a/docs/src/components/BuiltinTools.mdx b/docs/src/components/BuiltinTools.mdx index 7edf0b1683..155e4c2602 100644 --- a/docs/src/components/BuiltinTools.mdx +++ b/docs/src/components/BuiltinTools.mdx @@ -13,7 +13,6 @@ import { LinkCard } from '@astrojs/starlight/components'; - diff --git a/docs/src/content/docs/reference/scripts/system.mdx b/docs/src/content/docs/reference/scripts/system.mdx index e63143ef25..d85eac8b9e 100644 --- a/docs/src/content/docs/reference/scripts/system.mdx +++ b/docs/src/content/docs/reference/scripts/system.mdx @@ -390,7 +390,7 @@ system({ const model = env.vars.agentWebSearchModel defAgent( - "web-search", + "web", "search the web to accomplish tasks.", `Your are a helpful LLM agent that can use web search. Answer the question in QUERY.`, @@ -1080,7 +1080,6 @@ Tools to query a git repository. - tool `git_branch_default`: Gets the default branch using git. - tool `git_branch_current`: Gets the current branch using git. - tool `git_branch_list`: List all branches using git. -- tool `git_diff`: Computes file diffs using the git diff command. If the diff is too large, it returns the list of modified/added files. - tool `git_list_commits`: Generates a history of commits using the git log command. - tool `git_status`: Generates a status of the repository using git. - tool `git_last_tag`: Gets the last tag using git. @@ -1113,58 +1112,6 @@ defTool("git_branch_list", "List all branches using git.", {}, async () => { return await git.exec("branch") }) -defTool( - "git_diff", - "Computes file diffs using the git diff command. If the diff is too large, it returns the list of modified/added files.", - { - type: "object", - properties: { - base: { - type: "string", - description: "Base branch, ref, commit sha to compare against.", - }, - head: { - type: "string", - description: - "Head branch, ref, commit sha to compare. Use 'HEAD' to compare against the current branch.", - }, - staged: { - type: "boolean", - description: "Compare staged changes", - }, - nameOnly: { - type: "boolean", - description: "Show only file names", - }, - paths: { - type: "array", - description: "Paths to compare", - items: { - type: "string", - description: "File path or wildcard supported by git", - }, - }, - excludedPaths: { - type: "array", - description: "Paths to exclude", - items: { - type: "string", - description: "File path or wildcard supported by git", - }, - }, - }, - }, - async (args) => { - const { context, ...rest } = args - const res = await git.diff({ - llmify: true, - ...rest, - }) - return res - }, - { maxTokens: 20000 } -) - defTool( "git_list_commits", "Generates a history of commits using the git log command.", diff --git a/package.json b/package.json index f896fc556a..797fd1681d 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "setup": "git submodule update --init --recursive", "setup:az": "curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash", "setup:bicep": "az bicep upgrade", + "az:login": "az login --scope api://trapi/.default", "install:playwright": "yarn install playwright --with-deps", "install:force": "rm yarn.lock && yarn install && yarn --cwd docs install:force && yarn --cwd slides install:force && yarn gen:licenses", "compile-ext": "yarn --cwd packages/core run prompts:bundle && yarn --cwd packages/vscode run compile", diff --git a/packages/core/src/anthropic.ts b/packages/core/src/anthropic.ts index 37d40769dc..84cc6dfce0 100644 --- a/packages/core/src/anthropic.ts +++ b/packages/core/src/anthropic.ts @@ -433,7 +433,7 @@ const completerFactory = ( trace.appendContent("\n\n") trace.itemValue(`🏁 finish reason`, finishReason) - if (usage) { + if (usage?.total_tokens) { trace.itemValue( `🪙 tokens`, `${usage.total_tokens} total, ${usage.prompt_tokens} prompt, ${usage.completion_tokens} completion` diff --git a/packages/core/src/chat.ts b/packages/core/src/chat.ts index 9a5fec9665..11a095797d 100644 --- a/packages/core/src/chat.ts +++ b/packages/core/src/chat.ts @@ -79,6 +79,7 @@ import { serializeLogProb, topLogprobsToMarkdown, } from "./logprob" +import { uniq } from "es-toolkit" export function toChatCompletionUserMessage( expanded: string, @@ -892,8 +893,15 @@ export async function executeChatSession( try { trace.startDetails(`🧠 llm chat`) - if (toolDefinitions?.length) + if (toolDefinitions?.length) { trace.detailsFenced(`🛠️ tools`, tools, "yaml") + const toolNames = toolDefinitions.map(({ spec }) => spec.name) + const duplicates = uniq(toolNames).filter( + (name, index) => toolNames.lastIndexOf(name) !== index + ) + if (duplicates.length) + throw new Error(`duplicate tools: ${duplicates.join(", ")}`) + } let genVars: Record while (true) { stats.turns++ diff --git a/packages/core/src/genaisrc/system.agent_web.genai.mjs b/packages/core/src/genaisrc/system.agent_web.genai.mjs index cb87e88a54..9963189b35 100644 --- a/packages/core/src/genaisrc/system.agent_web.genai.mjs +++ b/packages/core/src/genaisrc/system.agent_web.genai.mjs @@ -5,7 +5,7 @@ system({ const model = env.vars.agentWebSearchModel defAgent( - "web-search", + "web", "search the web to accomplish tasks.", `Your are a helpful LLM agent that can use web search. Answer the question in QUERY.`, diff --git a/packages/core/src/genaisrc/system.git.genai.mjs b/packages/core/src/genaisrc/system.git.genai.mjs index b753cd36e4..1fb5fbeea0 100644 --- a/packages/core/src/genaisrc/system.git.genai.mjs +++ b/packages/core/src/genaisrc/system.git.genai.mjs @@ -25,58 +25,6 @@ defTool("git_branch_list", "List all branches using git.", {}, async () => { return await git.exec("branch") }) -defTool( - "git_diff", - "Computes file diffs using the git diff command. If the diff is too large, it returns the list of modified/added files.", - { - type: "object", - properties: { - base: { - type: "string", - description: "Base branch, ref, commit sha to compare against.", - }, - head: { - type: "string", - description: - "Head branch, ref, commit sha to compare. Use 'HEAD' to compare against the current branch.", - }, - staged: { - type: "boolean", - description: "Compare staged changes", - }, - nameOnly: { - type: "boolean", - description: "Show only file names", - }, - paths: { - type: "array", - description: "Paths to compare", - items: { - type: "string", - description: "File path or wildcard supported by git", - }, - }, - excludedPaths: { - type: "array", - description: "Paths to exclude", - items: { - type: "string", - description: "File path or wildcard supported by git", - }, - }, - }, - }, - async (args) => { - const { context, ...rest } = args - const res = await git.diff({ - llmify: true, - ...rest, - }) - return res - }, - { maxTokens: 20000 } -) - defTool( "git_list_commits", "Generates a history of commits using the git log command.", diff --git a/packages/core/src/llms.json b/packages/core/src/llms.json index 537459a406..46b17b071d 100644 --- a/packages/core/src/llms.json +++ b/packages/core/src/llms.json @@ -71,10 +71,10 @@ "prediction": false, "bearerToken": true, "aliases": { - "large": "gemini-2.0-flash-exp", + "large": "gemini-1.5-flash-latest", "small": "gemini-1.5-flash-latest", - "vision": "gemini-2.0-flash-exp", - "long": "gemini-2.0-flash-exp", + "vision": "gemini-1.5-flash-latest", + "long": "gemini-1.5-flash-latest", "reasoning": "gemini-2.0-flash-thinking-exp-1219", "reasoning_small": "gemini-2.0-flash-thinking-exp-1219", "embeddings": "text-embedding-004" diff --git a/packages/core/src/openai.ts b/packages/core/src/openai.ts index 16592161f3..73b324cdc6 100644 --- a/packages/core/src/openai.ts +++ b/packages/core/src/openai.ts @@ -399,7 +399,7 @@ export const OpenAIChatCompletion: ChatCompletionHandler = async ( trace.appendContent("\n\n") if (responseModel) trace.itemValue(`model`, responseModel) trace.itemValue(`🏁 finish reason`, finishReason) - if (usage) { + if (usage?.total_tokens) { trace.itemValue( `🪙 tokens`, `${usage.total_tokens} total, ${usage.prompt_tokens} prompt, ${usage.completion_tokens} completion`