├── .github └── workflows │ ├── publish.yml │ └── test.yml ├── .gitignore ├── LICENSE ├── README.md ├── claude_to_sqlite ├── __init__.py ├── __main__.py └── cli.py ├── pyproject.toml └── tests ├── artifacts.json ├── example.json └── test_claude_to_sqlite.py /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish Python Package 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | test: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v5 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | cache: pip 23 | cache-dependency-path: pyproject.toml 24 | - name: Install dependencies 25 | run: | 26 | pip install '.[test]' 27 | - name: Run tests 28 | run: | 29 | python -m pytest 30 | deploy: 31 | runs-on: ubuntu-latest 32 | needs: [test] 33 | environment: release 34 | permissions: 35 | id-token: write 36 | steps: 37 | - uses: actions/checkout@v4 38 | - name: Set up Python 39 | uses: actions/setup-python@v5 40 | with: 41 | python-version: "3.12" 42 | cache: pip 43 | cache-dependency-path: pyproject.toml 44 | - name: Install dependencies 45 | run: | 46 | pip install setuptools wheel build 47 | - name: Build 48 | run: | 49 | python -m build 50 | - name: Publish 51 | uses: pypa/gh-action-pypi-publish@release/v1 52 | 53 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [push, pull_request] 4 | 5 | permissions: 6 | contents: read 7 | 8 | jobs: 9 | test: 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up Python ${{ matrix.python-version }} 17 | uses: actions/setup-python@v5 18 | with: 19 | python-version: ${{ matrix.python-version }} 20 | cache: pip 21 | cache-dependency-path: pyproject.toml 22 | - name: Install dependencies 23 | run: | 24 | pip install '.[test]' 25 | - name: Run tests 26 | run: | 27 | python -m pytest 28 | cog --check README.md 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .venv 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | venv 6 | .eggs 7 | .pytest_cache 8 | *.egg-info 9 | .DS_Store 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # claude-to-sqlite 2 | 3 | [![PyPI](https://img.shields.io/pypi/v/claude-to-sqlite.svg)](https://pypi.org/project/claude-to-sqlite/) 4 | [![Changelog](https://img.shields.io/github/v/release/simonw/claude-to-sqlite?include_prereleases&label=changelog)](https://github.com/simonw/claude-to-sqlite/releases) 5 | [![Tests](https://github.com/simonw/claude-to-sqlite/actions/workflows/test.yml/badge.svg)](https://github.com/simonw/claude-to-sqlite/actions/workflows/test.yml) 6 | [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/claude-to-sqlite/blob/master/LICENSE) 7 | 8 | Convert a [Claude.ai](https://claude.ai/) export to SQLite 9 | 10 | ## Installation 11 | 12 | Install this tool using `pip`: 13 | ```bash 14 | pip install claude-to-sqlite 15 | ``` 16 | ## Usage 17 | 18 | Start by [exporting your Claude data](https://support.anthropic.com/en/articles/9450526-how-can-i-export-my-claude-ai-data). You will be emailed a link to a zip file (though it may be missing the `.zip` extension). 19 | 20 | Run the command like this: 21 | 22 | ```bash 23 | claude-to-sqlite claude-export.zip claude.db 24 | ``` 25 | Now `claude.db` will be a SQLite containing the `conversations` and `messages` from your Claude export. 26 | 27 | You can explore that using [Datasette](https://datasette.io/): 28 | 29 | ```bash 30 | datasette claude.db 31 | ``` 32 | ## Database schema 33 | 34 | Assuming the Claude export JSON has not changed since this tool was last released on 20th October 2024 the database tables should look like this: 35 | 36 | 50 | ```sql 51 | CREATE TABLE [conversations] ( 52 | [uuid] TEXT PRIMARY KEY, 53 | [name] TEXT, 54 | [created_at] TEXT, 55 | [updated_at] TEXT, 56 | [account_id] TEXT 57 | ); 58 | CREATE TABLE [messages] ( 59 | [uuid] TEXT PRIMARY KEY, 60 | [text] TEXT, 61 | [sender] TEXT, 62 | [created_at] TEXT, 63 | [updated_at] TEXT, 64 | [attachments] TEXT, 65 | [files] TEXT, 66 | [conversation_id] TEXT REFERENCES [conversations]([uuid]) 67 | ); 68 | CREATE TABLE [artifacts] ( 69 | [id] TEXT PRIMARY KEY, 70 | [artifact] TEXT, 71 | [identifier] TEXT, 72 | [version] INTEGER, 73 | [type] TEXT, 74 | [language] TEXT, 75 | [title] TEXT, 76 | [content] TEXT, 77 | [thinking] TEXT, 78 | [conversation_id] TEXT REFERENCES [conversations]([uuid]), 79 | [message_id] TEXT REFERENCES [messages]([uuid]) 80 | ); 81 | ``` 82 | 83 | 84 | ## Development 85 | 86 | To contribute to this tool, first checkout the code. Then create a new virtual environment: 87 | ```bash 88 | cd claude-to-sqlite 89 | python -m venv venv 90 | source venv/bin/activate 91 | ``` 92 | Now install the dependencies and test dependencies: 93 | ```bash 94 | pip install -e '.[test]' 95 | ``` 96 | To run the tests: 97 | ```bash 98 | python -m pytest 99 | ``` 100 | -------------------------------------------------------------------------------- /claude_to_sqlite/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonw/claude-to-sqlite/c64aac7dce3c6f206e699c9c7dfe71d9f25829b7/claude_to_sqlite/__init__.py -------------------------------------------------------------------------------- /claude_to_sqlite/__main__.py: -------------------------------------------------------------------------------- 1 | from .cli import cli 2 | 3 | if __name__ == "__main__": 4 | cli() 5 | -------------------------------------------------------------------------------- /claude_to_sqlite/cli.py: -------------------------------------------------------------------------------- 1 | import click 2 | import json 3 | import re 4 | import sqlite_utils 5 | from typing import List, Dict 6 | import zipfile 7 | 8 | 9 | @click.command() 10 | @click.argument( 11 | "export_path", 12 | type=click.Path(exists=True, readable=True, file_okay=True, dir_okay=False), 13 | ) 14 | @click.argument( 15 | "db_path", type=click.Path(writable=True, file_okay=True, dir_okay=False) 16 | ) 17 | @click.version_option() 18 | def cli(export_path, db_path): 19 | """ 20 | Convert a Claude.ai export to SQLite 21 | 22 | Example usage: 23 | 24 | claude-to-sqlite claude.zip claude.db 25 | """ 26 | db = sqlite_utils.Database(db_path) 27 | conversations = parse_file(export_path) 28 | artifact_versions = {} 29 | with click.progressbar(conversations) as bar: 30 | for conversation in bar: 31 | conversation["account_id"] = conversation.pop("account")["uuid"] 32 | messages = conversation.pop("chat_messages") 33 | conversation_id = conversation["uuid"] 34 | db["conversations"].insert( 35 | conversation, pk="uuid", alter=True, replace=True 36 | ) 37 | for message in messages: 38 | to_insert = dict(message, conversation_id=conversation_id) 39 | db["messages"].insert( 40 | to_insert, 41 | pk="uuid", 42 | foreign_keys=("conversation_id",), 43 | alter=True, 44 | replace=True, 45 | ) 46 | artifacts = [] 47 | if to_insert["sender"] == "assistant": 48 | artifacts = extract_artifacts( 49 | to_insert["text"], 50 | conversation_id=conversation_id, 51 | message_id=to_insert["uuid"], 52 | versions=artifact_versions, 53 | ) 54 | db["artifacts"].insert_all( 55 | [ 56 | dict(artifact, message_id=to_insert["uuid"]) 57 | for artifact in artifacts 58 | ], 59 | pk="id", 60 | foreign_keys=("message_id", "conversation_id"), 61 | alter=True, 62 | replace=True, 63 | ) 64 | 65 | thinking_re = r"(.*?)" 66 | artifact_re = r"(.*?)" 67 | attr_re = r'(\w+)="([^"]*)"' 68 | 69 | 70 | def extract_artifacts( 71 | text: str, conversation_id: str, message_id: str, versions: dict 72 | ) -> List[Dict[str, str]]: 73 | # Find all artifacts and thinking tags with their positions 74 | artifacts = [ 75 | (m.start(), m.group(1), m.group(2)) 76 | for m in re.finditer(artifact_re, text, re.DOTALL) 77 | ] 78 | thinking_tags = [ 79 | (m.start(), m.group(1)) for m in re.finditer(thinking_re, text, re.DOTALL) 80 | ] 81 | 82 | # Combine and sort all tags by their position in the text 83 | all_tags = sorted( 84 | [(pos, "artifact", attr, content) for pos, attr, content in artifacts] 85 | + [(pos, "thinking", content, "") for pos, content in thinking_tags] 86 | ) 87 | 88 | result = [] 89 | current_thinking = None 90 | 91 | for _, tag_type, attr_or_content, content in all_tags: 92 | if tag_type == "thinking": 93 | current_thinking = attr_or_content.strip() 94 | elif tag_type == "artifact": 95 | # Parse attributes 96 | attributes = dict(re.findall(attr_re, attr_or_content)) 97 | 98 | identifier = attributes.get("identifier", "") 99 | artifact_id = f"{conversation_id}-{identifier}" 100 | 101 | # Increment version for this identifier 102 | version = (versions.get(artifact_id) or 0) + 1 103 | versions[artifact_id] = version 104 | 105 | thinking = None 106 | if current_thinking: 107 | thinking = current_thinking 108 | current_thinking = None 109 | 110 | artifact_dict = { 111 | "id": f"{artifact_id}-{version}", 112 | "artifact": artifact_id, 113 | "identifier": identifier, 114 | "version": version, 115 | "type": attributes.get("type", ""), 116 | "language": attributes.get("language", ""), 117 | "title": attributes.get("title", ""), 118 | "content": content.strip(), 119 | "thinking": thinking, 120 | "conversation_id": conversation_id, 121 | "message_id": message_id, 122 | } 123 | result.append(artifact_dict) 124 | 125 | return result 126 | 127 | 128 | def parse_file(file_path): 129 | json_data = None 130 | with open(file_path, "rb") as f: 131 | if zipfile.is_zipfile(file_path): 132 | with zipfile.ZipFile(f) as z: 133 | if "conversations.json" in z.namelist(): 134 | with z.open("conversations.json") as json_file: 135 | json_data = json_file.read() 136 | else: 137 | raise click.ClickException( 138 | "No 'conversations.json' file found in the ZIP archive" 139 | ) 140 | else: 141 | f.seek(0) 142 | json_data = f.read() 143 | try: 144 | return json.loads(json_data) 145 | except json.JSONDecodeError: 146 | raise click.ClickException("File is neither a valid ZIP nor a valid JSON file") 147 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "claude-to-sqlite" 3 | version = "0.2" 4 | description = "Convert a Claude.ai export to SQLite" 5 | readme = "README.md" 6 | authors = [{name = "Simon Willison"}] 7 | license = {text = "Apache-2.0"} 8 | requires-python = ">=3.8" 9 | classifiers = [ 10 | "License :: OSI Approved :: Apache Software License" 11 | ] 12 | dependencies = [ 13 | "click", 14 | "sqlite-utils", 15 | "cogapp" 16 | ] 17 | 18 | [project.urls] 19 | Homepage = "https://github.com/simonw/claude-to-sqlite" 20 | Changelog = "https://github.com/simonw/claude-to-sqlite/releases" 21 | Issues = "https://github.com/simonw/claude-to-sqlite/issues" 22 | CI = "https://github.com/simonw/claude-to-sqlite/actions" 23 | 24 | [project.scripts] 25 | claude-to-sqlite = "claude_to_sqlite.cli:cli" 26 | 27 | [project.optional-dependencies] 28 | test = ["pytest"] 29 | -------------------------------------------------------------------------------- /tests/artifacts.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "uuid": "91098bc8-f2c4-427b-b71b-1e25efa2e871", 4 | "name": "LLM Pricing Calculator", 5 | "created_at": "2024-10-17T03:28:33.480257Z", 6 | "updated_at": "2024-10-17T03:47:12.635369Z", 7 | "account": { 8 | "uuid": "2a0434bc-651f-407a-bc74-bdc295dc009b" 9 | }, 10 | "chat_messages": [ 11 | { 12 | "uuid": "083850f6-fca7-40c3-916a-e57f7ae5f0fe", 13 | "text": "Add a onkeyup event too, I want that calculator to update as I type\n\nAlso add a section underneath the calculator called \"Presets\" which lets the user click a model to populate the cost per million fields with that model's prices - which should be shown on the page too\n\nI've dumped in some screenshots of pricing pages you can use - ignore prompt caching prices", 14 | "sender": "human", 15 | "created_at": "2024-10-17T03:37:51.154489Z", 16 | "updated_at": "2024-10-17T03:37:51.154489Z", 17 | "attachments": [], 18 | "files": [ 19 | { 20 | "file_name": "CleanShot 20241016 at 20.34.122x.png" 21 | }, 22 | { 23 | "file_name": "CleanShot 20241016 at 20.34.332x.png" 24 | }, 25 | { 26 | "file_name": "CleanShot 20241016 at 20.34.532x.png" 27 | }, 28 | { 29 | "file_name": "CleanShot 20241016 at 20.35.232x.png" 30 | }, 31 | { 32 | "file_name": "CleanShot 20241016 at 20.37.012x.png" 33 | } 34 | ] 35 | }, 36 | { 37 | "uuid": "287b1868-17d4-4660-9089-b3eb4ddecb1b", 38 | "text": "Built me an artifact with no react that is a pricing calculator for large language models\n\nIt has four numeric inputs , for number of input tokens, number of output tokens, cost per million input tokens in dollars and cost per million output tokens in dollars\n\nThe result is displayed twice: once as dollars and once as cents. These values update as the number fields changed, no need to hit submit\n\nMake it look nice on mobile", 39 | "sender": "human", 40 | "created_at": "2024-10-17T03:28:55.541307Z", 41 | "updated_at": "2024-10-17T03:28:55.541307Z", 42 | "attachments": [], 43 | "files": [] 44 | }, 45 | { 46 | "uuid": "5e3e08cb-7e91-44fc-a2bb-6abacba3cb71", 47 | "text": " Certainly! I'll create an HTML artifact with a pricing calculator for large language models that meets your requirements. This calculator will use vanilla JavaScript to handle the calculations and update the results in real-time as the input values change.\n\nThis request is suitable for an artifact as it's a self-contained, interactive component that can be reused and modified. It's substantial enough to warrant its own artifact and will be more useful as a standalone piece. I'll create a new artifact with the identifier \"llm-pricing-calculator\".\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.00

