From 73410df3c17b4b53d4b7e994d16d7eb5d3700df4 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 27 Jul 2025 21:07:16 -0700 Subject: [PATCH 1/2] feat: model capability warning --- src/ui/IntroMessage.tsx | 15 +++- src/ui/ModelCapabilityWarning.test.tsx | 42 ++++++++++ src/ui/ModelCapabilityWarning.tsx | 27 +++++++ src/utils/index.ts | 1 + src/utils/modelCapability.test.ts | 103 +++++++++++++++++++++++++ src/utils/modelCapability.ts | 16 ++++ 6 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 src/ui/ModelCapabilityWarning.test.tsx create mode 100644 src/ui/ModelCapabilityWarning.tsx create mode 100644 src/utils/index.ts create mode 100644 src/utils/modelCapability.test.ts create mode 100644 src/utils/modelCapability.ts diff --git a/src/ui/IntroMessage.tsx b/src/ui/IntroMessage.tsx index a97578e8e..2c4230f21 100644 --- a/src/ui/IntroMessage.tsx +++ b/src/ui/IntroMessage.tsx @@ -4,6 +4,8 @@ import React from "react"; import { parseArgs } from "../args.js"; import { getAllSlashCommands } from "../commands/commands.js"; import { MCPService } from "../mcp.js"; +import { isModelCapable } from "../utils/modelCapability.js"; +import ModelCapabilityWarning from "./ModelCapabilityWarning.js"; interface IntroMessageProps { config: AssistantUnrolled; @@ -32,6 +34,9 @@ const IntroMessage: React.FC = ({ const allRules = [...commandLineRules, ...configRules]; + // Check if model is capable + const modelCapable = isModelCapable(model.provider, model.name); + return ( {/* Agent name */} @@ -44,6 +49,14 @@ const IntroMessage: React.FC = ({ Model: {model.name.split("/").pop()} + {/* Model capability warning */} + {!modelCapable && ( + <> + + + + )} + {/* Slash commands */} @@ -94,4 +107,4 @@ const IntroMessage: React.FC = ({ ); }; -export default IntroMessage; +export default IntroMessage; \ No newline at end of file diff --git a/src/ui/ModelCapabilityWarning.test.tsx b/src/ui/ModelCapabilityWarning.test.tsx new file mode 100644 index 000000000..ec8d3afce --- /dev/null +++ b/src/ui/ModelCapabilityWarning.test.tsx @@ -0,0 +1,42 @@ +import { render } from 'ink-testing-library'; +import React from 'react'; +import { describe, expect, test } from '@jest/globals'; +import ModelCapabilityWarning from './ModelCapabilityWarning.js'; + +describe('ModelCapabilityWarning', () => { + test('should render warning message with model name', () => { + const { lastFrame } = render( + React.createElement(ModelCapabilityWarning, { modelName: 'gpt-3-davinci' }) + ); + + const frame = lastFrame(); + if (frame) { + expect(frame).toContain('Model Capability Warning'); + expect(frame).toContain('gpt-3-davinci'); + expect(frame).toContain('may have limited capabilities'); + expect(frame).toContain('Consider using a more capable model'); + } + }); + + test('should handle model names with slashes', () => { + const { lastFrame } = render( + React.createElement(ModelCapabilityWarning, { modelName: 'local/mistral-7b' }) + ); + + const frame = lastFrame(); + if (frame) { + expect(frame).toContain('local/mistral-7b'); + } + }); + + test('should display warning icon', () => { + const { lastFrame } = render( + React.createElement(ModelCapabilityWarning, { modelName: 'test-model' }) + ); + + const frame = lastFrame(); + if (frame) { + expect(frame).toContain('⚠️'); + } + }); +}); \ No newline at end of file diff --git a/src/ui/ModelCapabilityWarning.tsx b/src/ui/ModelCapabilityWarning.tsx new file mode 100644 index 000000000..87737abe7 --- /dev/null +++ b/src/ui/ModelCapabilityWarning.tsx @@ -0,0 +1,27 @@ +import { Box, Text } from "ink"; +import React from "react"; + +interface ModelCapabilityWarningProps { + modelName: string; +} + +const ModelCapabilityWarning: React.FC = ({ + modelName, +}) => { + return ( + + + ⚠️ + + Model Capability Warning + + + + The model "{modelName}" is not recommended for use with cn due to + limited reasoning and tool calling capabilities + + + ); +}; + +export default ModelCapabilityWarning; diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 000000000..25312b3d7 --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1 @@ +export { isModelCapable } from './modelCapability.js'; \ No newline at end of file diff --git a/src/utils/modelCapability.test.ts b/src/utils/modelCapability.test.ts new file mode 100644 index 000000000..fa64daefe --- /dev/null +++ b/src/utils/modelCapability.test.ts @@ -0,0 +1,103 @@ +import { isModelCapable } from './modelCapability.js'; + +describe('isModelCapable', () => { + describe('OpenAI models', () => { + test('should consider GPT-4 models as capable', () => { + expect(isModelCapable('openai', 'gpt-4')).toBe(true); + expect(isModelCapable('openai', 'gpt-4-turbo')).toBe(true); + expect(isModelCapable('openai', 'gpt-4-0613')).toBe(true); + }); + + test('should consider GPT-3.5-turbo as capable', () => { + expect(isModelCapable('openai', 'gpt-3.5-turbo')).toBe(true); + expect(isModelCapable('openai', 'gpt-3.5-turbo-16k')).toBe(true); + }); + + test('should consider older GPT-3 models as less capable', () => { + expect(isModelCapable('openai', 'gpt-3-davinci')).toBe(false); + expect(isModelCapable('openai', 'gpt-3-curie')).toBe(false); + }); + }); + + describe('Anthropic models', () => { + test('should consider Claude-3 models as capable', () => { + expect(isModelCapable('anthropic', 'claude-3-opus')).toBe(true); + expect(isModelCapable('anthropic', 'claude-3-sonnet')).toBe(true); + }); + + test('should consider Claude-2 as capable', () => { + expect(isModelCapable('anthropic', 'claude-2')).toBe(true); + expect(isModelCapable('anthropic', 'claude-2.1')).toBe(true); + }); + + test('should consider Claude-1 as less capable', () => { + expect(isModelCapable('anthropic', 'claude-1')).toBe(false); + }); + }); + + describe('Google models', () => { + test('should consider Gemini Pro models as capable', () => { + expect(isModelCapable('google', 'gemini-pro')).toBe(true); + expect(isModelCapable('gemini', 'gemini-ultra')).toBe(true); + }); + + test('should consider PaLM-2 models as capable', () => { + expect(isModelCapable('google', 'palm-2-chat')).toBe(true); + }); + }); + + describe('Local/Ollama models', () => { + test('should consider larger models as capable', () => { + expect(isModelCapable('ollama', 'llama2-70b')).toBe(true); + expect(isModelCapable('local', 'codellama-34b')).toBe(true); + }); + + test('should consider smaller models as less capable', () => { + expect(isModelCapable('ollama', 'llama2-7b')).toBe(false); + expect(isModelCapable('local', 'mistral-7b')).toBe(false); + }); + }); + + describe('Meta/Llama models', () => { + test('should consider large Llama models as capable', () => { + expect(isModelCapable('llama', 'llama-2-70b')).toBe(true); + expect(isModelCapable('meta', 'llama-65b')).toBe(true); + }); + + test('should consider small Llama models as less capable', () => { + expect(isModelCapable('llama', 'llama-2-7b')).toBe(false); + expect(isModelCapable('meta', 'llama-13b')).toBe(false); + }); + }); + + describe('Continue Proxy models', () => { + test('should consider continue-proxy models as capable', () => { + expect(isModelCapable('continue-proxy', 'any-model')).toBe(true); + }); + }); + + describe('Hugging Face models', () => { + test('should consider code-specific models as capable', () => { + expect(isModelCapable('huggingface', 'codellama-instruct')).toBe(true); + expect(isModelCapable('huggingface', 'starcoder-base')).toBe(true); + }); + + test('should consider general chat models as less capable', () => { + expect(isModelCapable('huggingface', 'falcon-7b')).toBe(false); + }); + }); + + describe('Unknown providers', () => { + test('should default to capable for unknown providers', () => { + expect(isModelCapable('unknown-provider', 'some-model')).toBe(true); + }); + }); + + describe('Case insensitivity', () => { + test('should handle different cases correctly', () => { + expect(isModelCapable('OPENAI', 'GPT-4')).toBe(true); + expect(isModelCapable('OpenAI', 'Gpt-4-Turbo')).toBe(true); + expect(isModelCapable('anthropic', 'CLAUDE-3-OPUS')).toBe(true); + }); + }); +}); \ No newline at end of file diff --git a/src/utils/modelCapability.ts b/src/utils/modelCapability.ts new file mode 100644 index 000000000..7ddc82cd9 --- /dev/null +++ b/src/utils/modelCapability.ts @@ -0,0 +1,16 @@ +/** + * Determines if a model is recommended for use with `cn` + */ +export function isModelCapable(provider: string, model: string): boolean { + const normalizedModel = model.toLowerCase(); + + if ( + [/gemini/, /claude/, /gpt/, /o\d/g, /kimi/, /qwen/].some((pattern) => + pattern.test(normalizedModel) + ) + ) { + return true; + } + + return false; +} From 81c48d0eee765c9a89a0b1d3acc5097b5c1542d6 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 27 Jul 2025 21:12:52 -0700 Subject: [PATCH 2/2] fix tests --- src/ui/ModelCapabilityWarning.test.tsx | 4 +- src/utils/modelCapability.test.ts | 58 +++++++++++++++++--------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/ui/ModelCapabilityWarning.test.tsx b/src/ui/ModelCapabilityWarning.test.tsx index ec8d3afce..910659a96 100644 --- a/src/ui/ModelCapabilityWarning.test.tsx +++ b/src/ui/ModelCapabilityWarning.test.tsx @@ -13,8 +13,8 @@ describe('ModelCapabilityWarning', () => { if (frame) { expect(frame).toContain('Model Capability Warning'); expect(frame).toContain('gpt-3-davinci'); - expect(frame).toContain('may have limited capabilities'); - expect(frame).toContain('Consider using a more capable model'); + expect(frame).toContain('is not recommended for use with cn due to limited reasoning and tool'); + expect(frame).toContain('calling capabilities'); } }); diff --git a/src/utils/modelCapability.test.ts b/src/utils/modelCapability.test.ts index fa64daefe..91c5e47fa 100644 --- a/src/utils/modelCapability.test.ts +++ b/src/utils/modelCapability.test.ts @@ -13,9 +13,15 @@ describe('isModelCapable', () => { expect(isModelCapable('openai', 'gpt-3.5-turbo-16k')).toBe(true); }); - test('should consider older GPT-3 models as less capable', () => { - expect(isModelCapable('openai', 'gpt-3-davinci')).toBe(false); - expect(isModelCapable('openai', 'gpt-3-curie')).toBe(false); + test('should consider O-series models as capable', () => { + expect(isModelCapable('openai', 'o1-preview')).toBe(true); + expect(isModelCapable('openai', 'o1-mini')).toBe(true); + expect(isModelCapable('openai', 'o3')).toBe(true); + }); + + test('should consider older GPT-3 models as capable', () => { + expect(isModelCapable('openai', 'gpt-3-davinci')).toBe(true); + expect(isModelCapable('openai', 'gpt-3-curie')).toBe(true); }); }); @@ -30,8 +36,8 @@ describe('isModelCapable', () => { expect(isModelCapable('anthropic', 'claude-2.1')).toBe(true); }); - test('should consider Claude-1 as less capable', () => { - expect(isModelCapable('anthropic', 'claude-1')).toBe(false); + test('should consider Claude-1 as capable', () => { + expect(isModelCapable('anthropic', 'claude-1')).toBe(true); }); }); @@ -41,15 +47,15 @@ describe('isModelCapable', () => { expect(isModelCapable('gemini', 'gemini-ultra')).toBe(true); }); - test('should consider PaLM-2 models as capable', () => { - expect(isModelCapable('google', 'palm-2-chat')).toBe(true); + test('should consider PaLM-2 models as not capable', () => { + expect(isModelCapable('google', 'palm-2-chat')).toBe(false); }); }); describe('Local/Ollama models', () => { - test('should consider larger models as capable', () => { - expect(isModelCapable('ollama', 'llama2-70b')).toBe(true); - expect(isModelCapable('local', 'codellama-34b')).toBe(true); + test('should consider larger models as not capable', () => { + expect(isModelCapable('ollama', 'llama2-70b')).toBe(false); + expect(isModelCapable('local', 'codellama-34b')).toBe(false); }); test('should consider smaller models as less capable', () => { @@ -59,9 +65,9 @@ describe('isModelCapable', () => { }); describe('Meta/Llama models', () => { - test('should consider large Llama models as capable', () => { - expect(isModelCapable('llama', 'llama-2-70b')).toBe(true); - expect(isModelCapable('meta', 'llama-65b')).toBe(true); + test('should consider large Llama models as not capable', () => { + expect(isModelCapable('llama', 'llama-2-70b')).toBe(false); + expect(isModelCapable('meta', 'llama-65b')).toBe(false); }); test('should consider small Llama models as less capable', () => { @@ -71,15 +77,15 @@ describe('isModelCapable', () => { }); describe('Continue Proxy models', () => { - test('should consider continue-proxy models as capable', () => { - expect(isModelCapable('continue-proxy', 'any-model')).toBe(true); + test('should consider continue-proxy models as not capable', () => { + expect(isModelCapable('continue-proxy', 'any-model')).toBe(false); }); }); describe('Hugging Face models', () => { - test('should consider code-specific models as capable', () => { - expect(isModelCapable('huggingface', 'codellama-instruct')).toBe(true); - expect(isModelCapable('huggingface', 'starcoder-base')).toBe(true); + test('should consider code-specific models as not capable', () => { + expect(isModelCapable('huggingface', 'codellama-instruct')).toBe(false); + expect(isModelCapable('huggingface', 'starcoder-base')).toBe(false); }); test('should consider general chat models as less capable', () => { @@ -88,8 +94,20 @@ describe('isModelCapable', () => { }); describe('Unknown providers', () => { - test('should default to capable for unknown providers', () => { - expect(isModelCapable('unknown-provider', 'some-model')).toBe(true); + test('should default to not capable for unknown providers', () => { + expect(isModelCapable('unknown-provider', 'some-model')).toBe(false); + }); + }); + + describe('Other capable models', () => { + test('should consider Qwen models as capable', () => { + expect(isModelCapable('alibaba', 'qwen-turbo')).toBe(true); + expect(isModelCapable('dashscope', 'qwen-max')).toBe(true); + }); + + test('should consider Kimi models as capable', () => { + expect(isModelCapable('moonshot', 'kimi-8k')).toBe(true); + expect(isModelCapable('moonshot', 'kimi-32k')).toBe(true); }); });