Skip to content

Commit 6e736cb

Browse files
committed
feat(new tool): GPT Token Counter
Fix #1334
1 parent 08d977b commit 6e736cb

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Tool - Gpt token estimator', () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/gpt-token-estimator');
6+
});
7+
8+
test('Has correct title', async ({ page }) => {
9+
await expect(page).toHaveTitle('Gpt token estimator - IT Tools');
10+
});
11+
12+
test('', async ({ page }) => {
13+
14+
});
15+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect, describe, it } from 'vitest';
2+
// import { } from './gpt-token-estimator.service';
3+
//
4+
// describe('gpt-token-estimator', () => {
5+
//
6+
// })

src/tools/gpt-token-estimator/gpt-token-estimator.service.ts

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<script setup lang="ts">
2+
import { GPTTokens } from 'gpt-tokens';
3+
import TextareaCopyable from '@/components/TextareaCopyable.vue';
4+
5+
const inputText = ref('');
6+
const outputTokenCosts = computed(() => {
7+
try {
8+
const usageInfo = new GPTTokens({
9+
model: 'gpt-3.5-turbo-1106',
10+
messages: [
11+
{ role: 'system', content: 'You are a helpful, pattern-following assistant that translates corporate jargon into plain English.' },
12+
{ role: 'user', content: 'This late pivot means we don\'t have time to boil the ocean for the client deliverable.' },
13+
],
14+
});
15+
16+
console.info('Used tokens: ', usageInfo.usedTokens);
17+
console.info('Used USD: ', usageInfo.usedUSD);
18+
}
19+
catch (e: any) {
20+
}
21+
});
22+
</script>
23+
24+
<template>
25+
<div>
26+
<c-input-text
27+
v-model:value="inputHtml"
28+
multiline raw-text
29+
placeholder="Your Html content..."
30+
rows="8"
31+
autofocus
32+
label="Your Html to convert (can paste from clipboard):"
33+
paste-html
34+
/>
35+
36+
<n-divider />
37+
38+
<n-form-item label="Output markdown:">
39+
<TextareaCopyable :value="outputMarkdown" />
40+
</n-form-item>
41+
</div>
42+
</template>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { CurrencyDollar } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'GPT Token Estimator',
6+
path: '/gpt-token-estimator',
7+
description: 'OpenAI GPT Token Estimator',
8+
keywords: ['gpt', 'token', 'estimator'],
9+
component: () => import('./gpt-token-estimator.vue'),
10+
icon: CurrencyDollar,
11+
createdAt: new Date('2024-08-15'),
12+
});

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
22
import { tool as base64StringConverter } from './base64-string-converter';
33
import { tool as basicAuthGenerator } from './basic-auth-generator';
44
import { tool as emailNormalizer } from './email-normalizer';
5+
import { tool as gptTokenEstimator } from './gpt-token-estimator';
56

67
import { tool as asciiTextDrawer } from './ascii-text-drawer';
78

@@ -160,6 +161,7 @@ export const toolsByCategory: ToolCategory[] = [
160161
emailNormalizer,
161162
regexTester,
162163
regexMemo,
164+
gptTokenEstimator,
163165
],
164166
},
165167
{

0 commit comments

Comments
 (0)