feat(core): use claude 4 as default chat model (#12596)

Support [AI-59](https://linear.app/affine-design/issue/AI-59)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Updated the default AI model for chat prompts to use Claude Sonnet 4.
- **Bug Fixes**
  - Improved model selection logic to better support reasoning features across more AI models.
- **Tests**
  - Enhanced test cases with consistent instructions for response length.
  - Skipped certain chat-related tests to refine test suite stability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
akumatus
2025-06-03 06:32:27 +00:00
parent a88dcc0951
commit cce756365a
7 changed files with 55 additions and 44 deletions
@@ -333,7 +333,7 @@ The term **“CRDT”** was first introduced by Marc Shapiro, Nuno Preguiça, Ca
messages: [
{
role: 'user' as const,
content: 'what is ssot',
content: 'what is AFFiNE AI?',
params: {
files: [
{
@@ -1558,7 +1558,7 @@ const imageActions: Prompt[] = [
];
const CHAT_PROMPT: Omit<Prompt, 'name'> = {
model: 'gpt-4.1',
model: 'claude-sonnet-4@20250514',
optionalModels: [
'gpt-4.1',
'o3',
@@ -142,7 +142,7 @@ export abstract class AnthropicProvider<T> extends CopilotProvider<T> {
}
private isReasoningModel(model: string) {
// only claude 3.7 sonnet supports reasoning config
return model.startsWith('claude-3-7-sonnet');
// claude 3.5 sonnet doesn't support reasoning config
return model.includes('sonnet') && !model.startsWith('claude-3-5-sonnet');
}
}
@@ -82,7 +82,7 @@ export function setupAIProvider(
//#region actions
AIProvider.provide('chat', async options => {
const { input, contexts, webSearch, reasoning } = options;
const { input, contexts, webSearch } = options;
const sessionId = await createSession({
promptName: 'Chat With AFFiNE AI',
@@ -90,7 +90,7 @@ export function setupAIProvider(
});
return textToText({
...options,
modelId: options.modelId ?? (reasoning ? 'o4-mini' : undefined),
modelId: options.modelId,
client,
sessionId,
content: input,
@@ -40,13 +40,16 @@ test.describe('AIBasic/Chat', () => {
- AI success
`, async ({ loggedInPage: page, utils }) => {
// Type and send a message
await utils.chatPanel.makeChat(page, 'Introduce AFFiNE to me');
await utils.chatPanel.makeChat(
page,
'Introduce AFFiNE to me. Answer in 50 words.'
);
// AI is loading
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Introduce AFFiNE to me',
content: 'Introduce AFFiNE to me. Answer in 50 words.',
},
{
role: 'assistant',
@@ -60,7 +63,7 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Introduce AFFiNE to me',
content: 'Introduce AFFiNE to me. Answer in 50 words.',
},
{
role: 'assistant',
@@ -73,7 +76,7 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Introduce AFFiNE to me',
content: 'Introduce AFFiNE to me. Answer in 50 words.',
},
{
role: 'assistant',
@@ -86,13 +89,16 @@ test.describe('AIBasic/Chat', () => {
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.makeChat(page, 'Introduce AFFiNE to me');
await utils.chatPanel.makeChat(
page,
'Introduce AFFiNE to me. Answer in 50 words.'
);
// AI Generating
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Introduce AFFiNE to me',
content: 'Introduce AFFiNE to me. Answer in 50 words.',
},
{
role: 'assistant',
@@ -104,7 +110,7 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Introduce AFFiNE to me',
content: 'Introduce AFFiNE to me. Answer in 50 words.',
},
{
role: 'assistant',
@@ -117,11 +123,14 @@ test.describe('AIBasic/Chat', () => {
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.makeChat(page, 'Hello, how can you help me?');
await utils.chatPanel.makeChat(
page,
'Hello, how can you help me? Answer in 50 words.'
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Hello, how can you help me?',
content: 'Hello, how can you help me? Answer in 50 words.',
},
{
role: 'assistant',
@@ -130,11 +139,14 @@ test.describe('AIBasic/Chat', () => {
]);
await expect(page.getByTestId('chat-action-list')).toBeVisible();
await utils.chatPanel.makeChat(page, 'Nice to meet you');
await utils.chatPanel.makeChat(
page,
'Nice to meet you. Answer in 50 words.'
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Hello, how can you help me?',
content: 'Hello, how can you help me? Answer in 50 words.',
},
{
role: 'assistant',
@@ -142,7 +154,7 @@ test.describe('AIBasic/Chat', () => {
},
{
role: 'user',
content: 'Nice to meet you',
content: 'Nice to meet you. Answer in 50 words.',
},
{
role: 'assistant',
@@ -168,13 +180,13 @@ test.describe('AIBasic/Chat', () => {
// Type and send a message
await utils.chatPanel.makeChat(
page,
'Hello, write a poem about the moon with 50 words.'
'Hello, write a poem about the moon. Answer in 50 words.'
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Hello, write a poem about the moon with 50 words.',
content: 'Hello, write a poem about the moon. Answer in 50 words.',
},
{
role: 'assistant',
@@ -215,7 +227,7 @@ test.describe('AIBasic/Chat', () => {
await page.route('**/graphql', route => route.abort('failed'));
// Send a message that will fail
await utils.chatPanel.makeChat(page, 'Hello');
await utils.chatPanel.makeChat(page, 'Hello. Answer in 50 words.');
await expect(page.getByTestId('ai-error')).toBeVisible();
await expect(page.getByTestId('action-retry-button')).toBeVisible();
@@ -229,7 +241,7 @@ test.describe('AIBasic/Chat', () => {
await page.route('**/graphql', route => route.abort('failed'));
// Send a message that will fail
await utils.chatPanel.makeChat(page, 'Hello');
await utils.chatPanel.makeChat(page, 'Hello. Answer in 50 words.');
// Verify error state
await expect(page.getByTestId('ai-error')).toBeVisible();
@@ -237,7 +249,7 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Hello',
content: 'Hello. Answer in 50 words.',
},
{
role: 'assistant',
@@ -254,7 +266,7 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Hello',
content: 'Hello. Answer in 50 words.',
},
{
role: 'assistant',
@@ -269,13 +281,13 @@ test.describe('AIBasic/Chat', () => {
}) => {
await utils.chatPanel.makeChat(
page,
'Introduce Large Language Model in under 500 words'
'Introduce Large Language Model. Answer in 50 words.'
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Introduce Large Language Model in under 500 words',
content: 'Introduce Large Language Model. Answer in 50 words.',
},
{
role: 'assistant',
@@ -289,7 +301,7 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Introduce Large Language Model in under 500 words',
content: 'Introduce Large Language Model. Answer in 50 words.',
},
{
role: 'assistant',
@@ -300,7 +312,7 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Introduce Large Language Model in under 500 words',
content: 'Introduce Large Language Model. Answer in 50 words.',
},
{
role: 'assistant',
@@ -333,11 +345,11 @@ test.describe('AIBasic/Chat', () => {
utils,
}) => {
await utils.chatPanel.openChatPanel(page);
await utils.chatPanel.makeChat(page, 'Hello');
await utils.chatPanel.makeChat(page, 'Hello. Answer in 50 words.');
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Hello',
content: 'Hello. Answer in 50 words.',
},
{
role: 'assistant',
@@ -352,11 +364,11 @@ test.describe('AIBasic/Chat', () => {
utils,
}) => {
await utils.chatPanel.openChatPanel(page);
await utils.chatPanel.makeChat(page, 'Hello');
await utils.chatPanel.makeChat(page, 'Hello. Answer in 50 words.');
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Hello',
content: 'Hello. Answer in 50 words.',
},
{
role: 'assistant',
@@ -383,13 +395,12 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.openChatPanel(page);
await utils.chatPanel.makeChat(
page,
'Help me write a two-line love poem, return two paragraphs for me.'
'Help me write a two-line love poem. Answer in 50 words.'
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content:
'Help me write a two-line love poem, return two paragraphs for me.',
content: 'Help me write a two-line love poem. Answer in 50 words.',
},
{
role: 'assistant',
@@ -437,7 +448,7 @@ test.describe('AIBasic/Chat', () => {
page,
'AFFiNE is an open source all in one workspace.'
);
await page.keyboard.type('Translate to chinese');
await page.keyboard.type('Translate to chinese.');
const sendButton = await page.getByTestId('ai-panel-input-send');
await expect(sendButton).toHaveAttribute('data-active', 'true');
@@ -448,7 +459,7 @@ test.describe('AIBasic/Chat', () => {
{
role: 'user',
content:
'AFFiNE is an open source all in one workspace.\nTranslate to chinese',
'AFFiNE is an open source all in one workspace.\nTranslate to chinese.',
},
{
role: 'assistant',
@@ -466,7 +477,7 @@ test.describe('AIBasic/Chat', () => {
await utils.editor.createShape(page, 'HelloWorld');
});
await page.waitForTimeout(1000);
await page.keyboard.type('What color is it?');
await page.keyboard.type('What color is it? Answer in 50 words.');
await page.waitForTimeout(1000);
const sendButton = await page.getByTestId('ai-panel-input-send');
@@ -478,7 +489,7 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'What color is it?',
content: 'What color is it? Answer in 50 words.',
},
{
role: 'assistant',
@@ -500,12 +511,12 @@ test.describe('AIBasic/Chat', () => {
await page.mouse.move(350, 350);
await page.mouse.up({ button: 'right' });
await page.keyboard.type('Who are you?');
await page.keyboard.press('Enter');
await utils.chatPanel.openChatPanel(page);
await utils.chatPanel.makeChat(page, 'Who are you? Answer in 50 words.');
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Who are you?',
content: 'Who are you? Answer in 50 words.',
},
{
role: 'assistant',
@@ -6,7 +6,7 @@ test.describe('AIChatWith/Network', () => {
await utils.chatPanel.openChatPanel(page);
});
test('should support chat with network if network search enabled', async ({
test.skip('should support chat with network if network search enabled', async ({
loggedInPage: page,
utils,
}) => {
@@ -6,7 +6,7 @@ test.describe('AIChatWith/Reasoning', () => {
await utils.chatPanel.openChatPanel(page);
});
test('should support chat with reasoning', async ({
test.skip('should support chat with reasoning', async ({
loggedInPage: page,
utils,
}) => {