aistudio-takeout 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import sys
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
if len(sys.argv) < 2 or sys.argv[1] in ["-h", "--help"]:
|
|
11
|
+
print(
|
|
12
|
+
"aistudio-takeout - Convert Google AI Studio chats to Markdown\n\n"
|
|
13
|
+
"Usage: aistudio-takeout <dir> [outdir]\n\n"
|
|
14
|
+
"Output:\n"
|
|
15
|
+
" <outdir>/*.chat.md: Markdown files"
|
|
16
|
+
)
|
|
17
|
+
sys.exit(0)
|
|
18
|
+
|
|
19
|
+
src = Path(sys.argv[1]).resolve()
|
|
20
|
+
out = Path(sys.argv[2] if len(sys.argv) > 2 else "aistudio").resolve()
|
|
21
|
+
|
|
22
|
+
if not src.exists():
|
|
23
|
+
sys.exit(f"Error: {src} not found")
|
|
24
|
+
if not src.is_dir():
|
|
25
|
+
sys.exit(f"Error: {src} is not a directory")
|
|
26
|
+
|
|
27
|
+
print(f"Converting {src.name}...")
|
|
28
|
+
out.mkdir(exist_ok=True)
|
|
29
|
+
|
|
30
|
+
files = [f for f in src.iterdir() if f.is_file() and not f.name.startswith(".")]
|
|
31
|
+
n = 0
|
|
32
|
+
|
|
33
|
+
for f in sorted(files):
|
|
34
|
+
try:
|
|
35
|
+
data = json.loads(f.read_text(encoding="utf-8"))
|
|
36
|
+
except (json.JSONDecodeError, UnicodeDecodeError):
|
|
37
|
+
continue
|
|
38
|
+
|
|
39
|
+
chunks = data.get("chunkedPrompt", {}).get("chunks", [])
|
|
40
|
+
if not chunks:
|
|
41
|
+
continue
|
|
42
|
+
|
|
43
|
+
settings = data.get("runSettings", {})
|
|
44
|
+
model = settings.get("model", "unknown").replace("models/", "")
|
|
45
|
+
mtime = datetime.fromtimestamp(f.stat().st_mtime)
|
|
46
|
+
created = mtime.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
|
47
|
+
date_prefix = mtime.strftime("%Y-%m-%d")
|
|
48
|
+
|
|
49
|
+
title = f.stem
|
|
50
|
+
md = [
|
|
51
|
+
f"---\nprovider: aistudio\ncreated: {created}\nmodel: {model}\n---\n\n# {title}\n"
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
for chunk in chunks:
|
|
55
|
+
role = chunk.get("role", "unknown")
|
|
56
|
+
text = chunk.get("text", "")
|
|
57
|
+
if not text and "parts" in chunk:
|
|
58
|
+
text = chunk["parts"][0].get("text", "") if chunk["parts"] else ""
|
|
59
|
+
md.append(f"\n## {'User' if role == 'user' else 'Model'}\n\n{text}\n")
|
|
60
|
+
|
|
61
|
+
safe = (
|
|
62
|
+
re.sub(r"[^a-zA-Z0-9\u4e00-\u9fff]+", "-", title).strip("-") or "untitled"
|
|
63
|
+
)
|
|
64
|
+
(out / f"{date_prefix}-{safe}.chat.md").write_text(
|
|
65
|
+
"".join(md), encoding="utf-8"
|
|
66
|
+
)
|
|
67
|
+
n += 1
|
|
68
|
+
print(f"✓ {date_prefix}-{safe}.chat.md")
|
|
69
|
+
|
|
70
|
+
print(f"\nDone! {n} chats → {out}/")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
main()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: aistudio-takeout
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Convert Google AI Studio chats to Markdown
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Project-URL: Repository, https://github.com/mefengl/aistudio-takeout
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# aistudio-takeout
|
|
10
|
+
|
|
11
|
+
Convert Google AI Studio chats to Markdown.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install aistudio-takeout
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
aistudio-takeout "Google AI Studio" # Creates aistudio/*.chat.md
|
|
23
|
+
aistudio-takeout "Google AI Studio" output # Creates output/*.chat.md
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Output:
|
|
27
|
+
```
|
|
28
|
+
aistudio/
|
|
29
|
+
├── 2025-01-15-chat-title.chat.md
|
|
30
|
+
├── 2025-01-20-another-chat.chat.md
|
|
31
|
+
└── ...
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Requirements
|
|
35
|
+
|
|
36
|
+
- Python 3.8+
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
MIT
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
aistudio_takeout/__init__.py,sha256=TdcX52sGE2CvEpwMmECi-H9_n46mTyvpRi3jjfdhKu4,2301
|
|
2
|
+
aistudio_takeout-0.1.0.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
|
|
3
|
+
aistudio_takeout-0.1.0.dist-info/entry_points.txt,sha256=D6W8qRXs4pS6Exx-EiuVFiHqALaFyn9rnmrG3RcKOx8,60
|
|
4
|
+
aistudio_takeout-0.1.0.dist-info/METADATA,sha256=6Tesyda2mVo3Y03N9EyJAJuE_pt62kpounynTVCPygo,706
|
|
5
|
+
aistudio_takeout-0.1.0.dist-info/RECORD,,
|