Skip to content

Commit

Permalink
fix: merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
rpidanny committed Nov 3, 2023
2 parents 3b09db9 + 40b1dc1 commit 6f4888d
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 41 deletions.
14 changes: 14 additions & 0 deletions apps/chrome-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [1.8.2](https://github.com/rpidanny/llm-prompt-templates/compare/chrome-extension-v1.8.1...chrome-extension-v1.8.2) (2023-11-02)


### Bug Fixes

* update package.json version on release ([#17](https://github.com/rpidanny/llm-prompt-templates/issues/17)) ([59a829c](https://github.com/rpidanny/llm-prompt-templates/commit/59a829cec1a75a8026938ca7837fa57836e01006))

## [1.8.1](https://github.com/rpidanny/llm-prompt-templates/compare/chrome-extension-v1.8.0...chrome-extension-v1.8.1) (2023-10-30)


### Bug Fixes

* bard text area selector ([#16](https://github.com/rpidanny/llm-prompt-templates/issues/16)) ([1c85d6a](https://github.com/rpidanny/llm-prompt-templates/commit/1c85d6a474b2e0eb3ddd2cfe9e205f79cf14c3ac))

# [1.8.0](https://github.com/rpidanny/llm-prompt-templates/compare/chrome-extension-v1.7.0...chrome-extension-v1.8.0) (2023-05-27)


Expand Down
2 changes: 1 addition & 1 deletion apps/chrome-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "llm-prompt-templates",
"version": "1.8.0",
"version": "1.8.2",
"description": "Get more out of your LLM with the latest advances in prompt engineering",
"type": "commonjs",
"repository": {
Expand Down
6 changes: 6 additions & 0 deletions apps/chrome-extension/release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ module.exports = {
changelogFile: `${srcRoot}/CHANGELOG.md`,
},
],
[
'@rpidanny/semantic-release-update-package.json',
{
packageJsonPath: `${srcRoot}/package.json`,
},
],
[
'@semantic-release/npm',
{
Expand Down
26 changes: 23 additions & 3 deletions apps/chrome-extension/src/pages/Content/base.dom.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IPrompt } from '@rpidanny/llm-prompt-templates';
import { message } from 'antd';
import mixpanel from 'mixpanel-browser';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
Expand All @@ -7,8 +8,6 @@ import { Metrics } from './metrics';
import { groupedPrompts } from './prompts';
import PromptsView from './PromptsView';

mixpanel.init('1eb7876e8cc0adf4a46631b5ba85b4d5');

export abstract class BaseDom {
protected abstract name: string;

Expand All @@ -26,7 +25,10 @@ export abstract class BaseDom {

init() {
console.log(`Initializing ${this.name} DOM`);

mixpanel.init('1eb7876e8cc0adf4a46631b5ba85b4d5');
mixpanel.identify('local');

this.promptsView = this.createPromptsElement();
this.addTriggers();
}
Expand All @@ -39,7 +41,16 @@ export abstract class BaseDom {
});

this.isPromptsViewOpen = false;
this.usePrompt(prompt);
try {
this.usePrompt(prompt);
} catch (error) {
console.error(error);
message.error(
'Failed to use prompt. Copying prompt to clipboard instead.',
5
);
this.copyPromptToClipboard(prompt);
}
this.hidePrompts();
}

Expand All @@ -61,6 +72,15 @@ export abstract class BaseDom {
);
}

protected copyPromptToClipboard(prompt: IPrompt) {
const clipboardItem = new ClipboardItem({
'text/plain': new Blob([prompt.content], { type: 'text/plain' }),
});
navigator.clipboard.write([clipboardItem]);

message.info(`${prompt.name} prompt copied to clipboard`, 7);
}

protected async showPrompts() {
mixpanel.track(Metrics.PromptListShown);

Expand Down
8 changes: 1 addition & 7 deletions apps/chrome-extension/src/pages/Content/generic.dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IPrompt } from '@rpidanny/llm-prompt-templates';
import { message } from 'antd';

import { BaseDom } from './base.dom';

Expand All @@ -10,12 +9,7 @@ export class GenericDom extends BaseDom {
protected addCustomTrigger() {}

protected usePrompt(prompt: IPrompt) {
const clipboardItem = new ClipboardItem({
'text/plain': new Blob([prompt.content], { type: 'text/plain' }),
});
navigator.clipboard.write([clipboardItem]);

message.info(`${prompt.name} prompt copied to clipboard`);
this.copyPromptToClipboard(prompt);
}
}

Expand Down
16 changes: 13 additions & 3 deletions apps/chrome-extension/src/pages/Content/llms/bard/bard.dom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { ChatGPTDom } from '../chatgpt/chatgpt.dom';
import { IPrompt } from '@rpidanny/llm-prompt-templates';

export class BardDom extends ChatGPTDom {
import { LLMDom } from '../llm.dom';

export class BardDom extends LLMDom {
protected name = 'Bard';
protected textAreaSelector = 'div > textarea';
protected textAreaSelector = 'rich-textarea > .ql-editor';

protected usePrompt(prompt: IPrompt) {
const textArea = this.getTextArea();
console.log('Setting text', prompt.content);
textArea.focus();
textArea.textContent = prompt.content;
textArea.style.height = textArea.scrollHeight + 'px';
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
import { IPrompt } from '@rpidanny/llm-prompt-templates';

import { BaseDom } from '../../base.dom';
import { LLMDom } from '../llm.dom';

export class ChatGPTDom extends BaseDom {
export class ChatGPTDom extends LLMDom {
protected name = 'ChatGPT';
protected textAreaSelector = 'div.relative > textarea';

private getTextArea(): HTMLTextAreaElement {
const textArea = document.querySelector<HTMLTextAreaElement>(
this.textAreaSelector
);

if (!textArea) throw new Error('Could not find text area');

return textArea;
}

protected addCustomTrigger() {
this.getTextArea().addEventListener('input', (event) => {
const input = event.target as HTMLTextAreaElement;
const text = input.value;

if (text === '/templates' || text === '/lpt') {
this.showPrompts();
} else if (this.isPromptsViewOpen) {
this.hidePrompts();
}
});
}

protected usePrompt(prompt: IPrompt) {
const textArea = this.getTextArea();
console.log('Setting text', prompt.content);
Expand Down
31 changes: 31 additions & 0 deletions apps/chrome-extension/src/pages/Content/llms/llm.dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { BaseDom } from '../base.dom';

export abstract class LLMDom extends BaseDom {
protected abstract name: string;
protected abstract textAreaSelector: string;

protected getTextArea(): HTMLTextAreaElement {
const textArea = document.querySelector<HTMLTextAreaElement>(
this.textAreaSelector
);

if (!textArea) {
throw new Error('Could not find text area');
}

return textArea;
}

protected addCustomTrigger() {
this.getTextArea().addEventListener('input', (event) => {
const input = event.target as HTMLTextAreaElement;
const text = input.value;

if (text === '/templates' || text === '/lpt') {
this.showPrompts();
} else if (this.isPromptsViewOpen) {
this.hidePrompts();
}
});
}
}
7 changes: 7 additions & 0 deletions libs/llm-prompt-templates/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.3.1](https://github.com/rpidanny/llm-prompt-templates/compare/llm-prompt-templates-v1.3.0...llm-prompt-templates-v1.3.1) (2023-11-02)


### Bug Fixes

* update package.json version on release ([#17](https://github.com/rpidanny/llm-prompt-templates/issues/17)) ([59a829c](https://github.com/rpidanny/llm-prompt-templates/commit/59a829cec1a75a8026938ca7837fa57836e01006))

# [1.3.0](https://github.com/rpidanny/llm-prompt-templates/compare/llm-prompt-templates-v1.2.0...llm-prompt-templates-v1.3.0) (2023-05-27)


Expand Down
4 changes: 2 additions & 2 deletions libs/llm-prompt-templates/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rpidanny/llm-prompt-templates",
"version": "1.0.1",
"version": "1.3.1",
"type": "commonjs",
"exports": {
".": "./src/index.js",
Expand All @@ -17,4 +17,4 @@
"url": "https://github.com/rpidanny/llm-prompt-templates.git",
"directory": "libs/llm-prompt-templates"
}
}
}
6 changes: 6 additions & 0 deletions libs/llm-prompt-templates/release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ module.exports = {
changelogFile: `${srcRoot}/CHANGELOG.md`,
},
],
[
'@rpidanny/semantic-release-update-package.json',
{
packageJsonPath: `${srcRoot}/package.json`,
},
],
[
'@semantic-release/npm',
{
Expand Down
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@nx/workspace": "16.1.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@rpidanny/eslint-config-typescript": "^1.1.0",
"@rpidanny/semantic-release-update-package.json": "^1.0.0",
"@svgr/webpack": "^6.1.2",
"@swc/cli": "~0.1.62",
"@swc/core": "~1.3.51",
Expand Down

0 comments on commit 6f4888d

Please sign in to comment.