From 2121a770ffb64db08a6c2228efe19efd060426c6 Mon Sep 17 00:00:00 2001 From: Marc McIntosh Date: Wed, 11 Dec 2024 13:42:27 +0100 Subject: [PATCH 1/4] fix: set tool use to agentic by default. --- src/features/Chat/Thread/reducer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/Chat/Thread/reducer.ts b/src/features/Chat/Thread/reducer.ts index eae45f1d..3bdafa37 100644 --- a/src/features/Chat/Thread/reducer.ts +++ b/src/features/Chat/Thread/reducer.ts @@ -48,7 +48,7 @@ const createChatThread = ( }; const createInitialState = ( - tool_use: ToolUse = "explore", + tool_use: ToolUse = "agent", integration?: IntegrationMeta | null, maybeMode?: LspChatMode, ): Chat => { From 5c4f10cff99927df77065a55264df12b60b7a7e3 Mon Sep 17 00:00:00 2001 From: Marc McIntosh Date: Wed, 11 Dec 2024 13:44:36 +0100 Subject: [PATCH 2/4] fix(links): only request links if tool use is agentic. --- src/hooks/useLinksFromLsp.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/hooks/useLinksFromLsp.ts b/src/hooks/useLinksFromLsp.ts index 9cd9b69f..6100809c 100644 --- a/src/hooks/useLinksFromLsp.ts +++ b/src/hooks/useLinksFromLsp.ts @@ -17,6 +17,7 @@ import { selectMessages, selectModel, selectThreadMode, + selectThreadToolUse, setIntegrationData, } from "../features/Chat"; import { useGoToLink } from "./useGoToLink"; @@ -35,6 +36,7 @@ export function useLinksFromLsp() { const chatId = useAppSelector(selectChatId); const maybeIntegration = useAppSelector(selectIntegration); const threadMode = useAppSelector(selectThreadMode); + const toolUse = useAppSelector(selectThreadToolUse); // TODO: add the model const caps = useGetCapsQuery(); @@ -106,10 +108,19 @@ export function useLinksFromLsp() { messages.length > 0 && isUserMessage(messages[messages.length - 1]); if (!model) return true; if (!caps.data) return true; + if (toolUse !== "agent") return true; return ( isStreaming || isWaiting || unCalledTools || lastMessageIsUserMessage ); - }, [caps.data, isStreaming, isWaiting, messages, model, unCalledTools]); + }, [ + caps.data, + isStreaming, + isWaiting, + messages, + model, + toolUse, + unCalledTools, + ]); const linksResult = linksApi.useGetLinksForChatQuery( { From 122e8868f7aa17a841f965fac84c437954ef3fe8 Mon Sep 17 00:00:00 2001 From: Marc McIntosh Date: Wed, 11 Dec 2024 15:06:17 +0100 Subject: [PATCH 3/4] fix(mode models): limit model selection when using agent. --- src/components/Chat/Chat.tsx | 52 ++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/components/Chat/Chat.tsx b/src/components/Chat/Chat.tsx index 9295d07d..1c80563a 100644 --- a/src/components/Chat/Chat.tsx +++ b/src/components/Chat/Chat.tsx @@ -22,11 +22,12 @@ import { getSelectedToolUse, getSelectedSystemPrompt, setSystemPrompt, + ToolUse, } from "../../features/Chat/Thread"; import { ThreadHistoryButton } from "../Buttons"; import { push } from "../../features/Pages/pagesSlice"; import { DropzoneProvider } from "../Dropzone"; -import { SystemPrompts } from "../../services/refact"; +import { CodeChatModel, SystemPrompts } from "../../services/refact"; export type ChatProps = { host: Config["host"]; @@ -105,6 +106,14 @@ export const Chat: React.FC = ({ useAutoSend(); + // TODO: ideally this could be set when the chat is created. + useEffect(() => { + if (chatToolUse === "agent" && !modelSupportsAgent(chatModel)) { + const modelToUse = modelForMode(chatModel, caps, chatToolUse); + onSetChatModel(modelToUse); + } + }, [caps, chatModel, chatToolUse, onSetChatModel]); + return ( = ({ onSubmit={handleSummit} model={chatModel} onSetChatModel={onSetChatModel} - caps={caps} + caps={{ + ...caps, + available_caps: capOptionsForMode(caps.available_caps, chatToolUse), + }} onClose={maybeSendToSidebar} prompts={promptsRequest.data ?? {}} onSetSystemPrompt={onSetSelectedSystemPrompt} @@ -177,3 +189,39 @@ export const Chat: React.FC = ({ ); }; + +const AGENT_ALLOW_LIST = ["gpt-4o", "claude-3-5-sonnet"]; +function modelForMode( + model: string, + caps: ChatFormProps["caps"], + toolUse?: ToolUse, +) { + if (toolUse !== "agent") return model; + + if (AGENT_ALLOW_LIST.includes(model)) return model; + + const available = Object.keys(caps.available_caps); + + const hasModels = AGENT_ALLOW_LIST.find((agent) => available.includes(agent)); + if (hasModels) return hasModels; + + return model || caps.default_cap; +} + +function modelSupportsAgent(model: string) { + return AGENT_ALLOW_LIST.includes(model); +} + +function capOptionsForMode( + caps: Record, + toolUse?: string, +) { + if (toolUse !== "agent") return caps; + const agentEntries = Object.entries(caps).filter(([key]) => + AGENT_ALLOW_LIST.includes(key), + ); + + if (agentEntries.length === 0) return caps; + + return Object.fromEntries(agentEntries); +} From b69371b6cdd15f2b7350a317a9aec167d1dd5ebb Mon Sep 17 00:00:00 2001 From: Marc McIntosh Date: Wed, 11 Dec 2024 15:18:29 +0100 Subject: [PATCH 4/4] test(chat default); switch from mini to gpt-4o --- src/features/Chat/Chat.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/Chat/Chat.test.tsx b/src/features/Chat/Chat.test.tsx index 1d129314..da000af8 100644 --- a/src/features/Chat/Chat.test.tsx +++ b/src/features/Chat/Chat.test.tsx @@ -228,7 +228,7 @@ describe("Chat", () => { // app.debug(select.parentElement?.parentElement, 10000); // expect(app.container.textContent).toContain("gpt-3.5-turbo"); - expect(screen.findByText("gpt-4o-mini")).not.toBeNull(); + expect(screen.findByText("gpt-4o")).not.toBeNull(); }); const textarea = screen.getByTestId("chat-form-textarea");