\n

Total Cost: 0 cents

\n
\n
\n\n \n\n\n
\n\nI've created an HTML artifact that includes a pricing calculator for large language models based on your specifications. Here's a breakdown of the key features:\n\n1. Four numeric inputs for:\n - Number of input tokens\n - Number of output tokens\n - Cost per million input tokens (in dollars)\n - Cost per million output tokens (in dollars)\n\n2. The result is displayed in both dollars (with two decimal places) and cents.\n\n3. The calculation updates in real-time as the input values change, without the need for a submit button.\n\n4. The design is responsive and looks good on mobile devices.\n\n5. I've used a simple and clean design with a white calculator on a light gray background for better readability and contrast.\n\n6. The JavaScript code handles the calculations and updates the result fields dynamically.\n\nTo use this calculator, you can copy the HTML code and save it as an .html file, then open it in a web browser. The calculator will work offline and doesn't require any external dependencies.\n\nLet me know if you'd like any modifications or have any questions about the implementation!", 48 | "sender": "assistant", 49 | "created_at": "2024-10-17T03:28:55.541307Z", 50 | "updated_at": "2024-10-17T03:28:55.541307Z", 51 | "attachments": [], 52 | "files": [] 53 | }, 54 | { 55 | "uuid": "f3d5450e-f7a9-47d8-961d-c5f60c00e4d8", 56 | "text": "Those fields should all start blank, while the prices should start at zero. Use the \"change\" event not the input event", 57 | "sender": "human", 58 | "created_at": "2024-10-17T03:30:35.859918Z", 59 | "updated_at": "2024-10-17T03:30:35.859918Z", 60 | "attachments": [], 61 | "files": [] 62 | }, 63 | { 64 | "uuid": "7d4445e2-4473-45f8-86d5-1c96473b32f6", 65 | "text": " Certainly, I'll modify the calculator to start with blank fields and use the \"change\" event instead of the \"input\" event. Here's the updated version:\n\nThis request is a modification of the existing \"llm-pricing-calculator\" artifact. It's not a new artifact but an update to improve the user experience and meet the new requirements. I'll reuse the \"llm-pricing-calculator\" identifier to maintain continuity.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.00

\n

Total Cost: 0 cents

\n
\n
\n\n \n\n\n
\n\nI've made the following changes to the LLM Pricing Calculator:\n\n1. Removed the `value` attributes from all input fields, so they start blank.\n2. Changed the event listener from 'input' to 'change'. This means the calculation will update when the user finishes entering a value and moves to another field, or when they press Enter.\n3. The initial calculation remains in place, which ensures that the price displays start at zero even when the input fields are blank.\n\nThese modifications address your requirements:\n- All input fields now start blank.\n- The prices (both in dollars and cents) start at zero.\n- The calculator uses the \"change\" event instead of the \"input\" event.\n\nThe rest of the functionality remains the same. Users can enter values into any of the four fields, and the total cost will be calculated and displayed both in dollars and cents when they complete their input for each field.\n\nIs there anything else you'd like me to modify or explain about this calculator?", 66 | "sender": "assistant", 67 | "created_at": "2024-10-17T03:30:35.859918Z", 68 | "updated_at": "2024-10-17T03:30:35.859918Z", 69 | "attachments": [], 70 | "files": [] 71 | }, 72 | { 73 | "uuid": "dfa84b16-6f6a-4b12-a0bd-6f9e6e72c099", 74 | "text": "Cents and dollars should both be shown wirh up to six decimal places", 75 | "sender": "human", 76 | "created_at": "2024-10-17T03:32:21.137036Z", 77 | "updated_at": "2024-10-17T03:32:21.137036Z", 78 | "attachments": [], 79 | "files": [] 80 | }, 81 | { 82 | "uuid": "5fd78d7e-e9fa-4a99-998c-bcfd31374670", 83 | "text": " Certainly, I'll update the calculator to show both cents and dollars with up to six decimal places. This will provide more precision for the calculated values.\n\nThis is another update to our existing \"llm-pricing-calculator\" artifact. We're modifying the precision of the displayed results to meet the user's new requirements. We'll continue to use the same identifier for consistency.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.000000

\n

Total Cost: 0.000000 cents

\n
\n
\n\n \n\n\n
\n\nI've made the following changes to the LLM Pricing Calculator to accommodate your request for higher precision:\n\n1. Updated the result display for both dollars and cents to show up to six decimal places:\n - Changed `totalCost.toFixed(2)` to `totalCost.toFixed(6)` for the dollar amount.\n - Changed `Math.round(totalCost * 100)` to `(totalCost * 100).toFixed(6)` for the cent amount.\n\n2. Updated the initial values in the HTML to show six decimal places: `0.000000` for both dollars and cents.\n\n3. Changed the `step` attribute for the input cost fields to `0.000001` to allow for more precise input if needed.\n\nThese modifications allow the calculator to display more precise results, which can be particularly useful when dealing with very small costs per token or when calculating the cost for a large number of tokens.\n\nThe calculator still maintains all the previous functionality:\n- Input fields start blank.\n- Prices (both in dollars and cents) start at zero with six decimal places.\n- The calculator uses the \"change\" event to update results.\n- The layout is responsive and mobile-friendly.\n\nIs there anything else you'd like me to adjust or explain about this updated calculator?", 84 | "sender": "assistant", 85 | "created_at": "2024-10-17T03:32:21.137036Z", 86 | "updated_at": "2024-10-17T03:32:21.137036Z", 87 | "attachments": [], 88 | "files": [] 89 | }, 90 | { 91 | "uuid": "abcb904f-d092-418f-96f8-cd1c76601376", 92 | "text": " Certainly! I'll update the calculator to include the onkeyup event for real-time updates as you type, and add a \"Presets\" section with clickable model options to populate the input fields. I'll use the pricing information from the screenshots you provided.\n\nThis request builds upon our existing \"llm-pricing-calculator\" artifact. We're adding new functionality and incorporating data from the provided images. This is a substantial update that will make the calculator more interactive and user-friendly, qualifying it as a good use of an artifact.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.000000

\n

Total Cost: 0.000000 cents

\n
\n
\n\n
\n

Presets

\n \n \n \n \n \n \n \n \n
\n\n \n\n\n
\n\nI've made the following changes to the LLM Pricing Calculator:\n\n1. Added `onkeyup` event handlers to all input fields, in addition to the existing `onchange` handlers. This ensures the calculator updates in real-time as you type.\n\n2. Created a new \"Presets\" section below the calculator with buttons for different models:\n - Gemini 1.5 Flash\n - Gemini 1.5 Flash-8B\n - Gemini 1.5 Pro\n - Claude 3.5 Sonnet\n - Claude 3 Opus\n - Claude 3 Haiku\n - GPT-4O\n - GPT-4O Mini\n\n3. Implemented a `setPreset` function that populates the input and output cost fields with the corresponding model's pricing when a preset button is clicked.\n\n4. Updated the styling to accommodate the new Presets section and make the buttons visually appealing.\n\n5. The calculator still displays results in both dollars and cents, with six decimal places for precision.\n\nTo use the calculator:\n1. Enter the number of input and output tokens.\n2. Either manually enter the cost per million tokens for input and output, or click on a preset button to automatically fill in these values for a specific model.\n3. The total cost will update in real-time as you type or when you select a preset.\n\nThis updated version provides a more interactive and user-friendly experience, allowing quick comparisons between different language models and custom pricing scenarios.", 93 | "sender": "assistant", 94 | "created_at": "2024-10-17T03:37:51.154489Z", 95 | "updated_at": "2024-10-17T03:37:51.154489Z", 96 | "attachments": [], 97 | "files": [] 98 | }, 99 | { 100 | "uuid": "6b8ffb4e-fdc7-4dc8-a401-3c556fb88d32", 101 | "text": "The presets should display the input/output costs per million next to the buttons", 102 | "sender": "human", 103 | "created_at": "2024-10-17T03:38:53.909415Z", 104 | "updated_at": "2024-10-17T03:38:53.909415Z", 105 | "attachments": [], 106 | "files": [] 107 | }, 108 | { 109 | "uuid": "4f0bbc81-c4fb-4379-acbb-c90e17bda248", 110 | "text": " Certainly! I'll update the presets section to display the input and output costs per million tokens next to each button. This will provide users with immediate visibility of the pricing for each model without having to click the buttons.\n\nThis request further enhances our existing \"llm-pricing-calculator\" artifact. We're adding more detailed information to the presets section, which will improve the user experience and make the calculator more informative. This update maintains the artifact's value as a standalone, reusable component.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.000000

\n

Total Cost: 0.000000 cents

\n
\n
\n\n
\n

Presets

\n
\n
\n\n \n\n\n
\n\nI've updated the LLM Pricing Calculator with the following changes:\n\n1. Redesigned the presets section to display input and output costs per million tokens next to each button.\n\n2. Created a `presets` object that contains all the model information, including the display name and pricing.\n\n3. Implemented a `createPresetButtons()` function that dynamically generates the preset buttons and their associated pricing information.\n\n4. Updated the styling to accommodate the new layout of the presets section, ensuring it's visually appealing and easy to read.\n\n5. Increased the max-width of the calculator and presets containers to 500px to accommodate the additional information.\n\n6. The calculator still updates in real-time as you type or when you select a preset.\n\nNow, users can see the input and output costs per million tokens for each model at a glance, making it easier to compare different models without having to click on the buttons. The preset buttons still function as before, populating the input fields with the corresponding model's pricing when clicked.\n\nThis update makes the calculator more informative and user-friendly, allowing for quick comparisons between different language models while maintaining the ability to input custom pricing scenarios.", 111 | "sender": "assistant", 112 | "created_at": "2024-10-17T03:38:53.909415Z", 113 | "updated_at": "2024-10-17T03:38:53.909415Z", 114 | "attachments": [], 115 | "files": [] 116 | }, 117 | { 118 | "uuid": "b5f146b3-7d51-43ad-9efd-47c11888137a", 119 | "text": "You should spell GPT-4o correctly (lower case o) - also add extra buttons for the \"Gemini 1.5 Pro > 128,000 tokens\" cases - and when you display prices of the presets they should show decimal points like this: $1.25 or $0.0375 or $15 or $0.25 or $2.50 - so no decimal points for a number like $15 and always at least two for a non-round-number", 120 | "sender": "human", 121 | "created_at": "2024-10-17T03:41:19.612456Z", 122 | "updated_at": "2024-10-17T03:41:19.612456Z", 123 | "attachments": [], 124 | "files": [] 125 | }, 126 | { 127 | "uuid": "67427317-da19-4fa1-a9b1-d3264caaa2c6", 128 | "text": " I apologize for the mistake in spelling GPT-4o. I'll make the corrections you've requested, including adding buttons for the \"Gemini 1.5 Pro > 128,000 tokens\" cases and adjusting the display of prices as specified.\n\nThis request involves further refinements to our \"llm-pricing-calculator\" artifact. We're correcting a spelling error, adding new preset options, and improving the price display format. These changes will enhance the accuracy and usability of the calculator, maintaining its value as a comprehensive, standalone tool.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.000000

\n

Total Cost: 0.000000 cents

\n
\n
\n\n
\n

Presets

\n
\n
\n\n \n\n\n
\n\nI've made the following changes to the LLM Pricing Calculator:\n\n1. Corrected the spelling of GPT-4o (lowercase 'o') in the presets object.\n\n2. Added a new preset for \"Gemini 1.5 Pro > 128k tokens\" with the appropriate pricing.\n\n3. Implemented a `formatPrice()` function to display prices according to the specified format:\n - No decimal points for whole numbers (e.g., $15)\n - At least two decimal places for non-round numbers (e.g., $0.0375)\n - Trimming trailing zeros for numbers with more than two decimal places (e.g., $1.25 instead of $1.2500)\n\n4. Updated the `createPresetButtons()` function to use the new `formatPrice()` function when displaying preset prices.\n\n5. Kept all other functionality intact, including real-time updates and the ability to input custom pricing scenarios.\n\nThese changes improve the accuracy of the model names, provide more pricing options, and present the prices in a more readable and consistent format. The calculator now offers a more comprehensive set of presets and displays pricing information in line with standard financial notation.", 129 | "sender": "assistant", 130 | "created_at": "2024-10-17T03:41:19.612456Z", 131 | "updated_at": "2024-10-17T03:41:19.612456Z", 132 | "attachments": [], 133 | "files": [] 134 | }, 135 | { 136 | "uuid": "963fbfff-2bf9-4da7-9934-657f3b299111", 137 | "text": "The Gemini 1.5 Flash and Gemini 1.5 Flash-8B models both have >128,000 prices too", 138 | "sender": "human", 139 | "created_at": "2024-10-17T03:42:40.826315Z", 140 | "updated_at": "2024-10-17T03:42:40.826315Z", 141 | "attachments": [], 142 | "files": [] 143 | }, 144 | { 145 | "uuid": "10f71281-2371-4e2d-bcf9-a2c868e4189a", 146 | "text": " I apologize for overlooking that detail. You're absolutely right, and I'll add the >128,000 token prices for both Gemini 1.5 Flash and Gemini 1.5 Flash-8B models as well. Let's update the calculator to include these options.\n\nThis request further refines our \"llm-pricing-calculator\" artifact by adding more comprehensive pricing options for the Gemini models. This update will make the calculator more accurate and useful for a wider range of token counts, maintaining its value as a detailed and practical tool.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.000000

\n

Total Cost: 0.000000 cents

\n
\n
\n\n
\n

Presets

\n
\n
\n\n \n\n\n
\n\nI've made the following updates to the LLM Pricing Calculator:\n\n1. Added new presets for Gemini 1.5 Flash and Gemini 1.5 Flash-8B models with >128,000 token prices:\n - Gemini 1.5 Flash ≤128k and >128k\n - Gemini 1.5 Flash-8B ≤128k and >128k\n\n2. Updated the preset names to clearly indicate which pricing applies to ≤128k tokens and which applies to >128k tokens.\n\n3. Adjusted the pricing for these models according to the information provided in the images:\n - Gemini 1.5 Flash >128k: Input $0.15, Output $0.60 per 1M tokens\n - Gemini 1.5 Flash-8B >128k: Input $0.075, Output $0.30 per 1M tokens\n\n4. Kept all other functionality intact, including the price formatting, real-time updates, and custom pricing input.\n\nThese changes provide a more comprehensive set of options for users, allowing them to accurately calculate costs for different token ranges across all Gemini models. The calculator now offers a clearer distinction between pricing tiers for each model, making it easier for users to select the appropriate preset based on their expected token usage.\n\nThe user interface remains intuitive, with each preset button clearly labeled and accompanied by its corresponding pricing information. This update ensures that the calculator remains a valuable tool for estimating costs across a wide range of language models and use cases.", 147 | "sender": "assistant", 148 | "created_at": "2024-10-17T03:42:40.826315Z", 149 | "updated_at": "2024-10-17T03:42:40.826315Z", 150 | "attachments": [], 151 | "files": [] 152 | }, 153 | { 154 | "uuid": "80de7d0d-7e65-4706-9945-5e549c7f3958", 155 | "text": "Add a disclaimer at the bottom that says \"Prices were correct as-of 16th October 2024, they may have changed\"", 156 | "sender": "human", 157 | "created_at": "2024-10-17T03:43:42.951452Z", 158 | "updated_at": "2024-10-17T03:43:42.951452Z", 159 | "attachments": [], 160 | "files": [] 161 | }, 162 | { 163 | "uuid": "6ec5a54c-dd6a-48ea-aea9-5d6bc35f6a9e", 164 | "text": " Certainly! I'll add the disclaimer at the bottom of the calculator as requested.\n\nThis request adds an important disclaimer to our \"llm-pricing-calculator\" artifact. This addition enhances the artifact's usefulness by providing context about the pricing information's timeliness, which is crucial for users to make informed decisions.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.000000

\n

Total Cost: 0.000000 cents

\n
\n
\n\n
\n

Presets

\n
\n
\n\n
\n Prices were correct as of 16th October 2024, they may have changed.\n
\n\n \n\n\n
\n\nI've made the following change to the LLM Pricing Calculator:\n\n1. Added a disclaimer at the bottom of the calculator that reads: \"Prices were correct as of 16th October 2024, they may have changed.\"\n\n2. Created a new `
` with the class \"disclaimer\" to contain this text.\n\n3. Added CSS styling for the disclaimer to ensure it's visually distinct from the rest of the content:\n - Slightly smaller font size (14px)\n - Gray color (#777)\n - Centered text\n - Italic font style\n\n4. Positioned the disclaimer after the presets section and gave it the same width and background as the calculator and presets sections for visual consistency.\n\nThis addition provides important context for users, reminding them that the preset prices are based on a specific date and may not reflect current pricing. It encourages users to verify the prices if absolute accuracy is required for their calculations.\n\nAll other functionality of the calculator remains unchanged, including the real-time cost updates, preset buttons, and price formatting.", 165 | "sender": "assistant", 166 | "created_at": "2024-10-17T03:43:42.951452Z", 167 | "updated_at": "2024-10-17T03:43:42.951452Z", 168 | "attachments": [], 169 | "files": [] 170 | }, 171 | { 172 | "uuid": "6a0d78ef-e4cd-4cd1-bdb2-fef1560f4c19", 173 | "text": "On wider screens the presets area should sit to the right of the calcualtor", 174 | "sender": "human", 175 | "created_at": "2024-10-17T03:45:17.501790Z", 176 | "updated_at": "2024-10-17T03:45:17.501790Z", 177 | "attachments": [], 178 | "files": [] 179 | }, 180 | { 181 | "uuid": "ee5c339f-3550-43c6-b09d-e0cfe9a38bd3", 182 | "text": " Certainly! I'll modify the layout so that on wider screens, the presets area sits to the right of the calculator. This will make better use of the available space on larger displays while maintaining a stacked layout on smaller screens for better mobile compatibility.\n\nThis request involves a significant layout change to our \"llm-pricing-calculator\" artifact. We're improving the use of space on wider screens, which will enhance the user experience for desktop users while maintaining mobile compatibility. This change maintains the artifact's value as a comprehensive, responsive tool.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n
\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.000000

\n

Total Cost: 0.000000 cents

\n
\n
\n\n
\n

Presets

\n
\n
\n
\n\n
\n Prices were correct as of 16th October 2024, they may have changed.\n
\n
\n\n \n\n\n
\n\nI've made the following changes to implement a responsive layout for the LLM Pricing Calculator:\n\n1. Added a container `
` with a max-width of 1000px to control the overall width of the calculator on larger screens.\n\n2. Created a flex container for the calculator and presets sections.\n\n3. Implemented a media query that activates the flex layout when the screen width is at least 768px (typical tablet width and above):\n ```css\n @media (min-width: 768px) {\n .flex-container {\n display: flex;\n gap: 20px;\n }\n .calculator {\n flex: 1;\n }\n .presets {\n flex: 1;\n }\n }\n ```\n\n4. Adjusted the styling to ensure consistent appearance in both layouts.\n\n5. Moved the disclaimer outside of the flex container to ensure it spans the full width below both sections.\n\nThese changes result in the following behavior:\n\n- On screens narrower than 768px (e.g., mobile devices), the layout remains stacked vertically as before.\n- On screens 768px and wider, the calculator appears on the left and the presets on the right, making better use of the available horizontal space.\n- The disclaimer remains centered below both sections in all layouts.\n\nAll the functionality of the calculator remains unchanged, including real-time cost updates, preset buttons, and price formatting. This responsive design ensures that the calculator is user-friendly and visually appealing on both mobile and desktop devices.", 183 | "sender": "assistant", 184 | "created_at": "2024-10-17T03:45:17.501790Z", 185 | "updated_at": "2024-10-17T03:45:17.501790Z", 186 | "attachments": [], 187 | "files": [] 188 | }, 189 | { 190 | "uuid": "3efe0913-0cea-410d-8639-faede73ba6f8", 191 | "text": "If it's showing \"Total Cost: 0.085500 cents\" it should show \"Total Cost: 0.0855 cents\" instead. And use * { box-sizing: border-box; }", 192 | "sender": "human", 193 | "created_at": "2024-10-17T03:47:12.635369Z", 194 | "updated_at": "2024-10-17T03:47:12.635369Z", 195 | "attachments": [], 196 | "files": [] 197 | }, 198 | { 199 | "uuid": "f976a5e8-7642-474f-82c6-e9a2abf5883c", 200 | "text": " Certainly! I'll update the cent display to trim unnecessary trailing zeros and add the `box-sizing: border-box` rule to all elements. These changes will improve the presentation of the results and ensure more predictable layout behavior.\n\nThis request involves refining the output format of our \"llm-pricing-calculator\" artifact and improving its CSS. These changes will enhance the readability of the results and the consistency of the layout, maintaining the artifact's value as a user-friendly tool.\n\n\n\n\n\n \n \n LLM Pricing Calculator\n \n\n\n
\n
\n
\n

LLM Pricing Calculator

\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n

Total Cost: $0.000000

\n

Total Cost: 0 cents

\n
\n
\n\n
\n

Presets

\n
\n
\n
\n\n
\n Prices were correct as of 16th October 2024, they may have changed.\n
\n
\n\n \n\n\n
\n\nI've made the following changes to the LLM Pricing Calculator:\n\n1. Added the `box-sizing: border-box;` rule to all elements:\n ```css\n * {\n box-sizing: border-box;\n }\n ```\n This ensures that padding and border are included in the element's total width and height, providing more predictable layouts.\n\n2. Updated the cent display to trim unnecessary trailing zeros:\n - Created a new `trimZeros` function:\n ```javascript\n function trimZeros(num) {\n return num.replace(/\\.?0+$/, '');\n }\n ```\n - Modified the `calculateCost` function to use `trimZeros`:\n ```javascript\n document.getElementById('costCents').textContent = trimZeros((totalCost * 100).toFixed(4));\n ```\n This change ensures that cents are displayed without unnecessary trailing zeros (e.g., \"0.0855 cents\" instead of \"0.085500 cents\").\n\n3. Adjusted the initial display of cents to show just \"0\" instead of \"0.000000\".\n\nThese modifications improve the calculator's layout consistency and the readability of the results. The calculator now provides a cleaner, more precise output for the cent values while maintaining all its previous functionality.\n\nThe responsive design, preset functionality, and real-time cost updates remain unchanged. Users can still interact with the calculator on both mobile and desktop devices, selecting presets or entering custom values to calculate LLM usage costs.", 201 | "sender": "assistant", 202 | "created_at": "2024-10-17T03:47:12.635369Z", 203 | "updated_at": "2024-10-17T03:47:12.635369Z", 204 | "attachments": [], 205 | "files": [] 206 | } 207 | ] 208 | } 209 | ] -------------------------------------------------------------------------------- /tests/example.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "uuid": "1db4c66e-b369-4e3a-96a9-6c16f8301ee8", 4 | "name": "Bash Command for OpenAI API", 5 | "created_at": "2024-10-18T05:30:10.325754Z", 6 | "updated_at": "2024-10-18T05:30:22.223181Z", 7 | "account": {"uuid": "2a0434bc-651f-407a-bc74-bdc295dc009b"}, 8 | "chat_messages": [ 9 | { 10 | "uuid": "22b34c9c-69c1-46ad-87da-71570a70f107", 11 | "text": "Turn this into a bash command", 12 | "sender": "human", 13 | "created_at": "2024-10-18T05:30:20.458713Z", 14 | "updated_at": "2024-10-18T05:30:20.458713Z", 15 | "attachments": [], 16 | "files": [{"file_name": "CleanShot 20241017 at 22.29.542x.png"}] 17 | }, 18 | { 19 | "uuid": "12c87835-a63c-430e-a090-bd70d9efb601", 20 | "text": " To turn this into a bash command, we need to modify the JSON structure slightly to make it compatible with bash syntax...", 21 | "sender": "assistant", 22 | "created_at": "2024-10-18T05:30:20.458713Z", 23 | "updated_at": "2024-10-18T05:30:20.458713Z", 24 | "attachments": [], 25 | "files": [] 26 | } 27 | ] 28 | } 29 | ] 30 | -------------------------------------------------------------------------------- /tests/test_claude_to_sqlite.py: -------------------------------------------------------------------------------- 1 | from click.testing import CliRunner 2 | from claude_to_sqlite.cli import cli 3 | import io 4 | import json 5 | import pathlib 6 | import pytest 7 | import sqlite_utils 8 | import zipfile 9 | 10 | TEST_DIR = pathlib.Path(__file__).parent 11 | EXAMPLE = json.loads((TEST_DIR / "example.json").read_text()) 12 | 13 | 14 | @pytest.mark.parametrize("use_zip", (False, True)) 15 | @pytest.mark.parametrize("is_valid_json", (True, False)) 16 | def test_import(use_zip, is_valid_json): 17 | runner = CliRunner() 18 | bytes = json.dumps(EXAMPLE).encode("utf-8") 19 | if not is_valid_json: 20 | bytes = b"x" + bytes 21 | if use_zip: 22 | zip_buffer = io.BytesIO() 23 | with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zip_file: 24 | zip_file.writestr("conversations.json", bytes) 25 | bytes = zip_buffer.getvalue() 26 | with runner.isolated_filesystem(): 27 | with open("export", "wb") as fp: 28 | fp.write(bytes) 29 | result = runner.invoke(cli, ["export", "export.db"]) 30 | if is_valid_json: 31 | assert result.exit_code == 0 32 | db = sqlite_utils.Database("export.db") 33 | assert set(db.table_names()) == {"conversations", "messages"} 34 | else: 35 | assert result.exit_code != 0 36 | assert ( 37 | result.output 38 | == "Error: File is neither a valid ZIP nor a valid JSON file\n" 39 | ) 40 | 41 | 42 | def test_import_artifacts(): 43 | runner = CliRunner() 44 | with runner.isolated_filesystem(): 45 | result = runner.invoke( 46 | cli, [str(TEST_DIR / "artifacts.json"), "export.db"], catch_exceptions=False 47 | ) 48 | assert result.exit_code == 0 49 | db = sqlite_utils.Database("export.db") 50 | assert set(db.table_names()) == {"conversations", "messages", "artifacts"} 51 | assert db["artifacts"].count == 10 52 | actual = [] 53 | for row in db["artifacts"].rows: 54 | actual.append( 55 | dict( 56 | row, 57 | content=row["content"][:10] + "...", 58 | thinking=row["thinking"][:10] + "...", 59 | ) 60 | ) 61 | expected = [ 62 | { 63 | "id": "91098bc8-f2c4-427b-b71b-1e25efa2e871-llm-pricing-calculator-1", 64 | "artifact": "91098bc8-f2c4-427b-b71b-1e25efa2e871-llm-pricing-calculator", 65 | "identifier": "llm-pricing-calculator", 66 | "version": 1, 67 | "type": "text/html", 68 | "language": "", 69 | "title": "LLM Pricing Calculator", 70 | "content": "