Skip to content

Commit d21ddc6

Browse files
committed
fix: tool use changing based on if models support tools and agent & fixes for types and stubs in caps
1 parent b1efd71 commit d21ddc6

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

refact-agent/gui/src/__fixtures__/caps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,15 @@ export const STUB_CAPS_RESPONSE: CapsResponse = {
339339
"groq-llama-3.1-8b",
340340
"groq-llama-3.1-70b",
341341
],
342+
code_chat_default_system_prompt: "default",
342343
caps_version: 0,
343344
};
344345

345346
export const EMPTY_CAPS_RESPONSE: CapsResponse = {
346347
caps_version: 0,
347348
cloud_name: "",
348349
code_chat_default_model: "",
350+
code_chat_default_system_prompt: "",
349351
code_chat_models: {},
350352
code_completion_default_model: "",
351353
code_completion_models: {},

refact-agent/gui/src/components/ChatForm/PromptSelect.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ export const PromptSelect: React.FC = () => {
3232
);
3333

3434
const caps = useGetCapsQuery();
35+
3536
const default_system_prompt =
3637
caps.data?.code_chat_default_system_prompt ?? "default";
38+
3739
const val = useMemo(
3840
() => Object.keys(selectedSystemPrompt)[0] ?? default_system_prompt,
39-
[selectedSystemPrompt],
41+
[selectedSystemPrompt, default_system_prompt],
4042
);
4143

4244
const options = useMemo(() => {
@@ -48,6 +50,12 @@ export const PromptSelect: React.FC = () => {
4850
});
4951
}, [promptsRequest.data]);
5052

53+
const isLoading = useMemo(
54+
() =>
55+
promptsRequest.isLoading || promptsRequest.isFetching || caps.isLoading,
56+
[promptsRequest.isLoading, promptsRequest.isFetching, caps.isLoading],
57+
);
58+
5159
return (
5260
<Flex
5361
gap="2"
@@ -60,7 +68,7 @@ export const PromptSelect: React.FC = () => {
6068
<Text size="2" wrap="nowrap">
6169
System Prompt:
6270
</Text>
63-
<Skeleton loading={promptsRequest.isLoading || promptsRequest.isFetching}>
71+
<Skeleton loading={isLoading}>
6472
<Box flexGrow="1" flexShrink="0">
6573
<Select
6674
name="system prompt"

refact-agent/gui/src/hooks/useCapsForToolUse.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
useAppDispatch,
99
} from ".";
1010

11-
import { getSelectedChatModel, setChatModel } from "../features/Chat";
11+
import {
12+
getSelectedChatModel,
13+
setChatModel,
14+
setToolUse,
15+
} from "../features/Chat";
1216

1317
// TODO: hard coded for now.
1418
const PAID_AGENT_LIST = [
@@ -48,6 +52,20 @@ export function useCapsForToolUse() {
4852
return true;
4953
}, [caps.data?.code_chat_models, currentModel]);
5054

55+
const modelsSupportingTools = useMemo(() => {
56+
const models = caps.data?.code_chat_models ?? {};
57+
return Object.entries(models)
58+
.filter(([_, value]) => value.supports_tools)
59+
.map(([key]) => key);
60+
}, [caps.data?.code_chat_models]);
61+
62+
const modelsSupportingAgent = useMemo(() => {
63+
const models = caps.data?.code_chat_models ?? {};
64+
return Object.entries(models)
65+
.filter(([_, value]) => value.supports_agent)
66+
.map(([key]) => key);
67+
}, [caps.data?.code_chat_models]);
68+
5169
const usableModels = useMemo(() => {
5270
const models = caps.data?.code_chat_models ?? {};
5371
const items = Object.entries(models).reduce<string[]>(
@@ -97,6 +115,22 @@ export function useCapsForToolUse() {
97115
}
98116
}, [currentModel, setCapModel, usableModels, usableModelsForPlan]);
99117

118+
useEffect(() => {
119+
if (caps.isSuccess) {
120+
if (toolUse === "agent" && modelsSupportingAgent.length === 0) {
121+
dispatch(setToolUse("explore"));
122+
} else if (toolUse === "explore" && modelsSupportingTools.length === 0) {
123+
dispatch(setToolUse("quick"));
124+
}
125+
}
126+
}, [
127+
dispatch,
128+
caps.isSuccess,
129+
toolUse,
130+
modelsSupportingAgent,
131+
modelsSupportingTools,
132+
]);
133+
100134
return {
101135
usableModels,
102136
usableModelsForPlan,

refact-agent/gui/src/services/refact/caps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export type CapsResponse = {
7979
caps_version: number;
8080
cloud_name: string;
8181
code_chat_default_model: string;
82+
code_chat_default_system_prompt: string;
8283
code_chat_models: Record<string, CodeChatModel>;
8384
code_completion_default_model: string;
8485
code_completion_models: Record<string, CodeCompletionModel>;

0 commit comments

Comments
 (0)