From d7e216d017b178e61192dc927474b582230ec89c Mon Sep 17 00:00:00 2001 From: rpidanny Date: Wed, 10 May 2023 23:10:34 +0200 Subject: [PATCH] feat: add prompt category selection --- package-lock.json | 83 ++++++++ package.json | 5 +- packages/chrome-extension/.eslintrc.json | 3 + packages/chrome-extension/project.json | 5 +- .../src/components/EnabledPrompts/index.tsx | 96 +++++++++ .../src/components/PromptTemplates/index.tsx | 188 +++++++++++------- packages/chrome-extension/src/manifest.json | 9 +- .../src/{ => pages/Content}/base.dom.tsx | 16 +- .../{ => pages/Content}/llms/bard/.gitkeep | 0 .../{ => pages/Content}/llms/bing/.gitkeep | 0 .../llms/chatgpt/chatgpt.content.styles.css | 0 .../Content}/llms/chatgpt/chatgpt.dom.ts | 0 .../{ => pages/Content}/llms/chatgpt/index.ts | 0 .../src/pages/Content/templates.ts | 54 +++++ .../src/pages/Popup/Popup.css | 0 .../src/pages/Popup/Popup.tsx | 54 +++++ .../src/pages/Popup/index.css | 17 ++ .../src/pages/Popup/index.html | 12 ++ .../src/pages/Popup/index.tsx | 11 + packages/chrome-extension/src/styles.css | 9 - packages/chrome-extension/src/templates.ts | 34 ---- packages/chrome-extension/webpack.config.js | 18 +- .../src/core/categories.enum.ts | 4 + .../llm-prompt-templates/src/core/code.ts | 6 + .../llm-prompt-templates/src/core/index.ts | 2 + .../src/core/interfaces.ts | 1 + .../src/core/pal/algorithmic.ts | 3 + .../llm-prompt-templates/src/core/question.ts | 6 + 28 files changed, 504 insertions(+), 132 deletions(-) create mode 100644 packages/chrome-extension/src/components/EnabledPrompts/index.tsx rename packages/chrome-extension/src/{ => pages/Content}/base.dom.tsx (88%) rename packages/chrome-extension/src/{ => pages/Content}/llms/bard/.gitkeep (100%) rename packages/chrome-extension/src/{ => pages/Content}/llms/bing/.gitkeep (100%) rename packages/chrome-extension/src/{ => pages/Content}/llms/chatgpt/chatgpt.content.styles.css (100%) rename packages/chrome-extension/src/{ => pages/Content}/llms/chatgpt/chatgpt.dom.ts (100%) rename packages/chrome-extension/src/{ => pages/Content}/llms/chatgpt/index.ts (100%) create mode 100644 packages/chrome-extension/src/pages/Content/templates.ts create mode 100644 packages/chrome-extension/src/pages/Popup/Popup.css create mode 100644 packages/chrome-extension/src/pages/Popup/Popup.tsx create mode 100644 packages/chrome-extension/src/pages/Popup/index.css create mode 100644 packages/chrome-extension/src/pages/Popup/index.html create mode 100644 packages/chrome-extension/src/pages/Popup/index.tsx delete mode 100644 packages/chrome-extension/src/styles.css delete mode 100644 packages/chrome-extension/src/templates.ts create mode 100644 packages/llm-prompt-templates/src/core/categories.enum.ts diff --git a/package-lock.json b/package-lock.json index a2df16b..8107660 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "@swc/cli": "~0.1.62", "@swc/core": "~1.3.51", "@testing-library/react": "14.0.0", + "@types/chrome": "^0.0.235", "@types/jest": "^29.4.0", "@types/node": "18.14.2", "@types/react": "18.0.28", @@ -55,6 +56,7 @@ "eslint-plugin-react": "7.32.2", "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-simple-import-sort": "^10.0.0", + "html-loader": "^4.2.0", "html-webpack-plugin": "^5.5.1", "husky": "^8.0.3", "jest": "^29.4.1", @@ -5787,6 +5789,16 @@ "@types/responselike": "^1.0.0" } }, + "node_modules/@types/chrome": { + "version": "0.0.235", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.235.tgz", + "integrity": "sha512-SPj9A4E35SBJICjnL04KZEA/eVr8Km7gbnEfAxzaU2fHpLSnN64OPnfOR3EpDJXXpSORKTn3OUDwugw+rYBBXA==", + "dev": true, + "dependencies": { + "@types/filesystem": "*", + "@types/har-format": "*" + } + }, "node_modules/@types/connect": { "version": "3.4.35", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", @@ -5856,6 +5868,21 @@ "@types/send": "*" } }, + "node_modules/@types/filesystem": { + "version": "0.0.32", + "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.32.tgz", + "integrity": "sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==", + "dev": true, + "dependencies": { + "@types/filewriter": "*" + } + }, + "node_modules/@types/filewriter": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.29.tgz", + "integrity": "sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==", + "dev": true + }, "node_modules/@types/glob": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz", @@ -5875,6 +5902,12 @@ "@types/node": "*" } }, + "node_modules/@types/har-format": { + "version": "1.2.10", + "resolved": "https://registry.npmjs.org/@types/har-format/-/har-format-1.2.10.tgz", + "integrity": "sha512-o0J30wqycjF5miWDKYKKzzOU1ZTLuA42HZ4HE7/zqTOc/jTLdQ5NhYWvsRQo45Nfi1KHoRdNhteSI4BAxTF1Pg==", + "dev": true + }, "node_modules/@types/html-minifier-terser": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@types/html-minifier-terser/-/html-minifier-terser-6.1.0.tgz", @@ -12606,6 +12639,56 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "node_modules/html-loader": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/html-loader/-/html-loader-4.2.0.tgz", + "integrity": "sha512-OxCHD3yt+qwqng2vvcaPApCEvbx+nXWu+v69TYHx1FO8bffHn/JjHtE3TTQZmHjwvnJe4xxzuecetDVBrQR1Zg==", + "dev": true, + "dependencies": { + "html-minifier-terser": "^7.0.0", + "parse5": "^7.0.0" + }, + "engines": { + "node": ">= 14.15.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.0.0" + } + }, + "node_modules/html-loader/node_modules/commander": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", + "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", + "dev": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/html-loader/node_modules/html-minifier-terser": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/html-minifier-terser/-/html-minifier-terser-7.2.0.tgz", + "integrity": "sha512-tXgn3QfqPIpGl9o+K5tpcj3/MN4SfLtsx2GWwBC3SSd0tXQGyF3gsSqad8loJgKZGM3ZxbYDd5yhiBIdWpmvLA==", + "dev": true, + "dependencies": { + "camel-case": "^4.1.2", + "clean-css": "~5.3.2", + "commander": "^10.0.0", + "entities": "^4.4.0", + "param-case": "^3.0.4", + "relateurl": "^0.2.7", + "terser": "^5.15.1" + }, + "bin": { + "html-minifier-terser": "cli.js" + }, + "engines": { + "node": "^14.13.1 || >=16.0.0" + } + }, "node_modules/html-minifier-terser": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/html-minifier-terser/-/html-minifier-terser-6.1.0.tgz", diff --git a/package.json b/package.json index 0963852..4ec3cf7 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "0.0.0", "license": "MIT", "scripts": { - "build": "nx run-many --target=build --all", + "build": "nx run-many --target=build --parallel=3", + "build:watch": "nx watch --all -- nx run-many --target=build --parallel=3", "test": "nx run-many --target=test --all", "lint": "nx run-many --target=lint --all", "format:check": "nx format:check --all", @@ -38,6 +39,7 @@ "@swc/cli": "~0.1.62", "@swc/core": "~1.3.51", "@testing-library/react": "14.0.0", + "@types/chrome": "^0.0.235", "@types/jest": "^29.4.0", "@types/node": "18.14.2", "@types/react": "18.0.28", @@ -57,6 +59,7 @@ "eslint-plugin-react": "7.32.2", "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-simple-import-sort": "^10.0.0", + "html-loader": "^4.2.0", "html-webpack-plugin": "^5.5.1", "husky": "^8.0.3", "jest": "^29.4.1", diff --git a/packages/chrome-extension/.eslintrc.json b/packages/chrome-extension/.eslintrc.json index 9d9c0db..39814ac 100644 --- a/packages/chrome-extension/.eslintrc.json +++ b/packages/chrome-extension/.eslintrc.json @@ -1,6 +1,9 @@ { "extends": ["../../.eslintrc.json"], "ignorePatterns": ["!**/*"], + "globals": { + "chrome": "readonly" + }, "overrides": [ { "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], diff --git a/packages/chrome-extension/project.json b/packages/chrome-extension/project.json index 13066c5..8f5f8d3 100644 --- a/packages/chrome-extension/project.json +++ b/packages/chrome-extension/project.json @@ -14,10 +14,7 @@ "baseHref": "/", "main": "packages/chrome-extension/src/index.ts", "tsConfig": "packages/chrome-extension/tsconfig.app.json", - "assets": [ - "packages/chrome-extension/src/assets", - "packages/chrome-extension/src/styles.css" - ], + "assets": ["packages/chrome-extension/src/assets"], "scripts": [], "isolatedConfig": true, "webpackConfig": "packages/chrome-extension/webpack.config.js" diff --git a/packages/chrome-extension/src/components/EnabledPrompts/index.tsx b/packages/chrome-extension/src/components/EnabledPrompts/index.tsx new file mode 100644 index 0000000..a89831f --- /dev/null +++ b/packages/chrome-extension/src/components/EnabledPrompts/index.tsx @@ -0,0 +1,96 @@ +/// +import { Select, Space, Tag } from 'antd'; +import type { CustomTagProps } from 'rc-select/lib/BaseSelect'; +import React, { useEffect, useState } from 'react'; + +const { Option } = Select; + +interface PromptCategory { + name: string; + emoji: string; +} + +interface SelectPromptCategoriesProps { + promptCategories: PromptCategory[]; +} + +const colorOptions: Record = { + General: 'gold', + Code: 'cyan', +}; + +function SelectPromptCategories({ + promptCategories, +}: SelectPromptCategoriesProps) { + const localStorageKey = 'enabledPromptCategories'; + + const [enabledPromptCategories, setEnabledPromptCategories] = useState< + string[] + >([]); + + useEffect(() => { + chrome.storage.local.get( + [localStorageKey], + (result: { [x: string]: string }) => { + if (result[localStorageKey]) { + setEnabledPromptCategories(result[localStorageKey].split(',')); + } + } + ); + }, []); + + const handleChange = async (values: string[]) => { + setEnabledPromptCategories(values); + await chrome.storage.local.set({ [localStorageKey]: values.join(',') }); + }; + + const tagRender = (props: CustomTagProps) => { + const { label, value, closable, onClose } = props; + + console.log(props); + + const onPreventMouseDown = (event: React.MouseEvent) => { + event.preventDefault(); + event.stopPropagation(); + }; + return ( + + {label} + + ); + }; + + return ( + + ); +} + +export default SelectPromptCategories; diff --git a/packages/chrome-extension/src/components/PromptTemplates/index.tsx b/packages/chrome-extension/src/components/PromptTemplates/index.tsx index fc95eb1..4fd4a4f 100644 --- a/packages/chrome-extension/src/components/PromptTemplates/index.tsx +++ b/packages/chrome-extension/src/components/PromptTemplates/index.tsx @@ -1,90 +1,132 @@ +/// + import './styles.css'; -import { IPromptTemplate } from '@rpidanny/llm-prompt-templates'; -import { List, Modal, Tag } from 'antd'; -import React, { Component } from 'react'; +import { + IPromptTemplate, + PromptTemplateCategory, +} from '@rpidanny/llm-prompt-templates'; +import { List, Modal, Tag, Typography } from 'antd'; +import React, { useEffect, useState } from 'react'; + +import { + IPromptCategories, + IPromptCategory, +} from '../../pages/Content/templates'; + +const { Text } = Typography; type Props = { visible: boolean; - templates: IPromptTemplate[]; + promptCategories: IPromptCategories; onCancel: () => void; onItemSelected: (template: IPromptTemplate) => void; }; -type State = object; +const PromptTemplates: React.FC = ({ + visible, + promptCategories, + onCancel, + onItemSelected, +}) => { + const localStorageKey = 'enabledPromptCategories'; -class PromptTemplates extends Component { - render() { - const { templates, visible, onCancel } = this.props; + const [enabledCategories, setEnabledCategories] = useState([]); - return ( - - LLM Prompt Templates - + useEffect(() => { + chrome.storage.local.get( + [localStorageKey], + (result: { [x: string]: string }) => { + if (result[localStorageKey]) { + setEnabledCategories(result[localStorageKey].split(',')); + } else { + setEnabledCategories(Object.keys(PromptTemplateCategory)); } - centered - open={visible} - onCancel={onCancel} - okButtonProps={{ disabled: true }} - cancelButtonProps={{ disabled: true }} - width={'70%'} - footer={null} - > -
- ( - e.stopPropagation()} - > - Paper - , - ] - : [] - } - extra={ -
- {item.tags?.map((tag) => ( - - {tag} - - ))} -
- } - onClick={() => this.handleItemClick(idx)} - className={'template-list-item'} - > - -
- )} - /> -
-
+ } ); - } + }, [visible]); - private handleItemClick(index: number) { - const { onItemSelected, templates } = this.props; + const handleItemClick = (group: PromptTemplateCategory, index: number) => { + onItemSelected(promptCategories[group].prompts[index]); + }; - onItemSelected(templates[index]); - } -} + return ( + + LLM Prompt Templates + + } + centered + open={visible} + onCancel={onCancel} + okButtonProps={{ disabled: true }} + cancelButtonProps={{ disabled: true }} + width={'80%'} + footer={null} + > +
+ {( + Object.entries(promptCategories) as [ + PromptTemplateCategory, + IPromptCategory + ][] + ) + .filter(([categoryName]) => enabledCategories.includes(categoryName)) + .map(([categoryName, category]) => ( + + {category.emoji} {categoryName} + + } + bordered + dataSource={category.prompts} + style={{ marginBottom: '1rem' }} + renderItem={(item, idx) => ( + e.stopPropagation()} + > + Paper + , + ] + : [] + } + extra={ +
+ {item.tags?.map((tag) => ( + + {tag} + + ))} +
+ } + onClick={() => + handleItemClick(categoryName as PromptTemplateCategory, idx) + } + className={'template-list-item'} + > + +
+ )} + /> + ))} +
+
+ ); +}; export default PromptTemplates; diff --git a/packages/chrome-extension/src/manifest.json b/packages/chrome-extension/src/manifest.json index 762aebe..caa4d43 100755 --- a/packages/chrome-extension/src/manifest.json +++ b/packages/chrome-extension/src/manifest.json @@ -6,11 +6,15 @@ "128": "assets/img/icon-128.png", "256": "assets/img/icon-256.png" }, + "action": { + "default_popup": "popup.html", + "default_icon": "assets/img/icon-256.png" + }, "content_scripts": [ { "matches": ["https://chat.openai.com/*"], "js": ["chatGPTContentScript.bundle.js"], - "css": ["chatgpt.content.styles.css", "styles.css"], + "css": ["chatgpt.content.styles.css"], "run_at": "document_end" } ], @@ -27,5 +31,6 @@ "resources": ["chatgpt.content.styles.css"], "matches": ["https://chat.openai.com/*"] } - ] + ], + "permissions": ["storage"] } diff --git a/packages/chrome-extension/src/base.dom.tsx b/packages/chrome-extension/src/pages/Content/base.dom.tsx similarity index 88% rename from packages/chrome-extension/src/base.dom.tsx rename to packages/chrome-extension/src/pages/Content/base.dom.tsx index 76897b9..6881000 100644 --- a/packages/chrome-extension/src/base.dom.tsx +++ b/packages/chrome-extension/src/pages/Content/base.dom.tsx @@ -2,8 +2,8 @@ import { IPromptTemplate } from '@rpidanny/llm-prompt-templates'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; -import PromptTemplates from './components/PromptTemplates'; -import { promptTemplates } from './templates'; +import PromptTemplates from '../../components/PromptTemplates'; +import { promptCategories } from './templates'; export abstract class BaseDom { protected abstract name: string; @@ -48,10 +48,10 @@ export abstract class BaseDom { return templatesView; } - private render() { + private async render() { ReactDOM.render( + + LLM Prompt Templates + + + Enabled Prompts + ({ + name, + emoji: category.emoji, + }) + )} + /> + Hint +
+ Ctrl + Shift + P or typing /templates opens + prompt templates page. +
+
+ + ); +} + +export default Popup; diff --git a/packages/chrome-extension/src/pages/Popup/index.css b/packages/chrome-extension/src/pages/Popup/index.css new file mode 100644 index 0000000..e02f72e --- /dev/null +++ b/packages/chrome-extension/src/pages/Popup/index.css @@ -0,0 +1,17 @@ +body { + width: 350px; + height: 300px; + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + + position: relative; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/packages/chrome-extension/src/pages/Popup/index.html b/packages/chrome-extension/src/pages/Popup/index.html new file mode 100644 index 0000000..c322cec --- /dev/null +++ b/packages/chrome-extension/src/pages/Popup/index.html @@ -0,0 +1,12 @@ + + + + + + Popup + + + +
+ + diff --git a/packages/chrome-extension/src/pages/Popup/index.tsx b/packages/chrome-extension/src/pages/Popup/index.tsx new file mode 100644 index 0000000..2a70471 --- /dev/null +++ b/packages/chrome-extension/src/pages/Popup/index.tsx @@ -0,0 +1,11 @@ +import './index.css'; + +import React from 'react'; +import { createRoot } from 'react-dom/client'; + +import Popup from './Popup'; + +const container = document.getElementById('app-container'); +// eslint-disable-next-line @typescript-eslint/no-non-null-assertion +const root = createRoot(container!); +root.render(); diff --git a/packages/chrome-extension/src/styles.css b/packages/chrome-extension/src/styles.css deleted file mode 100644 index f48a9d8..0000000 --- a/packages/chrome-extension/src/styles.css +++ /dev/null @@ -1,9 +0,0 @@ -/* .templates-list { - margin: 5px; - padding: 5px; -} - -.templates-list div div { - font-size: 0.8rem; - padding: 2px; -} */ diff --git a/packages/chrome-extension/src/templates.ts b/packages/chrome-extension/src/templates.ts deleted file mode 100644 index c6090a9..0000000 --- a/packages/chrome-extension/src/templates.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { - CodeErrorHelp, - GeneralKnowledge, - IPromptTemplate, - OptimizeCode, - OptimizeCodeWithExplanation, - QuestionWithContext, - QuestionWithReasoning, - SQLQuery, - WriteTests, - ZeroShotCoT, - ZeroShotCoTAPE, -} from '@rpidanny/llm-prompt-templates'; - -export const GeneralPrompts: IPromptTemplate[] = [ - QuestionWithReasoning, - QuestionWithContext, - ZeroShotCoT, - ZeroShotCoTAPE, - GeneralKnowledge, -]; - -export const CodePrompts: IPromptTemplate[] = [ - WriteTests, - OptimizeCode, - OptimizeCodeWithExplanation, - CodeErrorHelp, - SQLQuery, -]; - -export const promptTemplates: IPromptTemplate[] = [ - ...GeneralPrompts, - ...CodePrompts, -]; diff --git a/packages/chrome-extension/webpack.config.js b/packages/chrome-extension/webpack.config.js index 0f2156a..ac70c86 100644 --- a/packages/chrome-extension/webpack.config.js +++ b/packages/chrome-extension/webpack.config.js @@ -7,6 +7,7 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const ReactRefreshTypeScript = require('react-refresh-typescript'); const TerserPlugin = require('terser-webpack-plugin'); const ZipPlugin = require('zip-webpack-plugin'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); const isDevelopment = process.env.NODE_ENV !== 'production'; @@ -37,10 +38,13 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { chatgptContentScript: path.join( config.context, 'src', + 'pages', + 'Content', 'llms', 'chatgpt', 'index.ts' ), + popup: path.join(config.context, 'src', 'pages', 'Popup', 'index.tsx'), }, output: { filename: '[name].bundle.js', @@ -162,12 +166,24 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { new CopyWebpackPlugin({ patterns: [ { - from: 'src/llms/chatgpt/chatgpt.content.styles.css', + from: 'src/pages/Content/llms/chatgpt/chatgpt.content.styles.css', to: path.join(config.output.path), force: true, }, ], }), + new HtmlWebpackPlugin({ + template: path.join( + config.context, + 'src', + 'pages', + 'Popup', + 'index.html' + ), + filename: 'popup.html', + chunks: ['popup'], + cache: false, + }), new ZipPlugin({ filename: `${process.env.npm_package_name}-chrome-extension.zip`, path: path.join(config.output.path, '../', 'zip'), diff --git a/packages/llm-prompt-templates/src/core/categories.enum.ts b/packages/llm-prompt-templates/src/core/categories.enum.ts new file mode 100644 index 0000000..aec4cc8 --- /dev/null +++ b/packages/llm-prompt-templates/src/core/categories.enum.ts @@ -0,0 +1,4 @@ +export enum PromptTemplateCategory { + General = 'General', + Code = 'Code', +} diff --git a/packages/llm-prompt-templates/src/core/code.ts b/packages/llm-prompt-templates/src/core/code.ts index fc250c9..5771f44 100644 --- a/packages/llm-prompt-templates/src/core/code.ts +++ b/packages/llm-prompt-templates/src/core/code.ts @@ -1,8 +1,10 @@ +import { PromptTemplateCategory } from './categories.enum'; import { IPromptTemplate } from './interfaces'; import { Tag } from './tags.enum'; export const WriteTests: IPromptTemplate = { name: 'Write Tests', + category: PromptTemplateCategory.Code, description: 'Instructs the LLM to write tests for a given piece of code.', tags: [Tag.Code, Tag.Test], content: `### Instruction ### @@ -16,6 +18,7 @@ Write tests for the following code: export const OptimizeCode: IPromptTemplate = { name: 'Optimize Code', + category: PromptTemplateCategory.Code, description: 'Instructs the LLM to optimize a given piece of code.', tags: [Tag.Code, Tag.Optimization], content: `### Instruction ### @@ -31,6 +34,7 @@ Only return the rewritten code and nothing else. export const OptimizeCodeWithExplanation: IPromptTemplate = { name: 'Optimize Code with Explanation', + category: PromptTemplateCategory.Code, description: 'Instructs the LLM to optimize a given piece of code along with explanation.', tags: [Tag.Code, Tag.Optimization], @@ -47,6 +51,7 @@ Also explain the changes you made to the code. export const CodeErrorHelp: IPromptTemplate = { name: 'Code Error Help', + category: PromptTemplateCategory.Code, description: 'Asks the LLM to help fix a given piece of code.', tags: [Tag.Code, Tag.Error, Tag.Debugging], content: `I am getting this error in my code. Can you please help me? @@ -59,6 +64,7 @@ export const CodeErrorHelp: IPromptTemplate = { export const SQLQuery: IPromptTemplate = { name: 'SQL Query', + category: PromptTemplateCategory.Code, description: 'Asks the LLM to write a SQL query for a given problem', tags: [Tag.Code, Tag.SQL], content: `### Instruction ### diff --git a/packages/llm-prompt-templates/src/core/index.ts b/packages/llm-prompt-templates/src/core/index.ts index 08cae78..1576de1 100644 --- a/packages/llm-prompt-templates/src/core/index.ts +++ b/packages/llm-prompt-templates/src/core/index.ts @@ -1,4 +1,6 @@ +export * from './categories.enum'; export * from './code'; export * from './interfaces'; export * from './pal'; export * from './question'; +export * from './tags.enum'; diff --git a/packages/llm-prompt-templates/src/core/interfaces.ts b/packages/llm-prompt-templates/src/core/interfaces.ts index 3750ffc..66f0274 100644 --- a/packages/llm-prompt-templates/src/core/interfaces.ts +++ b/packages/llm-prompt-templates/src/core/interfaces.ts @@ -2,6 +2,7 @@ export interface IPromptTemplate { name: string; content: string; description: string; + category: string; tags?: string[]; paper?: string; } diff --git a/packages/llm-prompt-templates/src/core/pal/algorithmic.ts b/packages/llm-prompt-templates/src/core/pal/algorithmic.ts index 01d1b9c..8936860 100644 --- a/packages/llm-prompt-templates/src/core/pal/algorithmic.ts +++ b/packages/llm-prompt-templates/src/core/pal/algorithmic.ts @@ -1,7 +1,9 @@ +import { PromptTemplateCategory } from '../categories.enum'; import { IPromptTemplate } from '../interfaces'; export const RepeatCopyPrompt: IPromptTemplate = { name: 'Repeat Copy', + category: PromptTemplateCategory.Code, description: 'Instructs the LLM to repeat a given sequence.', tags: ['sequence', 'copy', 'algorithmic', 'pal'], paper: 'https://arxiv.org/abs/2211.10435', @@ -74,6 +76,7 @@ Q: {question} export const ObjectCountingPrompt: IPromptTemplate = { name: 'Object Counting', + category: PromptTemplateCategory.Code, description: 'Instructs the LLM to count the number of objects in a given sequence.', tags: ['counting', 'algorithmic', 'pal'], diff --git a/packages/llm-prompt-templates/src/core/question.ts b/packages/llm-prompt-templates/src/core/question.ts index 01dc254..fc6322b 100644 --- a/packages/llm-prompt-templates/src/core/question.ts +++ b/packages/llm-prompt-templates/src/core/question.ts @@ -1,3 +1,4 @@ +import { PromptTemplateCategory } from './categories.enum'; import { IPromptTemplate } from './interfaces'; import { Tag } from './tags.enum'; @@ -5,6 +6,7 @@ export const QuestionWithReasoning: IPromptTemplate = { name: 'Question with Reasoning', description: `This prompt guides critical thinking by instructing the LLM to provide it's initial thoughts, critique them, and provide a final answer.`, tags: [Tag.Question, Tag.Reasoning], + category: PromptTemplateCategory.General, content: `{question} Reply in the following pattern: @@ -17,6 +19,7 @@ export const QuestionWithContext: IPromptTemplate = { name: 'Question with Context', description: `This prompt asks the LLM to answer a question based on a provided context.`, tags: [Tag.Question, Tag.Context], + category: PromptTemplateCategory.General, content: `Answer the question based on the context below. Keep the answer short. Respond "Unsure about answer" if not sure about the answer. Context: {context} @@ -31,6 +34,7 @@ export const ZeroShotCoT: IPromptTemplate = { name: 'Zero-Shot CoT', description: `Chain-of-thought (CoT) prompting enables complex reasoning capabilities through intermediate reasoning steps. Useful for more complex arithmetic, commonsense, and symbolic reasoning tasks.`, tags: [Tag.ChainOfThought, Tag.Reasoning], + category: PromptTemplateCategory.General, paper: 'https://arxiv.org/abs/2205.11916', content: `{question} @@ -42,6 +46,7 @@ export const ZeroShotCoTAPE: IPromptTemplate = { name: 'Zero-Shot CoT (APE)', description: `Chain-of-thought (CoT) prompt discovered by automatic prompt engineer (APE) which is better than the human engineered zero-shot CoT prompt.`, tags: [Tag.ChainOfThought, Tag.Reasoning, Tag.AutomaticPromptEngineer], + category: PromptTemplateCategory.General, paper: 'https://arxiv.org/abs/2211.01910', content: `{question} @@ -53,6 +58,7 @@ export const GeneralKnowledge: IPromptTemplate = { name: 'General Knowledge', description: `Incorporates general knowledge or information to help the model make more accurate common sense reasoning.`, tags: [Tag.GeneralKnowledge, Tag.Reasoning], + category: PromptTemplateCategory.General, paper: 'https://arxiv.org/abs/2110.08387', content: `Input: Greece is larger than mexico. Knowledge: Greece is approximately 131,957 sq km, while Mexico is approximately 1,964,375 sq km, making Mexico 1,389% larger than Greece.