├── claude_to_sqlite
├── __init__.py
├── __main__.py
└── cli.py
├── .gitignore
├── .github
└── workflows
│ ├── test.yml
│ └── publish.yml
├── pyproject.toml
├── tests
├── example.json
├── test_claude_to_sqlite.py
└── artifacts.json
├── README.md
└── LICENSE
/claude_to_sqlite/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/claude_to_sqlite/__main__.py:
--------------------------------------------------------------------------------
1 | from .cli import cli
2 |
3 | if __name__ == "__main__":
4 | cli()
5 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # claude-to-sqlite
2 |
3 | [](https://pypi.org/project/claude-to-sqlite/)
4 | [](https://github.com/simonw/claude-to-sqlite/releases)
5 | [](https://github.com/simonw/claude-to-sqlite/actions/workflows/test.yml)
6 | [](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/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 |
--------------------------------------------------------------------------------
/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": "This 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 | ]
--------------------------------------------------------------------------------