writing-machine 0.0.1__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.
- writing_machine-0.0.1/LICENSE +21 -0
- writing_machine-0.0.1/MANIFEST.in +1 -0
- writing_machine-0.0.1/PKG-INFO +41 -0
- writing_machine-0.0.1/README.md +18 -0
- writing_machine-0.0.1/pyproject.toml +36 -0
- writing_machine-0.0.1/setup.cfg +4 -0
- writing_machine-0.0.1/src/writing_machine/__init__.py +19 -0
- writing_machine-0.0.1/src/writing_machine/cli.py +119 -0
- writing_machine-0.0.1/src/writing_machine/config.py +22 -0
- writing_machine-0.0.1/src/writing_machine/githf.py +97 -0
- writing_machine-0.0.1/src/writing_machine/machina.yaml +3 -0
- writing_machine-0.0.1/src/writing_machine/machine.py +87 -0
- writing_machine-0.0.1/src/writing_machine.egg-info/PKG-INFO +41 -0
- writing_machine-0.0.1/src/writing_machine.egg-info/SOURCES.txt +16 -0
- writing_machine-0.0.1/src/writing_machine.egg-info/dependency_links.txt +1 -0
- writing_machine-0.0.1/src/writing_machine.egg-info/entry_points.txt +2 -0
- writing_machine-0.0.1/src/writing_machine.egg-info/requires.txt +7 -0
- writing_machine-0.0.1/src/writing_machine.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexander Fedotov
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include src/writing_machine/*.yaml
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: writing-machine
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Machine that writes texts.
|
|
5
|
+
Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/writing-machine/writing-machine
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/writing-machine/writing-machine/issues
|
|
8
|
+
Keywords: writing-machine
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: electroid>=0.0.16
|
|
16
|
+
Requires-Dist: opehaina>=0.0.1
|
|
17
|
+
Requires-Dist: PyGithub>=2.6.0
|
|
18
|
+
Requires-Dist: PyYAML>=6.0.1
|
|
19
|
+
Requires-Dist: urllib3>=2.0.4
|
|
20
|
+
Requires-Dist: requests>=2.32.3
|
|
21
|
+
Requires-Dist: click>=8.3.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Writing Machine
|
|
25
|
+
A Machine that writes texts.
|
|
26
|
+
```bash
|
|
27
|
+
echo '[{"role": "user", "content": "Write an explanatory text..."}]' \
|
|
28
|
+
| uvx writing-machine \
|
|
29
|
+
--provider-api-key=sk-ant-api... \
|
|
30
|
+
--github-token=ghp_... \
|
|
31
|
+
--mode=single
|
|
32
|
+
```
|
|
33
|
+
Or:
|
|
34
|
+
```bash
|
|
35
|
+
pip install writing-machine
|
|
36
|
+
```
|
|
37
|
+
Then:
|
|
38
|
+
```Python
|
|
39
|
+
# Python
|
|
40
|
+
import writing_machine
|
|
41
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Writing Machine
|
|
2
|
+
A Machine that writes texts.
|
|
3
|
+
```bash
|
|
4
|
+
echo '[{"role": "user", "content": "Write an explanatory text..."}]' \
|
|
5
|
+
| uvx writing-machine \
|
|
6
|
+
--provider-api-key=sk-ant-api... \
|
|
7
|
+
--github-token=ghp_... \
|
|
8
|
+
--mode=single
|
|
9
|
+
```
|
|
10
|
+
Or:
|
|
11
|
+
```bash
|
|
12
|
+
pip install writing-machine
|
|
13
|
+
```
|
|
14
|
+
Then:
|
|
15
|
+
```Python
|
|
16
|
+
# Python
|
|
17
|
+
import writing_machine
|
|
18
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=67.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
[project]
|
|
5
|
+
name = "writing-machine"
|
|
6
|
+
version = "0.0.1"
|
|
7
|
+
authors = [
|
|
8
|
+
{name="Machina Ratiocinatrix", email="machina.ratio@gmail.com"},
|
|
9
|
+
]
|
|
10
|
+
description = "A Machine that writes texts."
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
classifiers=[
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
keywords = ["writing-machine"]
|
|
20
|
+
|
|
21
|
+
dependencies = [
|
|
22
|
+
"electroid >= 0.0.16",
|
|
23
|
+
"opehaina >= 0.0.1",
|
|
24
|
+
"PyGithub >= 2.6.0",
|
|
25
|
+
"PyYAML >= 6.0.1",
|
|
26
|
+
"urllib3 >= 2.0.4",
|
|
27
|
+
"requests >= 2.32.3",
|
|
28
|
+
"click >= 8.3.0"
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
writing-machine = "writing_machine.cli:run"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
"Homepage" = "https://github.com/writing-machine/writing-machine"
|
|
36
|
+
"Bug Tracker" = "https://github.com/writing-machine/writing-machine/issues"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Python
|
|
3
|
+
|
|
4
|
+
"""Copyright (c) Alexander Fedotov.
|
|
5
|
+
This source code is licensed under the license found in the
|
|
6
|
+
LICENSE file in the root directory of this source tree.
|
|
7
|
+
"""
|
|
8
|
+
from .config import settings
|
|
9
|
+
from .machine import machine
|
|
10
|
+
from .githf import connect_to_repo, read_file
|
|
11
|
+
|
|
12
|
+
config = dict()
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
'machine',
|
|
16
|
+
'connect_to_repo',
|
|
17
|
+
'read_file',
|
|
18
|
+
'settings'
|
|
19
|
+
]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Python
|
|
3
|
+
|
|
4
|
+
"""Copyright (c) Alexander Fedotov.
|
|
5
|
+
This source code is licensed under the license found in the
|
|
6
|
+
LICENSE file in the root directory of this source tree.
|
|
7
|
+
"""
|
|
8
|
+
from os import environ
|
|
9
|
+
from .config import settings
|
|
10
|
+
import sys
|
|
11
|
+
import json
|
|
12
|
+
import click
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@click.command()
|
|
16
|
+
@click.option('--provider-api-key', 'provider_api_key', envvar='PROVIDER_API_KEY',
|
|
17
|
+
default='', help='Language Model API provider key.')
|
|
18
|
+
@click.option('--github-token', 'github_token', envvar='GITHUB_TOKEN',
|
|
19
|
+
default='', help='GitHub API token for private repo access.')
|
|
20
|
+
@click.option('--mode', type=click.Choice(['single', 'daemon']),
|
|
21
|
+
default='single',
|
|
22
|
+
help='single: one-shot stdin→stdout. '
|
|
23
|
+
'interactive: line-delimited JSON loop.')
|
|
24
|
+
def run(provider_api_key, github_token, mode):
|
|
25
|
+
"""writing-machine: an AI agent communicating via stdin/stdout.
|
|
26
|
+
|
|
27
|
+
In 'single' mode (default): reads a full JSON array from stdin,
|
|
28
|
+
responds once, and exits.
|
|
29
|
+
|
|
30
|
+
In 'daemon' mode: reads one JSON line at a time from stdin,
|
|
31
|
+
responds with one JSON line on stdout, and loops until EOF or SIGINT.
|
|
32
|
+
"""
|
|
33
|
+
# Set environment variables so electroid and githf pick them up
|
|
34
|
+
if provider_api_key:
|
|
35
|
+
if provider_api_key.startswith('sk-proj-'):
|
|
36
|
+
settings['provider'] = 'OpenAI'
|
|
37
|
+
environ['OPENAI_API_KEY'] = provider_api_key
|
|
38
|
+
elif provider_api_key.startswith('sk-ant-'):
|
|
39
|
+
settings['provider'] = 'Anthropic'
|
|
40
|
+
environ['ANTHROPIC_API_KEY'] = provider_api_key
|
|
41
|
+
elif provider_api_key.startswith('AIzaSy'):
|
|
42
|
+
settings['provider'] = 'Gemini'
|
|
43
|
+
environ['GEMINI_API_KEY'] = provider_api_key
|
|
44
|
+
elif provider_api_key.startswith('gsk_'):
|
|
45
|
+
settings['provider'] = 'Groq'
|
|
46
|
+
environ['GROQ_API_KEY'] = provider_api_key
|
|
47
|
+
elif provider_api_key.startswith('xai-'):
|
|
48
|
+
settings['provider'] = 'XAI'
|
|
49
|
+
environ['XAI_API_KEY'] = provider_api_key
|
|
50
|
+
elif provider_api_key.startswith('LLM|'):
|
|
51
|
+
settings['provider'] = 'Meta'
|
|
52
|
+
environ['META_API_KEY'] = provider_api_key
|
|
53
|
+
else:
|
|
54
|
+
if settings['provider'] == '':
|
|
55
|
+
raise ValueError(f"Unrecognized API key prefix and no provider specified.")
|
|
56
|
+
if github_token:
|
|
57
|
+
environ['GITHUB_TOKEN'] = github_token
|
|
58
|
+
|
|
59
|
+
from .machine import machine
|
|
60
|
+
|
|
61
|
+
if mode == 'daemon':
|
|
62
|
+
_run_daemon(machine)
|
|
63
|
+
else:
|
|
64
|
+
_run_single(machine)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _run_single(machine):
|
|
68
|
+
"""One-shot mode: read full JSON from stdin, respond, exit."""
|
|
69
|
+
try:
|
|
70
|
+
messages = json.load(sys.stdin)
|
|
71
|
+
except json.JSONDecodeError as e:
|
|
72
|
+
print(f"Error: invalid JSON on stdin: {e}", file=sys.stderr)
|
|
73
|
+
sys.exit(1)
|
|
74
|
+
|
|
75
|
+
if not isinstance(messages, list):
|
|
76
|
+
print("Error: stdin must contain a JSON array of messages.",
|
|
77
|
+
file=sys.stderr)
|
|
78
|
+
sys.exit(1)
|
|
79
|
+
|
|
80
|
+
text, thoughts = machine(messages)
|
|
81
|
+
json.dump([text, thoughts], sys.stdout)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _run_daemon(machine):
|
|
85
|
+
"""Daemon: line-delimited JSON loop.
|
|
86
|
+
|
|
87
|
+
Each line on stdin is a JSON array of messages.
|
|
88
|
+
Each response is a JSON array [text, thoughts] followed by newline.
|
|
89
|
+
Loops until SIGINT on stdin.
|
|
90
|
+
"""
|
|
91
|
+
print("daemon", file=sys.stderr)
|
|
92
|
+
try:
|
|
93
|
+
# Loop blocks until input is available on stdin
|
|
94
|
+
for line in sys.stdin:
|
|
95
|
+
line = line.strip()
|
|
96
|
+
if not line:
|
|
97
|
+
continue
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
messages = json.loads(line)
|
|
101
|
+
except json.JSONDecodeError as e:
|
|
102
|
+
print(f"Error: invalid JSON: {e}", file=sys.stderr)
|
|
103
|
+
continue
|
|
104
|
+
|
|
105
|
+
if not isinstance(messages, list):
|
|
106
|
+
print("Error: expected a JSON array of messages.",
|
|
107
|
+
file=sys.stderr)
|
|
108
|
+
continue
|
|
109
|
+
|
|
110
|
+
text, thoughts = machine(messages)
|
|
111
|
+
json.dump([text, thoughts], sys.stdout)
|
|
112
|
+
sys.stdout.write('\n')
|
|
113
|
+
sys.stdout.flush()
|
|
114
|
+
except KeyboardInterrupt:
|
|
115
|
+
sys.exit(0)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == '__main__':
|
|
119
|
+
run()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Python
|
|
3
|
+
|
|
4
|
+
"""Copyright (c) Alexander Fedotov.
|
|
5
|
+
This source code is licensed under the license found in the
|
|
6
|
+
LICENSE file in the root directory of this source tree.
|
|
7
|
+
"""
|
|
8
|
+
from os import environ
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
settings = dict(
|
|
12
|
+
github_token = environ.get('GITHUB_TOKEN', ''),
|
|
13
|
+
github_name = environ.get('GITHUB_NAME', ''),
|
|
14
|
+
github_email = environ.get('GITHUB_EMAIL', ''),
|
|
15
|
+
provider_api_key = environ.get('PROVIDER_API_KEY', ''),
|
|
16
|
+
provider = environ.get('PROVIDER', ''),
|
|
17
|
+
machine_organization_name = environ.get('MACHINE_ORGANIZATION_NAME', 'writing-machine'),
|
|
18
|
+
private_repo_with_text = environ.get('PRIVATE_REPO_WITH_TEXT','writing_machine'),
|
|
19
|
+
system_prompt_file = environ.get('SYSTEM_PROMPT_FILE', 'machina.yaml'),
|
|
20
|
+
name = '',
|
|
21
|
+
instructions = ''
|
|
22
|
+
)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Python
|
|
3
|
+
|
|
4
|
+
"""Copyright (c) Alexander Fedotov.
|
|
5
|
+
This source code is licensed under the license found in the
|
|
6
|
+
LICENSE file in the root directory of this source tree.
|
|
7
|
+
"""
|
|
8
|
+
from os import environ
|
|
9
|
+
from github import Github, UnknownObjectException
|
|
10
|
+
from urllib3 import disable_warnings
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
github_token = environ.get('GITHUB_TOKEN', '')
|
|
14
|
+
github_name = environ.get('GITHUB_NAME', '')
|
|
15
|
+
github_email = environ.get('GITHUB_EMAIL', '')
|
|
16
|
+
|
|
17
|
+
# The useless urllib3 warning is too maddening for an ordinary human being.
|
|
18
|
+
disable_warnings()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Repo
|
|
22
|
+
def connect_to_repo(organization=None,
|
|
23
|
+
repository_name=None,
|
|
24
|
+
private=False):
|
|
25
|
+
"""
|
|
26
|
+
Establish a connection with a GitHub repository.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
organization (str, optional): The name of the organization. If not provided,
|
|
30
|
+
the repository is assumed to be owned by the authenticated user.
|
|
31
|
+
repository_name (str): The name of the repository.
|
|
32
|
+
private (bool, optional): Whether the repository is private. Defaults to False.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
github.Repository.Repository: The GitHub repository object if the connection is successful.
|
|
36
|
+
None: If the connection fails.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
github.UnknownObjectException: If the repository does not exist.
|
|
40
|
+
|
|
41
|
+
Note:
|
|
42
|
+
The function requires the following environment variables to be set:
|
|
43
|
+
- GITHUB_TOKEN: The personal access token for authentication.
|
|
44
|
+
- GITHUB_NAME: The name of the authenticated user.
|
|
45
|
+
- GITHUB_EMAIL: The email of the authenticated user.
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
gh = Github(github_token, verify=False)
|
|
50
|
+
if organization:
|
|
51
|
+
org = gh.get_organization(organization)
|
|
52
|
+
try:
|
|
53
|
+
repo = org.get_repo(f'{repository_name}')
|
|
54
|
+
except UnknownObjectException:
|
|
55
|
+
# print('Can not connect YOU to this repo in this organization')
|
|
56
|
+
repo = None
|
|
57
|
+
return repo
|
|
58
|
+
else:
|
|
59
|
+
user = gh.get_user()
|
|
60
|
+
try:
|
|
61
|
+
repo = user.get_repo(repository_name)
|
|
62
|
+
except UnknownObjectException:
|
|
63
|
+
# print('Can not connect YOU to this repo')
|
|
64
|
+
repo = None
|
|
65
|
+
return repo
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def read_file(repository,
|
|
69
|
+
file_path):
|
|
70
|
+
"""
|
|
71
|
+
Read the contents of a file in a GitHub repository.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
repository (github.Repository.Repository): The GitHub repository object.
|
|
75
|
+
file_path (str): The path to the file in the repository, formatted as
|
|
76
|
+
'directory_in_repo/subdirectory/file.ext'.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
str: The contents of the file as a string. If the file does not exist, an empty string is returned.
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
github.UnknownObjectException: If the file does not exist in the repository.
|
|
83
|
+
|
|
84
|
+
Note:
|
|
85
|
+
This function assumes that the repository object has already been authenticated and connected.
|
|
86
|
+
"""
|
|
87
|
+
try:
|
|
88
|
+
# Get the file if it exists
|
|
89
|
+
ingested_file = repository.get_contents(file_path)
|
|
90
|
+
content = ingested_file.decoded_content.decode("utf-8")
|
|
91
|
+
|
|
92
|
+
except UnknownObjectException:
|
|
93
|
+
# The file doesn't exist
|
|
94
|
+
# print('The file does not exist')
|
|
95
|
+
content = ''
|
|
96
|
+
|
|
97
|
+
return content
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Python
|
|
3
|
+
|
|
4
|
+
"""Copyright (c) Alexander Fedotov.
|
|
5
|
+
This source code is licensed under the license found in the
|
|
6
|
+
LICENSE file in the root directory of this source tree.
|
|
7
|
+
"""
|
|
8
|
+
from os import environ, path
|
|
9
|
+
from .config import settings
|
|
10
|
+
import sys
|
|
11
|
+
import yaml
|
|
12
|
+
from . import githf # from .
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _fetch_instructions():
|
|
16
|
+
"""Retrieve the system prompt from a private GitHub repo.
|
|
17
|
+
Falls back to the local machina.yaml if GitHub is unreachable.
|
|
18
|
+
Returns the 'description' field from the YAML as the system prompt string.
|
|
19
|
+
"""
|
|
20
|
+
try:
|
|
21
|
+
repo = githf.connect_to_repo(
|
|
22
|
+
organization=settings['machine_organization_name'],
|
|
23
|
+
repository_name=settings['private_repo_with_text'],
|
|
24
|
+
private=True
|
|
25
|
+
)
|
|
26
|
+
raw_yaml = githf.read_file(
|
|
27
|
+
repository=repo,
|
|
28
|
+
file_path=settings['system_prompt_file']
|
|
29
|
+
)
|
|
30
|
+
except Exception as e:
|
|
31
|
+
print(f"Warning: could not fetch prompt from GitHub: {e}",
|
|
32
|
+
file=sys.stderr)
|
|
33
|
+
local_path = path.join(path.dirname(__file__), 'machina.yaml')
|
|
34
|
+
with open(local_path, 'r') as f:
|
|
35
|
+
raw_yaml = f.read()
|
|
36
|
+
|
|
37
|
+
# Parse whatever you've gotten.
|
|
38
|
+
parsed = yaml.safe_load(raw_yaml)
|
|
39
|
+
name = parsed.get('name')
|
|
40
|
+
settings['name'] = name
|
|
41
|
+
instructions = parsed.get('description', 'You are a helpful assistant.')
|
|
42
|
+
settings['instructions'] = instructions
|
|
43
|
+
return name, instructions
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def machine(messages):
|
|
47
|
+
"""Core agent logic.
|
|
48
|
+
|
|
49
|
+
1. Fetches the system prompt from a private GitHub repo.
|
|
50
|
+
2. Calls Anthropic via electroid.cloud() with the messages.
|
|
51
|
+
3. Returns (text, thoughts) tuple.
|
|
52
|
+
"""
|
|
53
|
+
# Fetch the confidential system prompt
|
|
54
|
+
name, system_prompt = _fetch_instructions()
|
|
55
|
+
|
|
56
|
+
# Load an appropriate library and query the API.
|
|
57
|
+
provider = settings['provider']
|
|
58
|
+
if provider == 'OpenAI':
|
|
59
|
+
# Call OpenAI API via opehaina
|
|
60
|
+
import opehaina
|
|
61
|
+
text, thoughts = opehaina.stream(
|
|
62
|
+
messages=messages,
|
|
63
|
+
system=system_prompt,
|
|
64
|
+
max_tokens=100000
|
|
65
|
+
)
|
|
66
|
+
return text, thoughts
|
|
67
|
+
|
|
68
|
+
elif provider == 'Anthropic':
|
|
69
|
+
# Call the Anthropic API via electroid
|
|
70
|
+
import electroid
|
|
71
|
+
text, thoughts = electroid.stream(
|
|
72
|
+
messages=messages,
|
|
73
|
+
system=system_prompt,
|
|
74
|
+
max_tokens=100000
|
|
75
|
+
)
|
|
76
|
+
return text, thoughts
|
|
77
|
+
|
|
78
|
+
elif provider == 'Groq':
|
|
79
|
+
...
|
|
80
|
+
elif provider == 'Xai':
|
|
81
|
+
...
|
|
82
|
+
elif provider == 'Meta':
|
|
83
|
+
...
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == '__main__':
|
|
87
|
+
machine([])
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: writing-machine
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Machine that writes texts.
|
|
5
|
+
Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/writing-machine/writing-machine
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/writing-machine/writing-machine/issues
|
|
8
|
+
Keywords: writing-machine
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: electroid>=0.0.16
|
|
16
|
+
Requires-Dist: opehaina>=0.0.1
|
|
17
|
+
Requires-Dist: PyGithub>=2.6.0
|
|
18
|
+
Requires-Dist: PyYAML>=6.0.1
|
|
19
|
+
Requires-Dist: urllib3>=2.0.4
|
|
20
|
+
Requires-Dist: requests>=2.32.3
|
|
21
|
+
Requires-Dist: click>=8.3.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Writing Machine
|
|
25
|
+
A Machine that writes texts.
|
|
26
|
+
```bash
|
|
27
|
+
echo '[{"role": "user", "content": "Write an explanatory text..."}]' \
|
|
28
|
+
| uvx writing-machine \
|
|
29
|
+
--provider-api-key=sk-ant-api... \
|
|
30
|
+
--github-token=ghp_... \
|
|
31
|
+
--mode=single
|
|
32
|
+
```
|
|
33
|
+
Or:
|
|
34
|
+
```bash
|
|
35
|
+
pip install writing-machine
|
|
36
|
+
```
|
|
37
|
+
Then:
|
|
38
|
+
```Python
|
|
39
|
+
# Python
|
|
40
|
+
import writing_machine
|
|
41
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/writing_machine/__init__.py
|
|
6
|
+
src/writing_machine/cli.py
|
|
7
|
+
src/writing_machine/config.py
|
|
8
|
+
src/writing_machine/githf.py
|
|
9
|
+
src/writing_machine/machina.yaml
|
|
10
|
+
src/writing_machine/machine.py
|
|
11
|
+
src/writing_machine.egg-info/PKG-INFO
|
|
12
|
+
src/writing_machine.egg-info/SOURCES.txt
|
|
13
|
+
src/writing_machine.egg-info/dependency_links.txt
|
|
14
|
+
src/writing_machine.egg-info/entry_points.txt
|
|
15
|
+
src/writing_machine.egg-info/requires.txt
|
|
16
|
+
src/writing_machine.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
writing_machine
|