From 03aab6f72caab8262fab96025a239a0a6f3839e6 Mon Sep 17 00:00:00 2001 From: Jonas Helming Date: Sun, 17 Nov 2024 00:18:52 +0100 Subject: [PATCH 1/3] All three brackets for variables fixed #14464 --- .../data/prompttemplate.tmLanguage.json | 51 +++++++++++++-- .../agent-configuration-widget.tsx | 4 +- .../ai-core/src/common/prompt-service-util.ts | 10 ++- .../ai-core/src/common/prompt-service.spec.ts | 64 +++++++++++++++++++ packages/ai-core/src/common/prompt-service.ts | 9 ++- 5 files changed, 126 insertions(+), 12 deletions(-) diff --git a/packages/ai-core/data/prompttemplate.tmLanguage.json b/packages/ai-core/data/prompttemplate.tmLanguage.json index da9b33b66723a..18b135042c764 100644 --- a/packages/ai-core/data/prompttemplate.tmLanguage.json +++ b/packages/ai-core/data/prompttemplate.tmLanguage.json @@ -2,17 +2,56 @@ "scopeName": "source.prompttemplate", "patterns": [ { - "name": "variable.other.prompttemplate", - "begin": "{{", + "name": "invalid.illegal.mismatched.prompttemplate", + "match": "\\{\\{\\{[^}]*\\}\\}(?!\\})", + "captures": { + "0": { + "name": "invalid.illegal.bracket.mismatch" + } + } + }, + { + "name": "invalid.illegal.mismatched.prompttemplate", + "match": "\\{\\{[^}]*\\}\\}\\}(?!\\})", + "captures": { + "0": { + "name": "invalid.illegal.bracket.mismatch" + } + } + }, + { + "name": "variable.other.prompttemplate.double", + "begin": "\\{\\{", "beginCaptures": { "0": { - "name": "punctuation.definition.brace.begin" + "name": "punctuation.definition.variable.begin" } }, - "end": "}}", + "end": "\\}\\}(?!\\})", "endCaptures": { "0": { - "name": "punctuation.definition.brace.end" + "name": "punctuation.definition.variable.end" + } + }, + "patterns": [ + { + "name": "keyword.control", + "match": "[a-zA-Z_][a-zA-Z0-9_]*" + } + ] + }, + { + "name": "variable.other.prompttemplate.triple", + "begin": "\\{\\{\\{", + "beginCaptures": { + "0": { + "name": "punctuation.definition.variable.begin" + } + }, + "end": "\\}\\}\\}(?!\\})", + "endCaptures": { + "0": { + "name": "punctuation.definition.variable.end" } }, "patterns": [ @@ -49,4 +88,4 @@ "fileTypes": [ ".prompttemplate" ] -} +} \ No newline at end of file diff --git a/packages/ai-core/src/browser/ai-configuration/agent-configuration-widget.tsx b/packages/ai-core/src/browser/ai-configuration/agent-configuration-widget.tsx index 09639eb0a1717..a81953302dd97 100644 --- a/packages/ai-core/src/browser/ai-configuration/agent-configuration-widget.tsx +++ b/packages/ai-core/src/browser/ai-configuration/agent-configuration-widget.tsx @@ -23,8 +23,8 @@ import { AIVariableService, LanguageModel, LanguageModelRegistry, + matchVariablesRegEx, PROMPT_FUNCTION_REGEX, - PROMPT_VARIABLE_REGEX, PromptCustomizationService, PromptService, } from '../../common'; @@ -182,7 +182,7 @@ export class AIAgentConfigurationWidget extends ReactWidget { promptTemplates.forEach(template => { const storedPrompt = this.promptService.getRawPrompt(template.id); const prompt = storedPrompt?.template ?? template.template; - const variableMatches = [...prompt.matchAll(PROMPT_VARIABLE_REGEX)]; + const variableMatches = matchVariablesRegEx(prompt); variableMatches.forEach(match => { const variableId = match[1]; diff --git a/packages/ai-core/src/common/prompt-service-util.ts b/packages/ai-core/src/common/prompt-service-util.ts index 0a7cf3e6b34be..55e9f3f200d09 100644 --- a/packages/ai-core/src/common/prompt-service-util.ts +++ b/packages/ai-core/src/common/prompt-service-util.ts @@ -14,8 +14,14 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** -/** Should match the one from VariableResolverService. The format is `{{variableName:arg}}`. */ -export const PROMPT_VARIABLE_REGEX = /\{\{\s*(.*?)\s*\}\}/g; +/** Should match the one from VariableResolverService. The format is `{{variableName:arg}}`. We allow {{}} and {{{}}} but no mixtures */ +export const PROMPT_VARIABLE_TWO_BRACES_REGEX = /(? { promptService.storePrompt('1', 'Hello, {{name}}!'); promptService.storePrompt('2', 'Goodbye, {{name}}!'); promptService.storePrompt('3', 'Ciao, {{invalid}}!'); + promptService.storePrompt('8', 'Hello, {{{name}}}'); }); it('should initialize prompts from PromptCollectionService', () => { @@ -47,6 +48,7 @@ describe('PromptService', () => { expect(allPrompts['1'].template).to.equal('Hello, {{name}}!'); expect(allPrompts['2'].template).to.equal('Goodbye, {{name}}!'); expect(allPrompts['3'].template).to.equal('Ciao, {{invalid}}!'); + expect(allPrompts['8'].template).to.equal('Hello, {{{name}}}'); }); it('should retrieve raw prompt by id', () => { @@ -95,4 +97,66 @@ describe('PromptService', () => { expect(prompt?.text).to.equal('Hello, John!'); } }); + + it('should retrieve raw prompt by id (three bracket)', () => { + const rawPrompt = promptService.getRawPrompt('8'); + expect(rawPrompt?.template).to.equal('Hello, {{{name}}}'); + }); + + it('should correctly replace variables (three brackets)', async () => { + const formattedPrompt = await promptService.getPrompt('8'); + expect(formattedPrompt?.text).to.equal('Hello, Jane'); + }); + + it('should ignore whitespace in variables (three bracket)', async () => { + promptService.storePrompt('9', 'Hello, {{{name }}}'); + promptService.storePrompt('10', 'Hello, {{{ name}}}'); + promptService.storePrompt('11', 'Hello, {{{ name }}}'); + promptService.storePrompt('12', 'Hello, {{{ name }}}'); + for (let i = 9; i <= 12; i++) { + const prompt = await promptService.getPrompt(`${i}`, { name: 'John' }); + expect(prompt?.text).to.equal('Hello, John'); + } + }); + + it('should ignore invalid prompts with unmatched brackets', async () => { + promptService.storePrompt('9', 'Hello, {{name'); + promptService.storePrompt('10', 'Hello, {{{name'); + promptService.storePrompt('11', 'Hello, name}}}}'); + const prompt1 = await promptService.getPrompt('9', { name: 'John' }); + expect(prompt1?.text).to.equal('Hello, {{name'); // Not matching due to missing closing brackets + + const prompt2 = await promptService.getPrompt('10', { name: 'John' }); + expect(prompt2?.text).to.equal('Hello, {{{name'); // Matches pattern due to valid three-start-two-end brackets + + const prompt3 = await promptService.getPrompt('11', { name: 'John' }); + expect(prompt3?.text).to.equal('Hello, name}}}}'); // Extra closing bracket, does not match cleanly + }); + + it('should handle a mixture of two and three brackets correctly', async () => { + promptService.storePrompt('12', 'Hi, {{name}}}'); // (invalid) + promptService.storePrompt('13', 'Hello, {{{name}}'); // (invalid) + promptService.storePrompt('14', 'Greetings, {{{name}}}}'); // (invalid) + promptService.storePrompt('15', 'Bye, {{{{name}}}'); // (invalid) + promptService.storePrompt('16', 'Ciao, {{{{name}}}}'); // (invalid) + promptService.storePrompt('17', 'Hi, {{name}}! {{{name}}}'); // Mixed valid patterns + + const prompt12 = await promptService.getPrompt('12', { name: 'John' }); + expect(prompt12?.text).to.equal('Hi, {{name}}}'); + + const prompt13 = await promptService.getPrompt('13', { name: 'John' }); + expect(prompt13?.text).to.equal('Hello, {{{name}}'); + + const prompt14 = await promptService.getPrompt('14', { name: 'John' }); + expect(prompt14?.text).to.equal('Greetings, {{{name}}}}'); + + const prompt15 = await promptService.getPrompt('15', { name: 'John' }); + expect(prompt15?.text).to.equal('Bye, {{{{name}}}'); + + const prompt16 = await promptService.getPrompt('16', { name: 'John' }); + expect(prompt16?.text).to.equal('Ciao, {{{{name}}}}'); + + const prompt17 = await promptService.getPrompt('17', { name: 'John' }); + expect(prompt17?.text).to.equal('Hi, John! John'); + }); }); diff --git a/packages/ai-core/src/common/prompt-service.ts b/packages/ai-core/src/common/prompt-service.ts index c6f8825477698..87f029c6bbf02 100644 --- a/packages/ai-core/src/common/prompt-service.ts +++ b/packages/ai-core/src/common/prompt-service.ts @@ -20,7 +20,7 @@ import { AIVariableService } from './variable-service'; import { ToolInvocationRegistry } from './tool-invocation-registry'; import { toolRequestToPromptText } from './language-model-util'; import { ToolRequest } from './language-model'; -import { PROMPT_VARIABLE_REGEX, PROMPT_FUNCTION_REGEX } from './prompt-service-util'; +import { PROMPT_FUNCTION_REGEX, matchVariablesRegEx } from './prompt-service-util'; export interface PromptTemplate { id: string; @@ -181,13 +181,18 @@ export class PromptServiceImpl implements PromptService { getDefaultRawPrompt(id: string): PromptTemplate | undefined { return this._prompts[id]; } + + matchVariables(template: string): RegExpMatchArray[] { + return matchVariablesRegEx(template); + } + async getPrompt(id: string, args?: { [key: string]: unknown }): Promise { const prompt = this.getRawPrompt(id); if (prompt === undefined) { return undefined; } - const matches = [...prompt.template.matchAll(PROMPT_VARIABLE_REGEX)]; + const matches = this.matchVariables(prompt.template); const variableAndArgReplacements = await Promise.all(matches.map(async match => { const completeText = match[0]; const variableAndArg = match[1]; From 21b8c8f3c9dc08c4b67bfdf752635d2a76922528 Mon Sep 17 00:00:00 2001 From: Jonas Helming Date: Sun, 17 Nov 2024 23:53:48 +0100 Subject: [PATCH 2/3] Allow comments in prompt templates fixed #14469 --- .../data/prompttemplate.tmLanguage.json | 16 ++++ .../agent-configuration-widget.tsx | 2 +- .../ai-core/src/common/prompt-service.spec.ts | 85 +++++++++++++++++++ packages/ai-core/src/common/prompt-service.ts | 25 +++++- 4 files changed, 125 insertions(+), 3 deletions(-) diff --git a/packages/ai-core/data/prompttemplate.tmLanguage.json b/packages/ai-core/data/prompttemplate.tmLanguage.json index 18b135042c764..338af6ea4514b 100644 --- a/packages/ai-core/data/prompttemplate.tmLanguage.json +++ b/packages/ai-core/data/prompttemplate.tmLanguage.json @@ -19,6 +19,22 @@ } } }, + { + "name": "comment.block.prompttemplate", + "begin": "^[\\t ]*{{!--", + "beginCaptures": { + "0": { + "name": "punctuation.definition.comment.begin" + } + }, + "end": "--}}", + "endCaptures": { + "0": { + "name": "punctuation.definition.comment.end" + } + }, + "patterns": [] + }, { "name": "variable.other.prompttemplate.double", "begin": "\\{\\{", diff --git a/packages/ai-core/src/browser/ai-configuration/agent-configuration-widget.tsx b/packages/ai-core/src/browser/ai-configuration/agent-configuration-widget.tsx index a81953302dd97..35abb84b328e5 100644 --- a/packages/ai-core/src/browser/ai-configuration/agent-configuration-widget.tsx +++ b/packages/ai-core/src/browser/ai-configuration/agent-configuration-widget.tsx @@ -180,7 +180,7 @@ export class AIAgentConfigurationWidget extends ReactWidget { const promptTemplates = agent.promptTemplates; const result: ParsedPrompt = { functions: [], globalVariables: [], agentSpecificVariables: [] }; promptTemplates.forEach(template => { - const storedPrompt = this.promptService.getRawPrompt(template.id); + const storedPrompt = this.promptService.getUnresolvedPrompt(template.id); const prompt = storedPrompt?.template ?? template.template; const variableMatches = matchVariablesRegEx(prompt); diff --git a/packages/ai-core/src/common/prompt-service.spec.ts b/packages/ai-core/src/common/prompt-service.spec.ts index 164925f62a5ee..106ef4fc85df0 100644 --- a/packages/ai-core/src/common/prompt-service.spec.ts +++ b/packages/ai-core/src/common/prompt-service.spec.ts @@ -159,4 +159,89 @@ describe('PromptService', () => { const prompt17 = await promptService.getPrompt('17', { name: 'John' }); expect(prompt17?.text).to.equal('Hi, John! John'); }); + + it('should strip single-line comments at the start of the template', () => { + promptService.storePrompt('comment-basic', '{{!-- Comment --}}Hello, {{name}}!'); + const prompt = promptService.getUnresolvedPrompt('comment-basic'); + expect(prompt?.template).to.equal('Hello, {{name}}!'); + }); + + it('should remove line break after first-line comment', () => { + promptService.storePrompt('comment-line-break', '{{!-- Comment --}}\nHello, {{name}}!'); + const prompt = promptService.getUnresolvedPrompt('comment-line-break'); + expect(prompt?.template).to.equal('Hello, {{name}}!'); + }); + + it('should strip multiline comments at the start of the template', () => { + promptService.storePrompt('comment-multiline', '{{!--\nMultiline comment\n--}}\nGoodbye, {{name}}!'); + const prompt = promptService.getUnresolvedPrompt('comment-multiline'); + expect(prompt?.template).to.equal('Goodbye, {{name}}!'); + }); + + it('should not strip comments not in the first line', () => { + promptService.storePrompt('comment-second-line', 'Hello, {{name}}!\n{{!-- Comment --}}'); + const prompt = promptService.getUnresolvedPrompt('comment-second-line'); + expect(prompt?.template).to.equal('Hello, {{name}}!\n{{!-- Comment --}}'); + }); + + it('should treat unclosed comments as regular text', () => { + promptService.storePrompt('comment-unclosed', '{{!-- Unclosed comment'); + const prompt = promptService.getUnresolvedPrompt('comment-unclosed'); + expect(prompt?.template).to.equal('{{!-- Unclosed comment'); + }); + + it('should treat standalone closing delimiters as regular text', () => { + promptService.storePrompt('comment-standalone', '--}} Hello, {{name}}!'); + const prompt = promptService.getUnresolvedPrompt('comment-standalone'); + expect(prompt?.template).to.equal('--}} Hello, {{name}}!'); + }); + + it('should handle nested comments and stop at the first closing tag', () => { + promptService.storePrompt('nested-comment', '{{!-- {{!-- Nested comment --}} --}}text'); + const prompt = promptService.getUnresolvedPrompt('nested-comment'); + expect(prompt?.template).to.equal('--}}text'); + }); + + it('should handle templates with only comments', () => { + promptService.storePrompt('comment-only', '{{!-- Only comments --}}'); + const prompt = promptService.getUnresolvedPrompt('comment-only'); + expect(prompt?.template).to.equal(''); + }); + + it('should handle mixed delimiters on the same line', () => { + promptService.storePrompt('comment-mixed', '{{!-- Unclosed comment --}}'); + const prompt = promptService.getUnresolvedPrompt('comment-mixed'); + expect(prompt?.template).to.equal(''); + }); + + it('should resolve variables after stripping single-line comments', async () => { + promptService.storePrompt('comment-resolve', '{{!-- Comment --}}Hello, {{name}}!'); + const prompt = await promptService.getPrompt('comment-resolve', { name: 'John' }); + expect(prompt?.text).to.equal('Hello, John!'); + }); + + it('should resolve variables in multiline templates with comments', async () => { + promptService.storePrompt('comment-multiline-vars', '{{!--\nMultiline comment\n--}}\nHello, {{name}}!'); + const prompt = await promptService.getPrompt('comment-multiline-vars', { name: 'John' }); + expect(prompt?.text).to.equal('Hello, John!'); + }); + + it('should resolve variables with standalone closing delimiters', async () => { + promptService.storePrompt('comment-standalone-vars', '--}} Hello, {{name}}!'); + const prompt = await promptService.getPrompt('comment-standalone-vars', { name: 'John' }); + expect(prompt?.text).to.equal('--}} Hello, John!'); + }); + + it('should treat unclosed comments as text and resolve variables', async () => { + promptService.storePrompt('comment-unclosed-vars', '{{!-- Unclosed comment\nHello, {{name}}!'); + const prompt = await promptService.getPrompt('comment-unclosed-vars', { name: 'John' }); + expect(prompt?.text).to.equal('{{!-- Unclosed comment\nHello, John!'); + }); + + it('should handle templates with mixed comments and variables', async () => { + promptService.storePrompt('comment-mixed-vars', '{{!-- Comment --}}Hi, {{name}}! {{!-- Another comment --}}'); + const prompt = await promptService.getPrompt('comment-mixed-vars', { name: 'John' }); + expect(prompt?.text).to.equal('Hi, John! {{!-- Another comment --}}'); + }); + }); diff --git a/packages/ai-core/src/common/prompt-service.ts b/packages/ai-core/src/common/prompt-service.ts index 87f029c6bbf02..db86326c8cad5 100644 --- a/packages/ai-core/src/common/prompt-service.ts +++ b/packages/ai-core/src/common/prompt-service.ts @@ -40,10 +40,15 @@ export interface ResolvedPromptTemplate { export const PromptService = Symbol('PromptService'); export interface PromptService { /** - * Retrieve the raw {@link PromptTemplate} object. + * Retrieve the raw {@link PromptTemplate} object (unresolved variables, functions and including comments). * @param id the id of the {@link PromptTemplate} */ getRawPrompt(id: string): PromptTemplate | undefined; + /** + * Retrieve the unresolved {@link PromptTemplate} object (unresolved variables, functions, excluding comments) + * @param id the id of the {@link PromptTemplate} + */ + getUnresolvedPrompt(id: string): PromptTemplate | undefined; /** * Retrieve the default raw {@link PromptTemplate} object. * @param id the id of the {@link PromptTemplate} @@ -182,12 +187,28 @@ export class PromptServiceImpl implements PromptService { return this._prompts[id]; } + getUnresolvedPrompt(id: string): PromptTemplate | undefined { + const rawPrompt = this.getRawPrompt(id); + if (!rawPrompt) { + return undefined; + } + return { + id: rawPrompt.id, + template: this.stripComments(rawPrompt.template) + }; + } + + protected stripComments(template: string): string { + const commentRegex = /^\s*{{!--[\s\S]*?--}}\s*\n?/; + return commentRegex.test(template) ? template.replace(commentRegex, '').trimStart() : template; + } + matchVariables(template: string): RegExpMatchArray[] { return matchVariablesRegEx(template); } async getPrompt(id: string, args?: { [key: string]: unknown }): Promise { - const prompt = this.getRawPrompt(id); + const prompt = this.getUnresolvedPrompt(id); if (prompt === undefined) { return undefined; } From 84e273bfe321c0d3c9db158abab9c2db759992a4 Mon Sep 17 00:00:00 2001 From: Jonas Helming Date: Mon, 18 Nov 2024 00:01:17 +0100 Subject: [PATCH 3/3] Add comment to motivate users to contribute prompts fixed #14471 --- .../prompt-template-contribution.md | 66 +++++++++++++++++++ .../ai-chat/src/common/command-chat-agents.ts | 4 +- .../src/common/orchestrator-chat-agent.ts | 4 +- .../src/common/universal-chat-agent.ts | 4 +- .../src/common/code-completion-agent.ts | 4 +- .../src/browser/ai-terminal-agent.ts | 6 +- .../ai-workspace-agent/src/common/template.ts | 4 +- 7 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 .github/DISCUSSION_TEMPLATE/prompt-template-contribution.md diff --git a/.github/DISCUSSION_TEMPLATE/prompt-template-contribution.md b/.github/DISCUSSION_TEMPLATE/prompt-template-contribution.md new file mode 100644 index 0000000000000..78e1e573cf8c4 --- /dev/null +++ b/.github/DISCUSSION_TEMPLATE/prompt-template-contribution.md @@ -0,0 +1,66 @@ + + +## What Does This Template Do? + +Provide a brief description of the prompt template: +- What problem does it solve? +- What specific functionality does it enhance and how? + +## The Prompt Template + +Paste your prompt template here as plain text. + +## Tested LLMs + +List the language models this template has been tested with, and describe how well it worked: +- LLM Name & Version, e.g., OpenAI GPT-4, LLaMA 3.2, etc. +- Which LLM providers did you use (OpenAI, llama-file, Ollama, etc.) +- Any notable performance observations or challenges? + +## Example User Requests + +Provide some example user requests that were tested with this template: +1. Example Request 1: [What the user inputted] +2. Example Request 2: [Another example] +3. Example Request 3: [And so on...] + +## Suggestions for Improvements (Optional) + +If you’re looking for feedback or collaboration, feel free to add: +- Known limitations or challenges. +- Ideas for improving the template. + +## Related Discussions or Resources (Optional) + +Link to any relevant discussions, documentation, or resources that could help others understand or improve your template. + +## License Agreement + +By submitting this template, you agree to the following: + +1. Your submission is contributed under the [MIT License](https://opensource.org/licenses/MIT). +2. You certify that your contribution complies with the **Developer Certificate of Origin (DCO) Version 1.1**, outlined below: + +--- + +### Developer Certificate of Origin 1.1 + +Copyright (C) 2004, 2006 The Linux Foundation and its contributors. +660 York Street, Suite 102, San Francisco, CA 94110 USA + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +#### Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I have the right to submit it under the open-source license indicated in the file; or +(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open-source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open-source license (unless I am permitted to submit under a different license), as indicated in the file; or +(c) The contribution was provided directly to me by some other person who certified (a), (b), or (c) and I have not modified it. + +(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my signoff) is maintained indefinitely and may be redistributed consistent with this project or the open-source license(s) involved. + +--- + +- [ ] **I agree to contribute this submission under the MIT License and certify compliance with the Developer Certificate of Origin (DCO) Version 1.1.** + diff --git a/packages/ai-chat/src/common/command-chat-agents.ts b/packages/ai-chat/src/common/command-chat-agents.ts index 7ab6608f049de..b6567b9cd7f61 100644 --- a/packages/ai-chat/src/common/command-chat-agents.ts +++ b/packages/ai-chat/src/common/command-chat-agents.ts @@ -36,7 +36,9 @@ import { export const commandTemplate: PromptTemplate = { id: 'command-system', - template: `# System Prompt + template: `{{!-- Have an improved or adapted version of this prompt template? Share it with the community here: +https://github.com/eclipse-theia/theia/discussions/new?category=show-and-tell&template=prompt-template-contribution.md --}} +# System Prompt You are a service that helps users find commands to execute in an IDE. You reply with stringified JSON Objects that tell the user which command to execute and its arguments, if any. diff --git a/packages/ai-chat/src/common/orchestrator-chat-agent.ts b/packages/ai-chat/src/common/orchestrator-chat-agent.ts index 94fdd5a9b88ef..882b8a32caa31 100644 --- a/packages/ai-chat/src/common/orchestrator-chat-agent.ts +++ b/packages/ai-chat/src/common/orchestrator-chat-agent.ts @@ -27,7 +27,9 @@ import { ChatHistoryEntry } from './chat-history-entry'; export const orchestratorTemplate: PromptTemplate = { id: 'orchestrator-system', - template: `# Instructions + template: `{{!-- Have an improved or adapted version of this prompt template? Share it with the community here: +https://github.com/eclipse-theia/theia/discussions/new?category=show-and-tell&template=prompt-template-contribution.md --}} +# Instructions Your task is to identify which Chat Agent(s) should best reply a given user's message. You consider all messages of the conversation to ensure consistency and avoid agent switches without a clear context change. diff --git a/packages/ai-chat/src/common/universal-chat-agent.ts b/packages/ai-chat/src/common/universal-chat-agent.ts index ab8838d7578e6..b24c64023e1bb 100644 --- a/packages/ai-chat/src/common/universal-chat-agent.ts +++ b/packages/ai-chat/src/common/universal-chat-agent.ts @@ -23,7 +23,9 @@ import { AbstractStreamParsingChatAgent, ChatAgent, SystemMessageDescription } f export const universalTemplate: PromptTemplate = { id: 'universal-system', - template: `# Instructions + template: `{{!-- Have an improved or adapted version of this prompt template? Share it with the community here: +https://github.com/eclipse-theia/theia/discussions/new?category=show-and-tell&template=prompt-template-contribution.md --}} +# Instructions You are an AI assistant integrated into the Theia IDE, specifically designed to help software developers by providing concise and accurate answers to programming-related questions. Your role is to enhance the diff --git a/packages/ai-code-completion/src/common/code-completion-agent.ts b/packages/ai-code-completion/src/common/code-completion-agent.ts index 1fa9ceaea384a..0c0aadd03be72 100644 --- a/packages/ai-code-completion/src/common/code-completion-agent.ts +++ b/packages/ai-code-completion/src/common/code-completion-agent.ts @@ -134,7 +134,9 @@ export class CodeCompletionAgentImpl implements CodeCompletionAgent { promptTemplates: PromptTemplate[] = [ { id: 'code-completion-prompt', - template: `You are a code completion agent. The current file you have to complete is named {{file}}. + template: `{{!-- Have an improved or adapted version of this prompt template? Share it with the community here: +https://github.com/eclipse-theia/theia/discussions/new?category=show-and-tell&template=prompt-template-contribution.md --}} +You are a code completion agent. The current file you have to complete is named {{file}}. The language of the file is {{language}}. Return your result as plain text without markdown formatting. Finish the following code snippet. diff --git a/packages/ai-terminal/src/browser/ai-terminal-agent.ts b/packages/ai-terminal/src/browser/ai-terminal-agent.ts index d6fe2accbe8e9..ddd3b4bd2ae7d 100644 --- a/packages/ai-terminal/src/browser/ai-terminal-agent.ts +++ b/packages/ai-terminal/src/browser/ai-terminal-agent.ts @@ -55,7 +55,8 @@ export class AiTerminalAgent implements Agent { id: 'terminal-system', name: 'AI Terminal System Prompt', description: 'Prompt for the AI Terminal Assistant', - template: ` + template: `{{!-- Have an improved or adapted version of this prompt template? Share it with the community here: +https://github.com/eclipse-theia/theia/discussions/new?category=show-and-tell&template=prompt-template-contribution.md --}} # Instructions Generate one or more command suggestions based on the user's request, considering the shell being used, the current working directory, and the recent terminal contents. Provide the best suggestion first, @@ -102,7 +103,8 @@ nothing to commit, working tree clean id: 'terminal-user', name: 'AI Terminal User Prompt', description: 'Prompt that contains the user request', - template: ` + template: `{{!-- Have an improved or adapted version of this prompt template? Share it with the community here: +https://github.com/eclipse-theia/theia/discussions/new?category=show-and-tell&template=prompt-template-contribution.md --}} user-request: {{userRequest}} shell: {{shell}} cwd: {{cwd}} diff --git a/packages/ai-workspace-agent/src/common/template.ts b/packages/ai-workspace-agent/src/common/template.ts index eb03aeea7eb90..afb401d7f12b0 100644 --- a/packages/ai-workspace-agent/src/common/template.ts +++ b/packages/ai-workspace-agent/src/common/template.ts @@ -18,7 +18,9 @@ import { GET_WORKSPACE_FILE_LIST_FUNCTION_ID, FILE_CONTENT_FUNCTION_ID, GET_WORK export const workspaceTemplate = { id: 'workspace-system', - template: `# Instructions + template: `{{!-- Have an improved or adapted version of this prompt template? Share it with the community here: +https://github.com/eclipse-theia/theia/discussions/new?category=show-and-tell&template=prompt-template-contribution.md --}} +# Instructions You are an AI assistant integrated into Theia IDE, designed to assist software developers with concise answers to programming-related questions. Your goal is to enhance productivity with quick, relevant solutions, explanations, and best practices. Keep responses short, delivering valuable insights and direct solutions.