├── cookies.js ├── modal.js ├── main.js ├── README.md ├── index.html └── style.css /cookies.js: -------------------------------------------------------------------------------- 1 | const cookieNotification = document.querySelector('.cookie-notification'); 2 | const cookieAccept = document.querySelector('#cookie-accept'); 3 | 4 | if (!localStorage.getItem('cookieAccepted')) { 5 | cookieNotification.style.display = 'block'; 6 | } 7 | 8 | cookieAccept.addEventListener('click', () => { 9 | localStorage.setItem('cookieAccepted', true); 10 | cookieNotification.style.display = 'none'; 11 | }); -------------------------------------------------------------------------------- /modal.js: -------------------------------------------------------------------------------- 1 | const modalLinks = document.querySelectorAll('.modal-link'); 2 | const modalCloseButtons = document.querySelectorAll('.modal-close'); 3 | const modals = document.querySelectorAll('.modal'); 4 | 5 | modalLinks.forEach((link) => { 6 | link.addEventListener('click', (event) => { 7 | event.preventDefault(); 8 | const target = link.getAttribute('href'); 9 | const modal = document.querySelector(target); 10 | modal.style.display = 'flex'; 11 | }); 12 | }); 13 | 14 | modalCloseButtons.forEach((button) => { 15 | button.addEventListener('click', (event) => { 16 | event.preventDefault(); 17 | const modal = button.closest('.modal'); 18 | modal.style.display = 'none'; 19 | }); 20 | }); 21 | 22 | modals.forEach((modal) => { 23 | modal.addEventListener('click', (event) => { 24 | if (event.target === modal) { 25 | modal.style.display = 'none'; 26 | } 27 | }); 28 | }); 29 | 30 | document.addEventListener('keyup', (event) => { 31 | if (event.key === 'Escape') { 32 | modals.forEach((modal) => { 33 | modal.style.display = 'none'; 34 | }); 35 | } 36 | }); -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | const modelSelect = document.getElementById('model'); 2 | const resultText = document.getElementById('result'); 3 | 4 | const wordCountButtons = document.querySelectorAll('.word-count-btn'); 5 | wordCountButtons.forEach(button => { 6 | button.addEventListener('click', () => { 7 | const words = button.getAttribute('data-words'); 8 | document.getElementById('word-count').value = words; 9 | calculateTotal(words); 10 | }); 11 | }); 12 | 13 | modelSelect.addEventListener('change', () => { 14 | calculateTotal(); 15 | }); 16 | 17 | document.getElementById('word-count').addEventListener('input', () => { 18 | calculateTotal(); 19 | }); 20 | 21 | function calculateTotal(words) { 22 | const wordCount = words || document.getElementById('word-count').value; 23 | const model = modelSelect.value; 24 | let price = 0; 25 | 26 | switch (model) { 27 | case 'chatgpt-4k': 28 | price = 0.002; 29 | break; 30 | case 'chatgpt-16k': 31 | price = 0.004; 32 | break; 33 | case 'gpt4-8k': 34 | price = 0.06; 35 | break; 36 | case 'gpt4-32k': 37 | price = 0.12; 38 | break; 39 | default: 40 | break; 41 | } 42 | 43 | const total = (wordCount / 500) * price; 44 | resultText.textContent = '$' + total.toFixed(2); 45 | } 46 | 47 | calculateTotal(); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
3 |
4 |
15 |
16 | ## 主要特点和功能
17 |
18 | 基于中文汉字的的 API 价格/成本计算器,对中文开发者更加友好;
19 |
20 | 可以帮助用户估算项目成本,规划API使用;
21 |
22 | 精确性高,简单易懂。
23 |
24 | ## 计算细节
25 |
26 | 模型对应的价格:
27 |
28 | >GPT-3.5-Turbo 4K - $0.002 / 1K tokens
29 | >
30 | >GPT-3.5-Turbo 16K - $0.004 / 1K tokens
31 | >
32 | >GPT-4.0 8K - $0.06 / 1K tokens
33 | >
34 | >GPT-4.0 32K - $0.12 / 1K tokens
35 |
36 | 计算公式:
37 |
38 | >成本 = (中文字数 * 2 / 1000) * 模型价格
39 |
40 | ## 部署方式
41 |
42 | 纯静态部署
43 |
44 | ## 开源赞助
45 |
46 |
47 |
48 |
49 |
50 | ## 相关项目
51 |
52 | * [ChatGPT-API-Faucet](https://github.com/terobox/ChatGPT-API-Faucet): AI 圈的水龙头网站,每24小时可领取一个令牌用于开发测试 AI 产品
53 |
54 | ## 开源协议
55 |
56 | [MIT](https://opensource.org/license/mit/)
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | $0.00
85 |