Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new tool): GPT Token Counter #1454

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/tools/gpt-token-estimator/gpt-token-estimator.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test, expect } from '@playwright/test';

Check failure on line 1 in src/tools/gpt-token-estimator/gpt-token-estimator.e2e.spec.ts

View workflow job for this annotation

GitHub Actions / ci

Member 'expect' of the import declaration should be sorted alphabetically

test.describe('Tool - Gpt token estimator', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/gpt-token-estimator');
});

test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('Gpt token estimator - IT Tools');
});

test('', async ({ page }) => {

Check warning on line 12 in src/tools/gpt-token-estimator/gpt-token-estimator.e2e.spec.ts

View workflow job for this annotation

GitHub Actions / ci

'page' is defined but never used. Allowed unused args must match /^_/u

});
});

Check failure on line 15 in src/tools/gpt-token-estimator/gpt-token-estimator.e2e.spec.ts

View workflow job for this annotation

GitHub Actions / ci

Newline required at end of file but not found
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, describe, it } from 'vitest';

Check failure on line 1 in src/tools/gpt-token-estimator/gpt-token-estimator.service.test.ts

View workflow job for this annotation

GitHub Actions / ci

Expected 1 empty line after import statement not followed by another import

Check failure on line 1 in src/tools/gpt-token-estimator/gpt-token-estimator.service.test.ts

View workflow job for this annotation

GitHub Actions / ci

'expect' is defined but never used

Check failure on line 1 in src/tools/gpt-token-estimator/gpt-token-estimator.service.test.ts

View workflow job for this annotation

GitHub Actions / ci

Member 'describe' of the import declaration should be sorted alphabetically

Check failure on line 1 in src/tools/gpt-token-estimator/gpt-token-estimator.service.test.ts

View workflow job for this annotation

GitHub Actions / ci

'describe' is defined but never used

Check failure on line 1 in src/tools/gpt-token-estimator/gpt-token-estimator.service.test.ts

View workflow job for this annotation

GitHub Actions / ci

'it' is defined but never used
// import { } from './gpt-token-estimator.service';
//
// describe('gpt-token-estimator', () => {
//
// })

Check failure on line 6 in src/tools/gpt-token-estimator/gpt-token-estimator.service.test.ts

View workflow job for this annotation

GitHub Actions / ci

Newline required at end of file but not found
Empty file.
42 changes: 42 additions & 0 deletions src/tools/gpt-token-estimator/gpt-token-estimator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script setup lang="ts">
import { GPTTokens } from 'gpt-tokens';
import TextareaCopyable from '@/components/TextareaCopyable.vue';

const inputText = ref('');

Check warning on line 5 in src/tools/gpt-token-estimator/gpt-token-estimator.vue

View workflow job for this annotation

GitHub Actions / ci

'inputText' is assigned a value but never used. Allowed unused vars must match /^_/u
const outputTokenCosts = computed(() => {

Check warning on line 6 in src/tools/gpt-token-estimator/gpt-token-estimator.vue

View workflow job for this annotation

GitHub Actions / ci

'outputTokenCosts' is assigned a value but never used. Allowed unused vars must match /^_/u
try {
const usageInfo = new GPTTokens({
model: 'gpt-3.5-turbo-1106',
messages: [
{ role: 'system', content: 'You are a helpful, pattern-following assistant that translates corporate jargon into plain English.' },
{ role: 'user', content: 'This late pivot means we don\'t have time to boil the ocean for the client deliverable.' },
],
});

console.info('Used tokens: ', usageInfo.usedTokens);

Check failure on line 16 in src/tools/gpt-token-estimator/gpt-token-estimator.vue

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
console.info('Used USD: ', usageInfo.usedUSD);

Check failure on line 17 in src/tools/gpt-token-estimator/gpt-token-estimator.vue

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
}
catch (e: any) {
}
});
</script>

<template>
<div>
<c-input-text
v-model:value="inputHtml"
multiline raw-text
placeholder="Your Html content..."
rows="8"
autofocus
label="Your Html to convert (can paste from clipboard):"
paste-html
/>

<n-divider />

<n-form-item label="Output markdown:">
<TextareaCopyable :value="outputMarkdown" />
</n-form-item>
</div>
</template>
12 changes: 12 additions & 0 deletions src/tools/gpt-token-estimator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CurrencyDollar } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'GPT Token Estimator',
path: '/gpt-token-estimator',
description: 'OpenAI GPT Token Estimator',
keywords: ['gpt', 'token', 'estimator'],
component: () => import('./gpt-token-estimator.vue'),
icon: CurrencyDollar,
createdAt: new Date('2024-08-15'),
});
2 changes: 2 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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 emailNormalizer } from './email-normalizer';
import { tool as gptTokenEstimator } from './gpt-token-estimator';

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

Expand Down Expand Up @@ -160,6 +161,7 @@ export const toolsByCategory: ToolCategory[] = [
emailNormalizer,
regexTester,
regexMemo,
gptTokenEstimator,
],
},
{
Expand Down
Loading