tov 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.
- tov-0.1.0.dist-info/METADATA +100 -0
- tov-0.1.0.dist-info/RECORD +6 -0
- tov-0.1.0.dist-info/WHEEL +4 -0
- tov-0.1.0.dist-info/entry_points.txt +2 -0
- tov-0.1.0.dist-info/licenses/LICENSE +21 -0
- tov.py +153 -0
|
@@ -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).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
tov.py,sha256=eKS1KjqtTiYj0k9TLPwORzqEZgUy4bf1MeIu9flHQ4c,4677
|
|
2
|
+
tov-0.1.0.dist-info/METADATA,sha256=egFPnVBXzNl3iEu8OktC3G3mMWfRPz1LBd8ctbMLwEo,3052
|
|
3
|
+
tov-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
4
|
+
tov-0.1.0.dist-info/entry_points.txt,sha256=EiwxiDO7Z9ZxrTfV3dqInD2zV7CYIbrcBwudKFG9bVA,33
|
|
5
|
+
tov-0.1.0.dist-info/licenses/LICENSE,sha256=LApbfq1RWzaNTpFWdFtipc-5ZC03Nlw0DbJHR4E_Zvw,1066
|
|
6
|
+
tov-0.1.0.dist-info/RECORD,,
|
|
@@ -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.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()
|