system message for tools
This commit is contained in:
parent
9fbd4cc045
commit
ee47711bdd
3 changed files with 29 additions and 18 deletions
|
|
@ -84,6 +84,13 @@ const MODEL_SUPPORTS_IMAGES: string[] = [
|
|||
"llama3.2",
|
||||
];
|
||||
|
||||
function modelSupportsTools(modelName: string) {
|
||||
return (
|
||||
modelName.includes("claude") &&
|
||||
(modelName.includes("3-5") || modelName.includes("3.5"))
|
||||
);
|
||||
}
|
||||
|
||||
function modelSupportsImages(
|
||||
provider: ModelProvider,
|
||||
model: string,
|
||||
|
|
@ -150,10 +157,10 @@ function autodetectTemplateType(model: string): TemplateType | undefined {
|
|||
lower.includes("chat-bison") ||
|
||||
lower.includes("pplx") ||
|
||||
lower.includes("gemini") ||
|
||||
lower.includes("grok")||
|
||||
lower.includes("grok") ||
|
||||
lower.includes("moonshot")
|
||||
) {
|
||||
return undefined;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (lower.includes("llama3")) {
|
||||
|
|
@ -354,4 +361,5 @@ export {
|
|||
autodetectTemplateType,
|
||||
llmCanGenerateInParallel,
|
||||
modelSupportsImages,
|
||||
modelSupportsTools,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { ChatHistory, ChatMessage, MessagePart } from "../index.js";
|
||||
import { normalizeToMessageParts } from "../util/messageContent.js";
|
||||
import { modelSupportsTools } from "./autodetect.js";
|
||||
|
||||
const SYSTEM_MESSAGE = `When generating new code:
|
||||
|
||||
|
|
@ -57,25 +58,33 @@ function helloWorld() {
|
|||
}
|
||||
\`\`\`
|
||||
|
||||
Always follow these guidelines when generating code responses.
|
||||
Always follow these guidelines when generating code responses.`;
|
||||
|
||||
Other rules:
|
||||
const 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.`;
|
||||
|
||||
function constructSystemPrompt(model: string): string | null {
|
||||
if (model.includes("sonnet")) {
|
||||
return SYSTEM_MESSAGE + "\n\n" + TOOL_USE_RULES;
|
||||
}
|
||||
if (modelSupportsTools(model)) {
|
||||
return TOOL_USE_RULES;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function constructMessages(
|
||||
history: ChatHistory,
|
||||
model: string,
|
||||
): ChatMessage[] {
|
||||
const msgs: ChatMessage[] = [];
|
||||
|
||||
// Only using this system message with Sonnet right now
|
||||
if (
|
||||
// hasCodeBlockWithFilename(history[0].message.content) &&
|
||||
model.includes("sonnet")
|
||||
) {
|
||||
const systemMessage = constructSystemPrompt(model);
|
||||
if (systemMessage) {
|
||||
msgs.push({
|
||||
role: "system" as const,
|
||||
content: SYSTEM_MESSAGE,
|
||||
content: systemMessage,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import {
|
|||
ChevronDownIcon,
|
||||
WrenchScrewdriverIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { modelSupportsTools } from "core/llm/autodetect";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import { defaultBorderRadius, lightGray, vscForeground } from "../..";
|
||||
|
|
@ -36,14 +37,7 @@ function ToggleToolsButton(props: ToggleToolsButtonProps) {
|
|||
const useTools = useSelector((store: RootState) => store.uiState.useTools);
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
|
||||
function toolUseAllowed() {
|
||||
return (
|
||||
defaultModel.model.includes("claude") &&
|
||||
(defaultModel.model.includes("3-5") || defaultModel.model.includes("3.5"))
|
||||
);
|
||||
}
|
||||
|
||||
if (!toolUseAllowed()) {
|
||||
if (!modelSupportsTools(defaultModel.model)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue