Merge pull request #4700 from continuedev/dallin/tool-prompt
Remove tool use system instructions
This commit is contained in:
commit
4a82e5a302
8 changed files with 19 additions and 53 deletions
|
|
@ -1,51 +1,23 @@
|
|||
import {
|
||||
ChatHistoryItem,
|
||||
ChatMessage,
|
||||
MessagePart,
|
||||
ModelDescription,
|
||||
} from "../";
|
||||
import { ChatHistoryItem, ChatMessage, MessagePart } from "../";
|
||||
import { normalizeToMessageParts } from "../util/messageContent";
|
||||
|
||||
import { modelSupportsTools } from "./autodetect";
|
||||
|
||||
const TOOL_USE_RULES = `<tool_use_rules>
|
||||
When using tools, follow the following guidelines:
|
||||
- Avoid calling tools unless they are absolutely necessary. For example, if you are asked a simple programming question you do not need web search. As another example, if the user asks you to explain something about code, do not create a new file.
|
||||
</tool_use_rules>`;
|
||||
|
||||
function constructSystemPrompt(
|
||||
modelDescription: ModelDescription,
|
||||
useTools: boolean,
|
||||
): string | null {
|
||||
let systemMessage = `<important_rules>
|
||||
const DEFAULT_SYSTEM_MESSAGE = `<important_rules>
|
||||
Always include the language and file name in the info string when you write code blocks. If you are editing "src/main.py" for example, your code block should start with '\`\`\`python src/main.py'.
|
||||
</important_rules>`;
|
||||
if (useTools && modelSupportsTools(modelDescription)) {
|
||||
systemMessage += "\n\n" + TOOL_USE_RULES;
|
||||
}
|
||||
return systemMessage;
|
||||
}
|
||||
|
||||
const CANCELED_TOOL_CALL_MESSAGE =
|
||||
"This tool call was cancelled by the user. You should clarify next steps, as they don't wish for you to use this tool.";
|
||||
|
||||
export function constructMessages(
|
||||
history: ChatHistoryItem[],
|
||||
modelDescription: ModelDescription,
|
||||
useTools: boolean,
|
||||
): ChatMessage[] {
|
||||
export function constructMessages(history: ChatHistoryItem[]): ChatMessage[] {
|
||||
const filteredHistory = history.filter(
|
||||
(item) => item.message.role !== "system",
|
||||
);
|
||||
const msgs: ChatMessage[] = [];
|
||||
|
||||
const systemMessage = constructSystemPrompt(modelDescription, useTools);
|
||||
if (systemMessage) {
|
||||
msgs.push({
|
||||
role: "system",
|
||||
content: systemMessage,
|
||||
});
|
||||
}
|
||||
msgs.push({
|
||||
role: "system",
|
||||
content: DEFAULT_SYSTEM_MESSAGE,
|
||||
});
|
||||
|
||||
for (let i = 0; i < filteredHistory.length; i++) {
|
||||
const historyItem = filteredHistory[i];
|
||||
|
|
|
|||
|
|
@ -8,14 +8,16 @@ export const createNewFileTool: Tool = {
|
|||
readonly: false,
|
||||
function: {
|
||||
name: BuiltInToolNames.CreateNewFile,
|
||||
description: "Create a new file",
|
||||
description:
|
||||
"Create a new file. Only use this when a file doesn't exist and should be created",
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["filepath", "contents"],
|
||||
properties: {
|
||||
filepath: {
|
||||
type: "string",
|
||||
description: "The path where the new file should be created",
|
||||
description:
|
||||
"The path where the new file should be created, relative to the root of the workspace",
|
||||
},
|
||||
contents: {
|
||||
type: "string",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export const readCurrentlyOpenFileTool: Tool = {
|
|||
function: {
|
||||
name: BuiltInToolNames.ReadCurrentlyOpenFile,
|
||||
description:
|
||||
"Read the currently open file in the IDE. If the user seems to be referring to a file that you can't see, this is probably it.",
|
||||
"Read the currently open file in the IDE. If the user seems to be referring to a file that you can't see, try using this",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {},
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export const readFileTool: Tool = {
|
|||
function: {
|
||||
name: BuiltInToolNames.ReadFile,
|
||||
description:
|
||||
"Use this tool whenever you need to view the contents of a file.",
|
||||
"Use this tool if you need to view the contents of an existing file.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["filepath"],
|
||||
|
|
@ -17,7 +17,7 @@ export const readFileTool: Tool = {
|
|||
filepath: {
|
||||
type: "string",
|
||||
description:
|
||||
"The path of the file to read, relative to the root of the workspace.",
|
||||
"The path of the file to read, relative to the root of the workspace (NOT uri or absolute path)",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export const runTerminalCommandTool: Tool = {
|
|||
function: {
|
||||
name: BuiltInToolNames.RunTerminalCommand,
|
||||
description:
|
||||
"Run a terminal command in the current directory. The shell is not stateful and will not remember any previous commands.",
|
||||
"Run a terminal command in the current directory. The shell is not stateful and will not remember any previous commands. Do NOT perform actions requiring special/admin priveleges.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["command"],
|
||||
|
|
@ -17,7 +17,7 @@ export const runTerminalCommandTool: Tool = {
|
|||
command: {
|
||||
type: "string",
|
||||
description:
|
||||
"The command to run. This will be passed directly into the shell.",
|
||||
"The command to run. This will be passed directly into the IDE shell.",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export const searchWebTool: Tool = {
|
|||
function: {
|
||||
name: BuiltInToolNames.SearchWeb,
|
||||
description:
|
||||
"Performs a web search, returning top results. This tool should only be called for questions that require external knowledge. Common programming questions do not require web search.",
|
||||
"Performs a web search, returning top results. Use this tool sparingly - only for questions that require specialized, external, and/or up-to-date knowledege. Common programming questions do not require web search.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["query"],
|
||||
|
|
|
|||
|
|
@ -119,11 +119,7 @@ export const streamResponseThunk = createAsyncThunk<
|
|||
|
||||
// Construct messages from updated history
|
||||
const updatedHistory = getState().session.history;
|
||||
const messages = constructMessages(
|
||||
[...updatedHistory],
|
||||
defaultModel,
|
||||
useTools,
|
||||
);
|
||||
const messages = constructMessages([...updatedHistory]);
|
||||
|
||||
posthog.capture("step run", {
|
||||
step_name: "User Input",
|
||||
|
|
|
|||
|
|
@ -60,11 +60,7 @@ export const streamResponseAfterToolCall = createAsyncThunk<
|
|||
dispatch(setActive());
|
||||
|
||||
const updatedHistory = getState().session.history;
|
||||
const messages = constructMessages(
|
||||
[...updatedHistory],
|
||||
defaultModel,
|
||||
useTools,
|
||||
);
|
||||
const messages = constructMessages([...updatedHistory]);
|
||||
unwrapResult(await dispatch(streamNormalInput({ messages })));
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue