mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-21 05:24:06 +03:00
1 parent
f1adc66c27
commit
a8a2a0d3f0
6 files changed
+209
No files matched your search
Vendored
+1
@@ -257,6 +257,7 @@ declare module '@vue/runtime-core' {
|
|||||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||||
NMenu: typeof import('naive-ui')['NMenu']
|
NMenu: typeof import('naive-ui')['NMenu']
|
||||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||||
|
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||||
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
||||||
Option43Generator: typeof import('./src/tools/option43-generator/option43-generator.vue')['default']
|
Option43Generator: typeof import('./src/tools/option43-generator/option43-generator.vue')['default']
|
||||||
|
|||||||
@@ -120,6 +120,7 @@
|
|||||||
"file-type": "^19.6.0",
|
"file-type": "^19.6.0",
|
||||||
"flatten-anything": "^4.0.1",
|
"flatten-anything": "^4.0.1",
|
||||||
"fuse.js": "^6.6.2",
|
"fuse.js": "^6.6.2",
|
||||||
|
"gpt-tokens": "^1.3.13",
|
||||||
"generate-schema": "^2.6.0",
|
"generate-schema": "^2.6.0",
|
||||||
"get-timezone-offset": "^1.0.5",
|
"get-timezone-offset": "^1.0.5",
|
||||||
"hash-wasm": "^4.11.0",
|
"hash-wasm": "^4.11.0",
|
||||||
|
|||||||
Generated
+23
@@ -260,6 +260,9 @@ dependencies:
|
|||||||
get-timezone-offset:
|
get-timezone-offset:
|
||||||
specifier: ^1.0.5
|
specifier: ^1.0.5
|
||||||
version: 1.0.5
|
version: 1.0.5
|
||||||
|
gpt-tokens:
|
||||||
|
specifier: ^1.3.13
|
||||||
|
version: 1.3.13
|
||||||
hash-wasm:
|
hash-wasm:
|
||||||
specifier: ^4.11.0
|
specifier: ^4.11.0
|
||||||
version: 4.12.0
|
version: 4.12.0
|
||||||
@@ -10657,6 +10660,14 @@ packages:
|
|||||||
resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==}
|
resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
|
|
||||||
|
/gpt-tokens@1.3.13:
|
||||||
|
resolution: {integrity: sha512-f1s9yc7jn2XCuy4jdeDJ5eaLwg1/fYKaLCxSE9osCQbQeBmoULr8XLNYYz4fr5ZzXzJH25m/9QwgUY0DCkUagA==}
|
||||||
|
dependencies:
|
||||||
|
decimal.js: 10.4.3
|
||||||
|
js-tiktoken: 1.0.16
|
||||||
|
openai-chat-tokens: 0.2.8
|
||||||
|
dev: false
|
||||||
|
|
||||||
/graceful-fs@4.2.11:
|
/graceful-fs@4.2.11:
|
||||||
resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==}
|
resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==}
|
||||||
|
|
||||||
@@ -11833,6 +11844,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==}
|
resolution: {integrity: sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/js-tiktoken@1.0.16:
|
||||||
|
resolution: {integrity: sha512-nUVdO5k/M9llWpiaZlBBDdtmr6qWXwSD6fgaDu2zM8UP+OXxx9V37lFkI6w0/1IuaDx7WffZ37oYd9KvcWKElg==}
|
||||||
|
dependencies:
|
||||||
|
base64-js: 1.5.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
/js-tokens@4.0.0:
|
/js-tokens@4.0.0:
|
||||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||||
|
|
||||||
@@ -13292,6 +13309,12 @@ packages:
|
|||||||
is-wsl: 2.2.0
|
is-wsl: 2.2.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/openai-chat-tokens@0.2.8:
|
||||||
|
resolution: {integrity: sha512-nW7QdFDIZlAYe6jsCT/VPJ/Lam3/w2DX9oxf/5wHpebBT49KI3TN43PPhYlq1klq2ajzXWKNOLY6U4FNZM7AoA==}
|
||||||
|
dependencies:
|
||||||
|
js-tiktoken: 1.0.16
|
||||||
|
dev: false
|
||||||
|
|
||||||
/opencollective-postinstall@2.0.3:
|
/opencollective-postinstall@2.0.3:
|
||||||
resolution: {integrity: sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==}
|
resolution: {integrity: sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|||||||
@@ -0,0 +1,170 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { GPTTokens } from 'gpt-tokens';
|
||||||
|
import JSON5 from 'json5';
|
||||||
|
import type { supportModelType } from 'gpt-tokens';
|
||||||
|
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||||
|
import { useValidation } from '@/composable/validation';
|
||||||
|
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||||
|
|
||||||
|
const models = GPTTokens.supportModels;
|
||||||
|
|
||||||
|
const model = useQueryParamOrStorage({ name: 'model', storageName: 'gpt-counter:model', defaultValue: 'gpt-3.5-turbo-1106' });
|
||||||
|
const systemPrompt = ref('');
|
||||||
|
const userPrompt = ref('');
|
||||||
|
|
||||||
|
const isAdvancedMode = ref(false);
|
||||||
|
const messagesJsonArray = ref('');
|
||||||
|
const toolsJsonArray = ref('');
|
||||||
|
|
||||||
|
const messagesValidation = useValidation({
|
||||||
|
source: messagesJsonArray,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
message: 'Invalid "messages" array',
|
||||||
|
validator: value => value && JSON5.parse(value.trim()),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const toolsValidation = useValidation({
|
||||||
|
source: toolsJsonArray,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
message: 'Invalid "tools" array',
|
||||||
|
validator: value => value && JSON5.parse(value.trim()),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const outputTokenCosts = computed(() => {
|
||||||
|
try {
|
||||||
|
let messagesArray = [];
|
||||||
|
let toolsArray = [];
|
||||||
|
|
||||||
|
if (isAdvancedMode.value) {
|
||||||
|
messagesArray = messagesJsonArray.value ? JSON5.parse(messagesJsonArray.value.trim()) : [];
|
||||||
|
toolsArray = toolsJsonArray.value ? JSON5.parse(toolsJsonArray.value.trim()) : [];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (systemPrompt.value) {
|
||||||
|
messagesArray.push({ role: 'system', content: systemPrompt.value });
|
||||||
|
}
|
||||||
|
if (userPrompt.value) {
|
||||||
|
messagesArray.push({ role: 'user', content: userPrompt.value });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!messagesArray.length) {
|
||||||
|
return {
|
||||||
|
error: '',
|
||||||
|
usedTokens: '0',
|
||||||
|
usedUSD: '0',
|
||||||
|
promptUsedTokens: '0',
|
||||||
|
completionUsedTokens: '0',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const tokens = new GPTTokens({
|
||||||
|
model: model.value as supportModelType,
|
||||||
|
messages: messagesArray,
|
||||||
|
tools: toolsArray,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
error: '',
|
||||||
|
usedTokens: tokens.usedTokens.toString(),
|
||||||
|
usedUSD: tokens.usedUSD.toString(),
|
||||||
|
promptUsedTokens: tokens.promptUsedTokens.toString(),
|
||||||
|
completionUsedTokens: tokens.completionUsedTokens.toString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (e: any) {
|
||||||
|
return {
|
||||||
|
error: e.toString(),
|
||||||
|
usedTokens: '',
|
||||||
|
usedUSD: '',
|
||||||
|
promptUsedTokens: '',
|
||||||
|
completionUsedTokens: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<c-select
|
||||||
|
v-model:value="model"
|
||||||
|
label-position="left"
|
||||||
|
label="Model:"
|
||||||
|
:options="models"
|
||||||
|
placeholder="Select GPT model"
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div flex justify-center>
|
||||||
|
<n-form-item label="Advanded JSON Mode" label-placement="left">
|
||||||
|
<n-checkbox v-model:checked="isAdvancedMode" mr-2 />
|
||||||
|
</n-form-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<c-card v-if="isAdvancedMode" title="Prompts">
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="messagesJsonArray"
|
||||||
|
multiline raw-text
|
||||||
|
placeholder="Your 'messages' JSON array..."
|
||||||
|
rows="5"
|
||||||
|
autofocus
|
||||||
|
label="Your 'messages' JSON array:"
|
||||||
|
:validation="messagesValidation"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="toolsJsonArray"
|
||||||
|
multiline raw-text
|
||||||
|
placeholder="Your 'tools' JSON array..."
|
||||||
|
rows="5"
|
||||||
|
autofocus
|
||||||
|
label="Your 'tools' JSON array:"
|
||||||
|
:validation="toolsValidation"
|
||||||
|
/>
|
||||||
|
</c-card>
|
||||||
|
<c-card v-else title="Input JSON(s)">
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="systemPrompt"
|
||||||
|
multiline raw-text
|
||||||
|
placeholder="Your System Prompt content..."
|
||||||
|
rows="2"
|
||||||
|
autofocus
|
||||||
|
label="Your System Prompt content:"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="userPrompt"
|
||||||
|
multiline raw-text
|
||||||
|
placeholder="Your User Prompt content..."
|
||||||
|
rows="6"
|
||||||
|
autofocus
|
||||||
|
label="Your User Prompt content:"
|
||||||
|
/>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<n-divider />
|
||||||
|
|
||||||
|
<c-alert v-if="outputTokenCosts.error">
|
||||||
|
{{ outputTokenCosts.error }}
|
||||||
|
</c-alert>
|
||||||
|
|
||||||
|
<div v-if="!outputTokenCosts.error">
|
||||||
|
<n-form-item label="Used Tokens:">
|
||||||
|
<TextareaCopyable :value="outputTokenCosts.usedTokens" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="Prompt Tokens:">
|
||||||
|
<TextareaCopyable :value="outputTokenCosts.promptUsedTokens" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="Completion Tokens:">
|
||||||
|
<TextareaCopyable :value="outputTokenCosts.completionUsedTokens" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="Used USD:">
|
||||||
|
<TextareaCopyable :value="outputTokenCosts.usedUSD" />
|
||||||
|
</n-form-item>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -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'),
|
||||||
|
});
|
||||||
@@ -25,6 +25,7 @@ import { tool as angleConverter } from './angle-converter';
|
|||||||
import { tool as floatingPointNumberConverter } from './floating-point-number-converter';
|
import { tool as floatingPointNumberConverter } from './floating-point-number-converter';
|
||||||
import { tool as snowflakeIdExtractor } from './snowflake-id-extractor';
|
import { tool as snowflakeIdExtractor } from './snowflake-id-extractor';
|
||||||
import { tool as emailNormalizer } from './email-normalizer';
|
import { tool as emailNormalizer } from './email-normalizer';
|
||||||
|
import { tool as gptTokenEstimator } from './gpt-token-estimator';
|
||||||
import { tool as myIp } from './my-ip';
|
import { tool as myIp } from './my-ip';
|
||||||
import { tool as geoDistanceCalculator } from './geo-distance-calculator';
|
import { tool as geoDistanceCalculator } from './geo-distance-calculator';
|
||||||
import { tool as xVrSpamcauseDecoder } from './x-vr-spamcause-decoder';
|
import { tool as xVrSpamcauseDecoder } from './x-vr-spamcause-decoder';
|
||||||
@@ -461,6 +462,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
components: [
|
components: [
|
||||||
gitMemo,
|
gitMemo,
|
||||||
nanoMemo,
|
nanoMemo,
|
||||||
|
gptTokenEstimator,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user