tov 0.1.0__tar.gz

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.
tov-0.1.0/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ .DS_Store
4
+ dist/
5
+ uv.lock
tov-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tom Dyson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
tov-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.5
2
+ Name: tov
3
+ Version: 0.1.0
4
+ Summary: Rewrite text in a given tone of voice using Gemini, from the command line
5
+ Project-URL: Homepage, https://github.com/tomdyson/tov
6
+ Project-URL: Issues, https://github.com/tomdyson/tov/issues
7
+ Author: Tom Dyson
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: cli,gemini,llm,rewrite,tone of voice
11
+ Classifier: Environment :: Console
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Text Processing
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: google-genai>=1.0
16
+ Description-Content-Type: text/markdown
17
+
18
+ # tov
19
+
20
+ Rewrite text in a given **t**one **o**f **v**oice using Google Gemini, from the command line.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ uv tool install tov
26
+ ```
27
+
28
+ or `pipx install tov`, or `pip install tov`. You'll need a Gemini API key in `GEMINI_API_KEY`.
29
+
30
+ To try it without installing:
31
+
32
+ ```bash
33
+ uvx tov "Plain, friendly British English" "Please be advised that the office is closed."
34
+ ```
35
+
36
+ ### As a single-file script
37
+
38
+ `tov.py` is self-contained: its dependencies are declared inline
39
+ ([PEP 723](https://peps.python.org/pep-0723/)), so [uv](https://docs.astral.sh/uv/)
40
+ installs them automatically when you run it directly.
41
+
42
+ ```bash
43
+ curl -fsSL https://raw.githubusercontent.com/tomdyson/tov/main/tov.py -o ~/.local/bin/tov
44
+ chmod +x ~/.local/bin/tov
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ```
50
+ tov TONE INPUT [MODEL]
51
+ tov INPUT [MODEL] # with TOV_TONE set
52
+ echo "text" | tov TONE [MODEL] # INPUT omitted or "-" reads stdin
53
+ tov --version
54
+ ```
55
+
56
+ - `TONE` and `INPUT` can each be literal text or a path to a file.
57
+ - `MODEL` defaults to `gemini-4-neon` (or `TOV_MODEL` if set).
58
+ - The rewrite streams to stdout with nothing else added; errors go to stderr.
59
+
60
+ ### Examples
61
+
62
+ ```bash
63
+ tov "Warm, plain British English. No jargon." "Per our previous correspondence, your application has been actioned."
64
+
65
+ pbpaste | tov ~/tone-guide.md | pbcopy
66
+
67
+ export TOV_TONE="Formal incident update for enterprise customers"
68
+ tov "server's down again lol" gemini-3.5-flash
69
+ ```
70
+
71
+ A model name is recognised by its shape: a single lowercase hyphenated token such as
72
+ `gemini-3.5-flash`. That lets `tov` work out what you meant:
73
+
74
+ - When input is piped in, `tov TONE MODEL` reads the input from stdin.
75
+ - When `TOV_TONE` is set, `tov INPUT MODEL` uses the tone from the environment, while
76
+ `tov TONE INPUT` (second argument not model-shaped) overrides it.
77
+
78
+ If your input text happens to look like a model name, pass it explicitly with
79
+ `tov TONE - MODEL` and pipe it in.
80
+
81
+ ## Environment
82
+
83
+ | Variable | Purpose |
84
+ | ---------------- | ------------------------------------- |
85
+ | `GEMINI_API_KEY` | Required. Your Gemini API key. |
86
+ | `TOV_TONE` | Default tone guidance (text or path). |
87
+ | `TOV_MODEL` | Default model. |
88
+
89
+ ## Development
90
+
91
+ ```bash
92
+ uv build # builds dist/tov-*.whl and .tar.gz
93
+ uv publish # uploads to PyPI (needs a PyPI token)
94
+ ```
95
+
96
+ Bump `__version__` in `tov.py` before each release.
97
+
98
+ ## Licence
99
+
100
+ MIT — see [LICENSE](LICENSE).
tov-0.1.0/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # tov
2
+
3
+ Rewrite text in a given **t**one **o**f **v**oice using Google Gemini, from the command line.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ uv tool install tov
9
+ ```
10
+
11
+ or `pipx install tov`, or `pip install tov`. You'll need a Gemini API key in `GEMINI_API_KEY`.
12
+
13
+ To try it without installing:
14
+
15
+ ```bash
16
+ uvx tov "Plain, friendly British English" "Please be advised that the office is closed."
17
+ ```
18
+
19
+ ### As a single-file script
20
+
21
+ `tov.py` is self-contained: its dependencies are declared inline
22
+ ([PEP 723](https://peps.python.org/pep-0723/)), so [uv](https://docs.astral.sh/uv/)
23
+ installs them automatically when you run it directly.
24
+
25
+ ```bash
26
+ curl -fsSL https://raw.githubusercontent.com/tomdyson/tov/main/tov.py -o ~/.local/bin/tov
27
+ chmod +x ~/.local/bin/tov
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```
33
+ tov TONE INPUT [MODEL]
34
+ tov INPUT [MODEL] # with TOV_TONE set
35
+ echo "text" | tov TONE [MODEL] # INPUT omitted or "-" reads stdin
36
+ tov --version
37
+ ```
38
+
39
+ - `TONE` and `INPUT` can each be literal text or a path to a file.
40
+ - `MODEL` defaults to `gemini-4-neon` (or `TOV_MODEL` if set).
41
+ - The rewrite streams to stdout with nothing else added; errors go to stderr.
42
+
43
+ ### Examples
44
+
45
+ ```bash
46
+ tov "Warm, plain British English. No jargon." "Per our previous correspondence, your application has been actioned."
47
+
48
+ pbpaste | tov ~/tone-guide.md | pbcopy
49
+
50
+ export TOV_TONE="Formal incident update for enterprise customers"
51
+ tov "server's down again lol" gemini-3.5-flash
52
+ ```
53
+
54
+ A model name is recognised by its shape: a single lowercase hyphenated token such as
55
+ `gemini-3.5-flash`. That lets `tov` work out what you meant:
56
+
57
+ - When input is piped in, `tov TONE MODEL` reads the input from stdin.
58
+ - When `TOV_TONE` is set, `tov INPUT MODEL` uses the tone from the environment, while
59
+ `tov TONE INPUT` (second argument not model-shaped) overrides it.
60
+
61
+ If your input text happens to look like a model name, pass it explicitly with
62
+ `tov TONE - MODEL` and pipe it in.
63
+
64
+ ## Environment
65
+
66
+ | Variable | Purpose |
67
+ | ---------------- | ------------------------------------- |
68
+ | `GEMINI_API_KEY` | Required. Your Gemini API key. |
69
+ | `TOV_TONE` | Default tone guidance (text or path). |
70
+ | `TOV_MODEL` | Default model. |
71
+
72
+ ## Development
73
+
74
+ ```bash
75
+ uv build # builds dist/tov-*.whl and .tar.gz
76
+ uv publish # uploads to PyPI (needs a PyPI token)
77
+ ```
78
+
79
+ Bump `__version__` in `tov.py` before each release.
80
+
81
+ ## Licence
82
+
83
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "tov"
3
+ dynamic = ["version"]
4
+ description = "Rewrite text in a given tone of voice using Gemini, from the command line"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ authors = [{ name = "Tom Dyson" }]
10
+ keywords = ["gemini", "llm", "rewrite", "tone of voice", "cli"]
11
+ classifiers = [
12
+ "Environment :: Console",
13
+ "Programming Language :: Python :: 3",
14
+ "Topic :: Text Processing",
15
+ ]
16
+ dependencies = ["google-genai>=1.0"]
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/tomdyson/tov"
20
+ Issues = "https://github.com/tomdyson/tov/issues"
21
+
22
+ [project.scripts]
23
+ tov = "tov:main"
24
+
25
+ [build-system]
26
+ requires = ["hatchling>=1.27"]
27
+ build-backend = "hatchling.build"
28
+
29
+ [tool.hatch.version]
30
+ path = "tov.py"
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ only-include = ["tov.py"]
34
+
35
+ [tool.hatch.build.targets.sdist]
36
+ include = ["tov.py", "README.md", "LICENSE", "pyproject.toml"]
tov-0.1.0/tov.py ADDED
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env -S uv run --script
2
+ # /// script
3
+ # requires-python = ">=3.10"
4
+ # dependencies = [
5
+ # "google-genai>=1.0",
6
+ # ]
7
+ # ///
8
+ """tov — rewrite text in a given tone of voice using Gemini.
9
+
10
+ Usage:
11
+ tov TONE INPUT [MODEL]
12
+ tov INPUT [MODEL] # with TOV_TONE set
13
+ echo "text" | tov TONE [MODEL] # INPUT omitted or "-" reads stdin
14
+
15
+ tov --version
16
+
17
+ TONE and INPUT may each be literal text or a path to a file.
18
+ """
19
+
20
+ __version__ = "0.1.0"
21
+
22
+ import os
23
+ import re
24
+ import sys
25
+ from pathlib import Path
26
+ from typing import NoReturn
27
+
28
+ from google import genai
29
+ from google.genai import errors, types
30
+
31
+ DEFAULT_MODEL = "gemini-4-neon"
32
+
33
+ SYSTEM_PROMPT = """You are an editor who rewrites text to match a tone-of-voice guide.
34
+
35
+ Rules:
36
+ - Rewrite the user's text so it follows the tone guidance below.
37
+ - Preserve the meaning, facts, names, numbers, links and overall structure \
38
+ (paragraphs, lists, headings) unless the guidance says otherwise.
39
+ - Do not add new claims or remove substantive content.
40
+ - Output ONLY the rewritten text: no preamble, no explanation, no quotation marks \
41
+ around it, no code fences.
42
+
43
+ <tone_guidance>
44
+ {tone}
45
+ </tone_guidance>"""
46
+
47
+
48
+ def usage(msg: str) -> NoReturn:
49
+ print(f"tov: {msg}\n", file=sys.stderr)
50
+ print(__doc__.strip(), file=sys.stderr)
51
+ sys.exit(2)
52
+
53
+
54
+ def resolve(value: str) -> str:
55
+ """Return the file's contents if value is a path to an existing file, else value."""
56
+ if value == "-":
57
+ return sys.stdin.read()
58
+ if len(value) < 1024 and "\n" not in value:
59
+ p = Path(value).expanduser()
60
+ if p.is_file():
61
+ return p.read_text()
62
+ return value
63
+
64
+
65
+ def looks_like_model(value: str) -> bool:
66
+ """Model IDs are single lowercase hyphenated tokens, e.g. gemini-4-neon."""
67
+ return bool(re.fullmatch(r"(models/)?[a-z][a-z0-9.]*(-[a-z0-9.]+)+", value))
68
+
69
+
70
+ def parse_args(argv: list[str]) -> tuple[str, str, str]:
71
+ if any(a in ("-h", "--help") for a in argv):
72
+ print(__doc__.strip())
73
+ sys.exit(0)
74
+ if argv[:1] in (["-V"], ["--version"]):
75
+ print(f"tov {__version__}")
76
+ sys.exit(0)
77
+
78
+ env_tone = os.environ.get("TOV_TONE")
79
+ args = list(argv)
80
+
81
+ # With TOV_TONE set, positionals are INPUT [MODEL] — unless there are two
82
+ # and the second doesn't look like a model name, in which case the user
83
+ # passed TONE INPUT explicitly and that overrides the environment.
84
+ if env_tone is not None and (
85
+ len(args) <= 1 or (len(args) == 2 and looks_like_model(args[1]))
86
+ ):
87
+ tone = env_tone
88
+ elif args:
89
+ tone = args.pop(0)
90
+ else:
91
+ usage("no tone given (pass it as the first argument or set TOV_TONE)")
92
+
93
+ if len(args) > 2:
94
+ usage("too many arguments")
95
+
96
+ # `echo text | tov TONE MODEL`: a lone model-like argument with piped
97
+ # stdin is the model, and the input comes from stdin.
98
+ if len(args) == 1 and looks_like_model(args[0]) and not sys.stdin.isatty():
99
+ args.insert(0, "-")
100
+
101
+ input_arg = args[0] if args else "-"
102
+ model = args[1] if len(args) > 1 else os.environ.get("TOV_MODEL", DEFAULT_MODEL)
103
+
104
+ if input_arg == "-" and sys.stdin.isatty():
105
+ usage("no input given (pass it as an argument or pipe it on stdin)")
106
+
107
+ tone_text = resolve(tone).strip()
108
+ input_text = resolve(input_arg).strip()
109
+ if not tone_text:
110
+ usage("tone is empty")
111
+ if not input_text:
112
+ usage("input is empty")
113
+ return tone_text, input_text, model
114
+
115
+
116
+ def main() -> None:
117
+ tone, text, model = parse_args(sys.argv[1:])
118
+
119
+ api_key = os.environ.get("GEMINI_API_KEY")
120
+ if not api_key:
121
+ print("tov: GEMINI_API_KEY is not set", file=sys.stderr)
122
+ sys.exit(1)
123
+
124
+ # Use GEMINI_API_KEY only; stop the SDK preferring GOOGLE_API_KEY if set.
125
+ os.environ.pop("GOOGLE_API_KEY", None)
126
+ client = genai.Client(api_key=api_key)
127
+ ended_with_newline = True
128
+ try:
129
+ stream = client.models.generate_content_stream(
130
+ model=model,
131
+ contents=text,
132
+ config=types.GenerateContentConfig(
133
+ system_instruction=SYSTEM_PROMPT.format(tone=tone),
134
+ ),
135
+ )
136
+ for chunk in stream:
137
+ if chunk.text:
138
+ sys.stdout.write(chunk.text)
139
+ sys.stdout.flush()
140
+ ended_with_newline = chunk.text.endswith("\n")
141
+ if not ended_with_newline:
142
+ sys.stdout.write("\n")
143
+ except errors.APIError as e:
144
+ if not ended_with_newline:
145
+ print(file=sys.stderr)
146
+ print(f"tov: Gemini API error ({model}): {e}", file=sys.stderr)
147
+ sys.exit(1)
148
+ except KeyboardInterrupt:
149
+ sys.exit(130)
150
+
151
+
152
+ if __name__ == "__main__":
153
+ main()