Skip to content

Commit 41be92e

Browse files
eneufeldJonasHelming
authored andcommitted
Add next template for coder
Co-authored-by: Jonas Helming <[email protected]>
1 parent b3a255c commit 41be92e

File tree

5 files changed

+70
-13
lines changed

5 files changed

+70
-13
lines changed

packages/ai-ide/src/browser/coder-agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { AbstractStreamParsingChatAgent } from '@theia/ai-chat/lib/common';
1717
import { injectable } from '@theia/core/shared/inversify';
1818
import { FILE_CONTENT_FUNCTION_ID, GET_WORKSPACE_FILE_LIST_FUNCTION_ID, GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID } from '../common/workspace-functions';
19-
import { CODER_REPLACE_PROMPT_TEMPLATE_ID, getCoderReplacePromptTemplate } from '../common/coder-replace-prompt-template';
19+
import { CODER_REPLACE_PROMPT_TEMPLATE_ID, getCoderReplacePromptTemplate, getCoderReplacePromptTemplateNext } from '../common/coder-replace-prompt-template';
2020
import { WriteChangeToFileProvider } from './file-changeset-functions';
2121
import { LanguageModelRequirement } from '@theia/ai-core';
2222
import { nls } from '@theia/core';
@@ -35,7 +35,7 @@ export class CoderAgent extends AbstractStreamParsingChatAgent {
3535
'An AI assistant integrated into Theia IDE, designed to assist software developers. This agent can access the users workspace, it can get a list of all available files \
3636
and folders and retrieve their content. Futhermore, it can suggest modifications of files to the user. It can therefore assist the user with coding tasks or other \
3737
tasks involving file changes.');
38-
override promptTemplates = [getCoderReplacePromptTemplate(true), getCoderReplacePromptTemplate(false)];
38+
override promptTemplates = [getCoderReplacePromptTemplate(true), getCoderReplacePromptTemplate(false), getCoderReplacePromptTemplateNext()];
3939
override functions = [GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID, GET_WORKSPACE_FILE_LIST_FUNCTION_ID, FILE_CONTENT_FUNCTION_ID, WriteChangeToFileProvider.ID];
4040
protected override systemPromptId: string | undefined = CODER_REPLACE_PROMPT_TEMPLATE_ID;
4141

packages/ai-ide/src/browser/workspace-search-provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { CancellationToken } from '@theia/core';
2020
import { inject, injectable } from '@theia/core/shared/inversify';
2121
import { SearchInWorkspaceService, SearchInWorkspaceCallbacks } from '@theia/search-in-workspace/lib/browser/search-in-workspace-service';
2222
import { SearchInWorkspaceResult, SearchInWorkspaceOptions } from '@theia/search-in-workspace/lib/common/search-in-workspace-interface';
23+
import { SEARCH_IN_WORKSPACE_FUNCTION_ID } from '../common/workspace-functions';
2324

24-
const SEARCH_IN_WORKSPACE_ID = 'searchInWorkspace';
2525
@injectable()
2626
export class WorkspaceSearchProvider implements ToolProvider {
2727

@@ -32,8 +32,8 @@ export class WorkspaceSearchProvider implements ToolProvider {
3232

3333
getTool(): ToolRequest {
3434
return {
35-
id: SEARCH_IN_WORKSPACE_ID,
36-
name: SEARCH_IN_WORKSPACE_ID,
35+
id: SEARCH_IN_WORKSPACE_FUNCTION_ID,
36+
name: SEARCH_IN_WORKSPACE_FUNCTION_ID,
3737
description: 'Searches the content of files within the workspace for lines matching the given search term (`query`). \
3838
The search uses case-insensitive string matching or regular expressions (controlled by the `useRegExp` parameter). \
3939
It returns a list of matching files, including the file path (URI), the line number, and the full text content of each matching line. \

packages/ai-ide/src/browser/workspace-task-provider.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import { TaskService } from '@theia/task/lib/browser/task-service';
2020
import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
2121
import { MutableChatRequestModel } from '@theia/ai-chat';
2222
import { CancellationToken } from '@theia/core';
23-
24-
export const LIST_TASKS_ID = 'listTasks';
25-
export const RUN_TASK_ID = 'runTask';
23+
import { LIST_TASKS_FUNCTION_ID, RUN_TASK_FUNCTION_ID } from '../common/workspace-functions';
2624

2725
@injectable()
2826
export class TaskListProvider implements ToolProvider {
@@ -32,8 +30,8 @@ export class TaskListProvider implements ToolProvider {
3230

3331
getTool(): ToolRequest {
3432
return {
35-
id: LIST_TASKS_ID,
36-
name: LIST_TASKS_ID,
33+
id: LIST_TASKS_FUNCTION_ID,
34+
name: LIST_TASKS_FUNCTION_ID,
3735
description: 'Lists available tool tasks in the workspace, such as build, run, test. Tasks can be filtered by name.',
3836
parameters: {
3937
type: 'object',
@@ -72,8 +70,8 @@ export class TaskRunnerProvider implements ToolProvider {
7270

7371
getTool(): ToolRequest {
7472
return {
75-
id: RUN_TASK_ID,
76-
name: RUN_TASK_ID,
73+
id: RUN_TASK_FUNCTION_ID,
74+
name: RUN_TASK_FUNCTION_ID,
7775
description: 'Executes a specified task.',
7876
parameters: {
7977
type: 'object',

packages/ai-ide/src/common/coder-replace-prompt-template.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,70 @@ import {
1515
GET_WORKSPACE_FILE_LIST_FUNCTION_ID,
1616
FILE_CONTENT_FUNCTION_ID,
1717
GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID,
18-
GET_FILE_DIAGNOSTICS_ID
18+
GET_FILE_DIAGNOSTICS_ID,
19+
SEARCH_IN_WORKSPACE_FUNCTION_ID,
20+
LIST_TASKS_FUNCTION_ID,
21+
RUN_TASK_FUNCTION_ID
1922
} from './workspace-functions';
2023
import { CONTEXT_FILES_VARIABLE_ID } from './context-variables';
2124
import { UPDATE_CONTEXT_FILES_FUNCTION_ID } from './context-functions';
2225

2326
export const CODER_REWRITE_PROMPT_TEMPLATE_ID = 'coder-rewrite';
2427
export const CODER_REPLACE_PROMPT_TEMPLATE_ID = 'coder-search-replace';
28+
export const CODER_REPLACE_PROMPT_TEMPLATE_NEXT_ID = 'coder-search-replace-next';
2529

30+
export function getCoderReplacePromptTemplateNext(): PromptTemplate {
31+
return {
32+
id: CODER_REPLACE_PROMPT_TEMPLATE_NEXT_ID,
33+
template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
34+
Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
35+
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
36+
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.
37+
38+
## Context Retrieval
39+
Use the following functions to interact with the workspace files if you require context:
40+
- **~{${GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID}}**: Returns the complete directory structure.
41+
- **~{${GET_WORKSPACE_FILE_LIST_FUNCTION_ID}}**: Lists files and directories in a specific directory.
42+
- **~{${FILE_CONTENT_FUNCTION_ID}}**: Retrieves the content of a specific file.
43+
- **~{${UPDATE_CONTEXT_FILES_FUNCTION_ID}}**: Remember file locations that are relevant for completing your tasks. Only add files that are really relevant to look at later.
44+
45+
## File Validation
46+
Use the following function to retrieve a list of problems in a file if the user requests fixes in a given file:
47+
- **~{${GET_FILE_DIAGNOSTICS_ID}}**: Retrieves a list of problems identified in a given file by tool integrations such as language servers and linters.
48+
49+
## Propose Code Changes
50+
To propose code changes or any file changes to the user, never print code or new file content in your response.
51+
52+
Instead, for each file you want to propose changes for:
53+
- **Always Retrieve Current Content**: Use ${FILE_CONTENT_FUNCTION_ID} to get the latest content of the target file.
54+
- **Change Content**: Use ~{changeSet_writeChangeToFile} or ~{changeSet_replaceContentInFile} to propose file changes to the user.\
55+
If ~{changeSet_replaceContentInFile} continously fails use ~{changeSet_writeChangeToFile}. Calling a function on a file will override previous \
56+
function calls on the same file, so you need exactly one successful call with all proposed changes per changed file. The changes will be presented as a applicable diff to \
57+
the user in any case.'
58+
59+
## File Search
60+
61+
To search for content in workspace files, use the following function: ~{${SEARCH_IN_WORKSPACE_FUNCTION_ID}}
62+
63+
## Tasks
64+
65+
The user might want you to execute some task. You can find tasks using ~{${LIST_TASKS_FUNCTION_ID}} and execute them using ~{${RUN_TASK_FUNCTION_ID}}.
66+
67+
## Additional Context
68+
69+
The following files have been provided for additional context. Some of them may also be referred to by the user. \
70+
Always look at the relevant files to understand your task using the function ~{${FILE_CONTENT_FUNCTION_ID}}
71+
{{${CONTEXT_FILES_VARIABLE_ID}}}
72+
73+
## Previously Proposed Changes
74+
You have previously proposed changes for the following files. Some suggestions may have been accepted by the user, while others may still be pending.
75+
{{${CHANGE_SET_SUMMARY_VARIABLE_ID}}}
76+
77+
{{prompt:project-info}}
78+
`,
79+
...({ variantOf: CODER_REPLACE_PROMPT_TEMPLATE_ID }),
80+
};
81+
}
2682
export function getCoderReplacePromptTemplate(withSearchAndReplace: boolean = false): PromptTemplate {
2783
return {
2884
id: withSearchAndReplace ? CODER_REPLACE_PROMPT_TEMPLATE_ID : CODER_REWRITE_PROMPT_TEMPLATE_ID,

packages/ai-ide/src/common/workspace-functions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ export const FILE_CONTENT_FUNCTION_ID = 'getFileContent';
1717
export const GET_WORKSPACE_FILE_LIST_FUNCTION_ID = 'getWorkspaceFileList';
1818
export const GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID = 'getWorkspaceDirectoryStructure';
1919
export const GET_FILE_DIAGNOSTICS_ID = 'getFileDiagnostics';
20+
export const SEARCH_IN_WORKSPACE_FUNCTION_ID = 'searchInWorkspace';
21+
export const LIST_TASKS_FUNCTION_ID = 'listTasks';
22+
export const RUN_TASK_FUNCTION_ID = 'runTask';

0 commit comments

Comments
 (0)