Skip to content

Commit

Permalink
Refine search-replace prompt default of coder and make it default (#1…
Browse files Browse the repository at this point in the history
…4870)

* Make search-replace prompt default of coder
* modified coder prompt to remove duplication

fixed #14869

Co-authored-by: Stefan Dirix <[email protected]>
  • Loading branch information
JonasHelming and sdirix authored Feb 7, 2025
1 parent 0140b47 commit 8b3ea1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/ai-ide-agents/src/browser/coder-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AbstractStreamParsingChatAgent, ChatAgent, SystemMessageDescription } f
import { AgentSpecificVariables, PromptTemplate } from '@theia/ai-core';
import { injectable } from '@theia/core/shared/inversify';
import { FILE_CONTENT_FUNCTION_ID, GET_WORKSPACE_FILE_LIST_FUNCTION_ID, GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID } from '../common/workspace-functions';
import { CODER_DEFAULT_PROMPT_TEMPLATE_ID, getCoderReplacePromptTemplate } from '../common/coder-replace-prompt-template';
import { CODER_REPLACE_PROMPT_TEMPLATE_ID, getCoderReplacePromptTemplate } from '../common/coder-replace-prompt-template';
import { WriteChangeToFileProvider } from './file-changeset-functions';

@injectable()
Expand All @@ -36,14 +36,14 @@ export class CoderAgent extends AbstractStreamParsingChatAgent implements ChatAg
}], 'chat');
this.name = 'Coder';
this.description = 'An AI assistant integrated into Theia IDE, designed to assist software developers with code tasks.';
this.promptTemplates = [getCoderReplacePromptTemplate(false), getCoderReplacePromptTemplate(true)];
this.promptTemplates = [getCoderReplacePromptTemplate(true), getCoderReplacePromptTemplate(false)];
this.variables = [];
this.agentSpecificVariables = [];
this.functions = [GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID, GET_WORKSPACE_FILE_LIST_FUNCTION_ID, FILE_CONTENT_FUNCTION_ID, WriteChangeToFileProvider.ID];
}

protected override async getSystemMessageDescription(): Promise<SystemMessageDescription | undefined> {
const resolvedPrompt = await this.promptService.getPrompt(CODER_DEFAULT_PROMPT_TEMPLATE_ID);
const resolvedPrompt = await this.promptService.getPrompt(CODER_REPLACE_PROMPT_TEMPLATE_ID);
return resolvedPrompt ? SystemMessageDescription.fromResolvedPromptTemplate(resolvedPrompt) : undefined;
}

Expand Down
17 changes: 6 additions & 11 deletions packages/ai-ide-agents/src/common/coder-replace-prompt-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {
GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID
} from './workspace-functions';

export const CODER_DEFAULT_PROMPT_TEMPLATE_ID = 'coder-default';
export const CODER_REWRITE_PROMPT_TEMPLATE_ID = 'coder-rewrite';
export const CODER_REPLACE_PROMPT_TEMPLATE_ID = 'coder-search-replace';

export function getCoderReplacePromptTemplate(withSearchAndReplace: boolean = false): PromptTemplate {
return {
id: withSearchAndReplace ? CODER_REPLACE_PROMPT_TEMPLATE_ID : CODER_DEFAULT_PROMPT_TEMPLATE_ID,
id: withSearchAndReplace ? CODER_REPLACE_PROMPT_TEMPLATE_ID : CODER_REWRITE_PROMPT_TEMPLATE_ID,
template: `You are an AI assistant integrated into Theia IDE, designed to assist software developers with code tasks. You can interact with the code base and suggest changes.
## Context Retrieval
Expand All @@ -39,15 +39,10 @@ Use the following functions to interact with the workspace files if you require
## Propose Code Changes
To propose code changes or any file changes to the user, never print code or other full content in your response.
Instead, use the following tool function to propose changes to the user:
**~{changeSet_writeChangeToFile}**
${withSearchAndReplace ? '**~{changeSet_replaceContentInFile}**\n' : ''}
### Guidelines for Proposing Code Changes
- For each proposed change:
- **Retrieve Current Content**: Use getFileContent to get the latest content of the target file.
- **Change Content**: Use ${withSearchAndReplace ? 'changeSet_writeChangeToFile or changeSet_replaceContentInFile' : 'changeSet_writeToFileChange'}\n
to suggest file changes to the user.`,
...(withSearchAndReplace ? { variantOf: CODER_DEFAULT_PROMPT_TEMPLATE_ID } : {}),
For each proposed change:
- **Retrieve Current Content**: Use ${FILE_CONTENT_FUNCTION_ID} to get the latest content of the target file.
- **Change Content**: Use ${withSearchAndReplace ? '~{changeSet_replaceContentInFile} or ' : ''} '~{changeSet_writeChangeToFile}' to suggest file changes to the user.`,
...(!withSearchAndReplace ? { variantOf: CODER_REPLACE_PROMPT_TEMPLATE_ID } : {}),
};
}

0 comments on commit 8b3ea1c

Please sign in to comment.