Skip to content

Commit

Permalink
feat(new tool): AI Prompt Splitter
Browse files Browse the repository at this point in the history
Fix #1195
  • Loading branch information
sharevb committed Aug 23, 2024
1 parent 80e46c9 commit 63c2daf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
55 changes: 55 additions & 0 deletions src/tools/ai-prompt-splitter/ai-prompt-splitter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<script setup lang="ts">
import promptSplitter from 'chatgpt-prompt-splitter';
import { useValidation } from '@/composable/validation';
const prompt = ref('');
const splitLength = ref(1024);
const splittedPrompts = computed(() => {
try {
return promptSplitter({
prompt: prompt.value,
splitLength: splitLength.value,
newLine: true,
});
}
catch (e: any) {
return [e.toString()];
}
});
const promptValidation = useValidation({
source: prompt,
rules: [
{
validator: v => v !== '',
message: 'Prompt must not be empty',
},
],
});
</script>

<template>
<div style="max-width: 600px;">
<c-card title="Prompt and options" mb-2>
<c-input-text
v-model:value="prompt"
label="Full Prompt"
multiline
placeholder="Put your full prompt here..."
rows="10"
:validation="promptValidation"
mb-2
/>
<n-form-item label="Character length for each chunk">
<n-input-number v-model:value="splitLength" :min="1" />
</n-form-item>
</c-card>

<c-card title="Splitted prompts">
<div v-for="(splittedPrompt, index) in splittedPrompts" :key="index">
<TextareaCopyable :value="splittedPrompt" />
</div>
</c-card>
</div>
</template>
12 changes: 12 additions & 0 deletions src/tools/ai-prompt-splitter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Prompt } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'AI Prompt Splitter',
path: '/ai-prompt-splitter',
description: 'Split a long document to multiple chat (ie ChatGPT) priompts',
keywords: ['ai', 'chatgpt', 'gpt', 'prompt', 'splitter'],
component: () => import('./ai-prompt-splitter.vue'),
icon: Prompt,
createdAt: new Date('2024-07-14'),
});
11 changes: 10 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as aiPromptSplitter } from './ai-prompt-splitter';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
Expand Down Expand Up @@ -155,7 +156,15 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Text',
components: [loremIpsumGenerator, textStatistics, emojiPicker, stringObfuscator, textDiff, numeronymGenerator],
components: [
loremIpsumGenerator,
textStatistics,
emojiPicker,
stringObfuscator,
textDiff,
numeronymGenerator,
aiPromptSplitter,
],
},
{
name: 'Data',
Expand Down

0 comments on commit 63c2daf

Please sign in to comment.