Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motivate users to contributes prompt templates #14472

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/DISCUSSION_TEMPLATE/prompt-template-contribution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!-- Suggested Title: Prompt Template for [Agent Name]: [Describe Functionality] -->

## 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.**

4 changes: 3 additions & 1 deletion packages/ai-chat/src/common/command-chat-agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion packages/ai-chat/src/common/orchestrator-chat-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion packages/ai-chat/src/common/universal-chat-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
67 changes: 61 additions & 6 deletions packages/ai-core/data/prompttemplate.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,72 @@
"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": "comment.block.prompttemplate",
"begin": "^[\\t ]*{{!--",
"beginCaptures": {
"0": {
"name": "punctuation.definition.brace.begin"
"name": "punctuation.definition.comment.begin"
}
},
"end": "}}",
"end": "--}}",
"endCaptures": {
"0": {
"name": "punctuation.definition.brace.end"
"name": "punctuation.definition.comment.end"
}
},
"patterns": []
},
{
"name": "variable.other.prompttemplate.double",
"begin": "\\{\\{",
"beginCaptures": {
"0": {
"name": "punctuation.definition.variable.begin"
}
},
"end": "\\}\\}(?!\\})",
"endCaptures": {
"0": {
"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": [
Expand Down Expand Up @@ -49,4 +104,4 @@
"fileTypes": [
".prompttemplate"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
AIVariableService,
LanguageModel,
LanguageModelRegistry,
matchVariablesRegEx,
PROMPT_FUNCTION_REGEX,
PROMPT_VARIABLE_REGEX,
PromptCustomizationService,
PromptService,
} from '../../common';
Expand Down Expand Up @@ -180,9 +180,9 @@ 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 = [...prompt.matchAll(PROMPT_VARIABLE_REGEX)];
const variableMatches = matchVariablesRegEx(prompt);

variableMatches.forEach(match => {
const variableId = match[1];
Expand Down
10 changes: 8 additions & 2 deletions packages/ai-core/src/common/prompt-service-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(?<!\{)\{\{\s*([^{}]+?)\s*\}\}(?!\})/g;
export const PROMPT_VARIABLE_THREE_BRACES_REGEX = /(?<!\{)\{\{\{\s*([^{}]+?)\s*\}\}\}(?!\})/g;
export function matchVariablesRegEx(template: string): RegExpMatchArray[] {
const twoBraceMatches = [...template.matchAll(PROMPT_VARIABLE_TWO_BRACES_REGEX)];
const threeBraceMatches = [...template.matchAll(PROMPT_VARIABLE_THREE_BRACES_REGEX)];
return twoBraceMatches.concat(threeBraceMatches);
}

/** Match function/tool references in the prompt. The format is `~{functionId}`. */
export const PROMPT_FUNCTION_REGEX = /\~\{\s*(.*?)\s*\}/g;
Loading
Loading