Skip to content

Commit

Permalink
fix duplicate git_diff tool
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 22, 2024
1 parent 52ab19d commit 19622b7
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 115 deletions.
2 changes: 1 addition & 1 deletion docs/src/components/BuiltinAgents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ import { LinkCard } from '@astrojs/starlight/components';
<LinkCard title="agent interpreter" description="run code interpreters for Python, Math. Use this agent to ground computation questions." href="/genaiscript/reference/scripts/system#systemagent_interpreter" />
<LinkCard title="agent planner" description="generates a plan to solve a task" href="/genaiscript/reference/scripts/system#systemagent_planner" />
<LinkCard title="agent user_input" description="ask user for input to confirm, select or answer the question in the query. The message should be very clear and provide all the context." href="/genaiscript/reference/scripts/system#systemagent_user_input" />
<LinkCard title="agent web-search" description="search the web to accomplish tasks." href="/genaiscript/reference/scripts/system#systemagent_web" />
<LinkCard title="agent web" description="search the web to accomplish tasks." href="/genaiscript/reference/scripts/system#systemagent_web" />
1 change: 0 additions & 1 deletion docs/src/components/BuiltinTools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { LinkCard } from '@astrojs/starlight/components';
<LinkCard title="git_branch_default" description="Gets the default branch using git." href="/genaiscript/reference/scripts/system#systemgit" />
<LinkCard title="git_branch_current" description="Gets the current branch using git." href="/genaiscript/reference/scripts/system#systemgit" />
<LinkCard title="git_branch_list" description="List all branches using git." href="/genaiscript/reference/scripts/system#systemgit" />
<LinkCard title="git_diff" description="Computes file diffs using the git diff command. If the diff is too large, it returns the list of modified/added files." href="/genaiscript/reference/scripts/system#systemgit" />
<LinkCard title="git_list_commits" description="Generates a history of commits using the git log command." href="/genaiscript/reference/scripts/system#systemgit" />
<LinkCard title="git_status" description="Generates a status of the repository using git." href="/genaiscript/reference/scripts/system#systemgit" />
<LinkCard title="git_last_tag" description="Gets the last tag using git." href="/genaiscript/reference/scripts/system#systemgit" />
Expand Down
55 changes: 1 addition & 54 deletions docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
serializeLogProb,
topLogprobsToMarkdown,
} from "./logprob"
import { uniq } from "es-toolkit"

export function toChatCompletionUserMessage(
expanded: string,
Expand Down Expand Up @@ -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<string, string>
while (true) {
stats.turns++
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/genaisrc/system.agent_web.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down
52 changes: 0 additions & 52 deletions packages/core/src/genaisrc/system.git.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/llms.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 19622b7

Please sign in to comment.