Skip to content

Commit 9d10686

Browse files
committed
Removes system prompts
Some newer models don't support them and for those that do it doesn't help much
1 parent eb4c841 commit 9d10686

File tree

4 files changed

+15
-46
lines changed

4 files changed

+15
-46
lines changed

src/ai/anthropicProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CancellationToken } from 'vscode';
22
import type { AIModel } from './aiProviderService';
33
import { getMaxCharacters } from './aiProviderService';
4-
import type { ChatMessage, SystemMessage } from './openAICompatibleProvider';
4+
import type { ChatMessage } from './openAICompatibleProvider';
55
import { OpenAICompatibleProvider } from './openAICompatibleProvider';
66

77
const provider = { id: 'anthropic', name: 'Anthropic' } as const;
@@ -102,7 +102,7 @@ export class AnthropicProvider extends OpenAICompatibleProvider<typeof provider.
102102
override async fetch(
103103
model: AIModel<typeof provider.id>,
104104
apiKey: string,
105-
messages: (maxCodeCharacters: number, retries: number) => [SystemMessage, ...ChatMessage[]],
105+
messages: (maxCodeCharacters: number, retries: number) => ChatMessage[],
106106
outputTokens: number,
107107
cancellation: CancellationToken | undefined,
108108
): Promise<[result: string, maxCodeCharacters: number]> {

src/ai/openAICompatibleProvider.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ import { interpolate } from '../system/string';
1010
import type { AIModel, AIProvider } from './aiProviderService';
1111
import { getMaxCharacters, getOrPromptApiKey, showDiffTruncationWarning } from './aiProviderService';
1212
import {
13-
explainChangesSystemPrompt,
1413
explainChangesUserPrompt,
15-
generateCloudPatchMessageSystemPrompt,
1614
generateCloudPatchMessageUserPrompt,
17-
generateCodeSuggestMessageSystemPrompt,
1815
generateCodeSuggestMessageUserPrompt,
19-
generateCommitMessageSystemPrompt,
2016
generateCommitMessageUserPrompt,
2117
} from './prompts';
2218

@@ -63,7 +59,6 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
6359
reporting: TelemetryEvents['ai/generate'],
6460
promptConfig: {
6561
type: 'commit' | 'cloud-patch' | 'code-suggestion';
66-
systemPrompt: string;
6762
userPrompt: string;
6863
customInstructions?: string;
6964
},
@@ -76,11 +71,7 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
7671
const [result, maxCodeCharacters] = await this.fetch(
7772
model,
7873
apiKey,
79-
(max, retries): [SystemMessage, ...ChatMessage[]] => {
80-
const system: SystemMessage = {
81-
role: 'system',
82-
content: promptConfig.systemPrompt,
83-
};
74+
(max, retries): ChatMessage[] => {
8475
const messages: ChatMessage[] = [
8576
{
8677
role: 'user',
@@ -93,10 +84,9 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
9384
];
9485

9586
reporting['retry.count'] = retries;
96-
reporting['input.length'] =
97-
(reporting['input.length'] ?? 0) + sum([system, ...messages], m => m.content.length);
87+
reporting['input.length'] = (reporting['input.length'] ?? 0) + sum(messages, m => m.content.length);
9888

99-
return [system, ...messages];
89+
return messages;
10090
},
10191
4096,
10292
options?.cancellation,
@@ -134,13 +124,11 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
134124
codeSuggestion
135125
? {
136126
type: 'code-suggestion',
137-
systemPrompt: generateCodeSuggestMessageSystemPrompt,
138127
userPrompt: generateCodeSuggestMessageUserPrompt,
139128
customInstructions: configuration.get('ai.generateCodeSuggestMessage.customInstructions'),
140129
}
141130
: {
142131
type: 'cloud-patch',
143-
systemPrompt: generateCloudPatchMessageSystemPrompt,
144132
userPrompt: generateCloudPatchMessageUserPrompt,
145133
customInstructions: configuration.get('ai.generateCloudPatchMessage.customInstructions'),
146134
},
@@ -160,7 +148,6 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
160148
reporting,
161149
{
162150
type: 'commit',
163-
systemPrompt: generateCommitMessageSystemPrompt,
164151
userPrompt: generateCommitMessageUserPrompt,
165152
customInstructions: configuration.get('ai.generateCommitMessage.customInstructions'),
166153
},
@@ -182,11 +169,7 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
182169
const [result, maxCodeCharacters] = await this.fetch(
183170
model,
184171
apiKey,
185-
(max, retries): [SystemMessage, ...ChatMessage[]] => {
186-
const system: SystemMessage = {
187-
role: 'system',
188-
content: explainChangesSystemPrompt,
189-
};
172+
(max, retries): ChatMessage[] => {
190173
const messages: ChatMessage[] = [
191174
{
192175
role: 'user',
@@ -199,10 +182,9 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
199182
];
200183

201184
reporting['retry.count'] = retries;
202-
reporting['input.length'] =
203-
(reporting['input.length'] ?? 0) + sum([system, ...messages], m => m.content.length);
185+
reporting['input.length'] = (reporting['input.length'] ?? 0) + sum(messages, m => m.content.length);
204186

205-
return [system, ...messages];
187+
return messages;
206188
},
207189
4096,
208190
options?.cancellation,
@@ -221,7 +203,7 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
221203
protected async fetch(
222204
model: AIModel<T>,
223205
apiKey: string,
224-
messages: (maxCodeCharacters: number, retries: number) => [SystemMessage, ...ChatMessage[]],
206+
messages: (maxCodeCharacters: number, retries: number) => ChatMessage[],
225207
outputTokens: number,
226208
cancellation: CancellationToken | undefined,
227209
): Promise<[result: string, maxCodeCharacters: number]> {

src/ai/prompts.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export const generateCommitMessageSystemPrompt = `You are an advanced AI programming assistant`;
2-
export const generateCommitMessageUserPrompt = `You are tasked with summarizing code changes into a concise but meaningful commit message. You will be provided with a code diff and optional additional context. Your goal is to analyze the changes and create a clear, informative commit message that accurately represents the modifications made to the code.
1+
export const generateCommitMessageUserPrompt = `You are an advanced AI programming assistant and are tasked with summarizing code changes into a concise but meaningful commit message. You will be provided with a code diff and optional additional context. Your goal is to analyze the changes and create a clear, informative commit message that accurately represents the modifications made to the code.
32
43
First, examine the following code changes provided in Git diff format:
54
<~~diff~~>
@@ -51,8 +50,7 @@ Fixes #789
5150
5251
Now, based on the provided code diff and any additional context, create a concise but meaningful commit message following the instructions above.`;
5352

54-
export const generateCloudPatchMessageSystemPrompt = `You are an advanced AI programming assistant`;
55-
export const generateCloudPatchMessageUserPrompt = `You are tasked with summarizing code changes into a concise and meaningful title and description. You will be provided with a code diff and optional additional context. Your goal is to analyze the changes and create a clear, informative title and description that accurately represents the modifications made to the code.
53+
export const generateCloudPatchMessageUserPrompt = `You are an advanced AI programming assistant and are tasked with summarizing code changes into a concise and meaningful title and description. You will be provided with a code diff and optional additional context. Your goal is to analyze the changes and create a clear, informative title and description that accurately represents the modifications made to the code.
5654
5755
First, examine the following code changes provided in Git diff format:
5856
<~~diff~~>
@@ -99,8 +97,7 @@ Integrates JWT for secure token generation
9997
10098
Now, based on the provided code diff and any additional context, create a concise but meaningful title and description following the instructions above.`;
10199

102-
export const generateCodeSuggestMessageSystemPrompt = `You are an advanced AI programming assistant`;
103-
export const generateCodeSuggestMessageUserPrompt = `You are tasked with summarizing code changes into a concise and meaningful code review title and description. You will be provided with a code diff and optional additional context. Your goal is to analyze the changes and create a clear, informative code review title and description that accurately represents the modifications made to the code.
100+
export const generateCodeSuggestMessageUserPrompt = `You are an advanced AI programming assistant and are tasked with summarizing code changes into a concise and meaningful code review title and description. You will be provided with a code diff and optional additional context. Your goal is to analyze the changes and create a clear, informative code review title and description that accurately represents the modifications made to the code.
104101
105102
First, examine the following code changes provided in Git diff format:
106103
<~~diff~~>
@@ -147,8 +144,7 @@ Integrates JWT for secure token generation
147144
148145
Now, based on the provided code diff and any additional context, create a concise but meaningful code review title and description following the instructions above.`;
149146

150-
export const explainChangesSystemPrompt = `You are an advanced AI programming assistant`;
151-
export const explainChangesUserPrompt = `You are tasked with creating clear, technical summaries of code changes that help reviewers understand the modifications and their implications. You will analyze a code diff and the author-provided message to produce a structured summary that captures the essential aspects of the changes.
147+
export const explainChangesUserPrompt = `You are an advanced AI programming assistant and are tasked with creating clear, technical summaries of code changes that help reviewers understand the modifications and their implications. You will analyze a code diff and the author-provided message to produce a structured summary that captures the essential aspects of the changes.
152148
153149
First, examine the following code changes provided in Git diff format:
154150
<~~diff~~>

src/ai/vscodeProvider.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ import { capitalize, getPossessiveForm, interpolate } from '../system/string';
88
import type { AIModel, AIProvider } from './aiProviderService';
99
import { getMaxCharacters, showDiffTruncationWarning } from './aiProviderService';
1010
import {
11-
explainChangesSystemPrompt,
1211
explainChangesUserPrompt,
13-
generateCloudPatchMessageSystemPrompt,
1412
generateCloudPatchMessageUserPrompt,
15-
generateCodeSuggestMessageSystemPrompt,
1613
generateCodeSuggestMessageUserPrompt,
17-
generateCommitMessageSystemPrompt,
1814
generateCommitMessageUserPrompt,
1915
} from './prompts';
2016

@@ -53,7 +49,6 @@ export class VSCodeAIProvider implements AIProvider<typeof provider.id> {
5349
reporting: TelemetryEvents['ai/generate'],
5450
promptConfig: {
5551
type: 'commit' | 'cloud-patch' | 'code-suggestion';
56-
systemPrompt: string;
5752
userPrompt: string;
5853
customInstructions?: string;
5954
},
@@ -77,7 +72,6 @@ export class VSCodeAIProvider implements AIProvider<typeof provider.id> {
7772
try {
7873
while (true) {
7974
const messages: LanguageModelChatMessage[] = [
80-
LanguageModelChatMessage.User(promptConfig.systemPrompt),
8175
LanguageModelChatMessage.User(
8276
interpolate(promptConfig.userPrompt, {
8377
diff: diff.substring(0, maxCodeCharacters),
@@ -151,13 +145,11 @@ export class VSCodeAIProvider implements AIProvider<typeof provider.id> {
151145
codeSuggestion
152146
? {
153147
type: 'code-suggestion',
154-
systemPrompt: generateCodeSuggestMessageSystemPrompt,
155148
userPrompt: generateCodeSuggestMessageUserPrompt,
156149
customInstructions: configuration.get('ai.generateCodeSuggestMessage.customInstructions'),
157150
}
158151
: {
159152
type: 'cloud-patch',
160-
systemPrompt: generateCloudPatchMessageSystemPrompt,
161153
userPrompt: generateCloudPatchMessageUserPrompt,
162154
customInstructions: configuration.get('ai.generateCloudPatchMessage.customInstructions'),
163155
},
@@ -180,7 +172,6 @@ export class VSCodeAIProvider implements AIProvider<typeof provider.id> {
180172
reporting,
181173
{
182174
type: 'commit',
183-
systemPrompt: generateCommitMessageSystemPrompt,
184175
userPrompt: generateCommitMessageUserPrompt,
185176
customInstructions: configuration.get('ai.generateCommitMessage.customInstructions'),
186177
},
@@ -216,11 +207,11 @@ export class VSCodeAIProvider implements AIProvider<typeof provider.id> {
216207

217208
const messages: LanguageModelChatMessage[] = [
218209
LanguageModelChatMessage.User(
219-
`${explainChangesSystemPrompt}.\n\n${interpolate(explainChangesUserPrompt, {
210+
interpolate(explainChangesUserPrompt, {
220211
diff: code,
221212
message: message,
222213
instructions: configuration.get('ai.explainChanges.customInstructions') ?? '',
223-
})}`,
214+
}),
224215
),
225216
];
226217

0 commit comments

Comments
 (0)