Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agentic defaults #233

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -105,6 +106,14 @@ export const Chat: React.FC<ChatProps> = ({

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 (
<DropzoneProvider asChild>
<Flex
Expand Down Expand Up @@ -140,7 +149,10 @@ export const Chat: React.FC<ChatProps> = ({
onSubmit={handleSummit}
model={chatModel}
onSetChatModel={onSetChatModel}
caps={caps}
caps={{
...caps,
available_caps: capOptionsForMode(caps.available_caps, chatToolUse),
}}
onClose={maybeSendToSidebar}
prompts={promptsRequest.data ?? {}}
onSetSystemPrompt={onSetSelectedSystemPrompt}
Expand Down Expand Up @@ -177,3 +189,39 @@ export const Chat: React.FC<ChatProps> = ({
</DropzoneProvider>
);
};

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<string, CodeChatModel>,
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);
}
2 changes: 1 addition & 1 deletion src/features/Chat/Chat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/features/Chat/Thread/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const createChatThread = (
};

const createInitialState = (
tool_use: ToolUse = "explore",
tool_use: ToolUse = "agent",
integration?: IntegrationMeta | null,
maybeMode?: LspChatMode,
): Chat => {
Expand Down
13 changes: 12 additions & 1 deletion src/hooks/useLinksFromLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
selectMessages,
selectModel,
selectThreadMode,
selectThreadToolUse,
setIntegrationData,
} from "../features/Chat";
import { useGoToLink } from "./useGoToLink";
Expand All @@ -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();
Expand Down Expand Up @@ -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(
{
Expand Down
Loading