Skip to content

Commit 14b610b

Browse files
committed
Merge branch 'feat/ai-prompt-splitter' into chore/all-my-stuffs
# Conflicts: # components.d.ts # src/tools/index.ts
2 parents 32ffd47 + adb0249 commit 14b610b

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@vueuse/router": "^10.0.0",
5555
"bcryptjs": "^2.4.3",
5656
"change-case": "^4.1.2",
57+
"chatgpt-prompt-splitter": "^1.0.5",
5758
"colord": "^2.9.3",
5859
"composerize-ts": "^0.6.2",
5960
"country-code-lookup": "^0.1.0",

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<script setup lang="ts">
2+
import promptSplitter from 'chatgpt-prompt-splitter';
3+
import { useValidation } from '@/composable/validation';
4+
5+
const prompt = ref('');
6+
const splitLength = ref(1024);
7+
8+
const splittedPrompts = computed(() => {
9+
try {
10+
return promptSplitter({
11+
prompt: prompt.value,
12+
splitLength: splitLength.value,
13+
newLine: true,
14+
});
15+
}
16+
catch (e: any) {
17+
return [e.toString()];
18+
}
19+
});
20+
21+
const promptValidation = useValidation({
22+
source: prompt,
23+
rules: [
24+
{
25+
validator: v => v !== '',
26+
message: 'Prompt must not be empty',
27+
},
28+
],
29+
});
30+
</script>
31+
32+
<template>
33+
<div style="max-width: 600px;">
34+
<c-card title="Prompt and options" mb-2>
35+
<c-input-text
36+
v-model:value="prompt"
37+
label="Full Prompt"
38+
multiline
39+
placeholder="Put your full prompt here..."
40+
rows="10"
41+
:validation="promptValidation"
42+
mb-2
43+
/>
44+
<n-form-item label="Character length for each chunk">
45+
<n-input-number v-model:value="splitLength" :min="1" />
46+
</n-form-item>
47+
</c-card>
48+
49+
<c-card title="Splitted prompts">
50+
<div v-for="(splittedPrompt, index) in splittedPrompts" :key="index">
51+
<TextareaCopyable :value="splittedPrompt" />
52+
</div>
53+
</c-card>
54+
</div>
55+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module "chatgpt-prompt-splitter" {
2+
export default function promptSplitter(options: {
3+
prompt: string
4+
splitLength: number
5+
newLine: boolean
6+
}): Array<string>;
7+
}

src/tools/ai-prompt-splitter/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Prompt } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'AI Prompt Splitter',
6+
path: '/ai-prompt-splitter',
7+
description: 'Split a long document to multiple chat (ie ChatGPT) priompts',
8+
keywords: ['ai', 'chatgpt', 'gpt', 'prompt', 'splitter'],
9+
component: () => import('./ai-prompt-splitter.vue'),
10+
icon: Prompt,
11+
createdAt: new Date('2024-07-14'),
12+
});

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { tool as regexTester } from './regex-tester';
1313
import { tool as regexMemo } from './regex-memo';
1414
import { tool as markdownToHtml } from './markdown-to-html';
1515
import { tool as pasteAsMarkdown } from './paste-as-markdown';
16+
import { tool as aiPromptSplitter } from './ai-prompt-splitter';
1617
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
1718
import { tool as numeronymGenerator } from './numeronym-generator';
1819
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -184,6 +185,7 @@ export const toolsByCategory: ToolCategory[] = [
184185
stringObfuscator,
185186
textDiff,
186187
numeronymGenerator,
188+
aiPromptSplitter,
187189
asciiTextDrawer,
188190
pasteAsMarkdown,
189191
],

0 commit comments

Comments
 (0)