answering-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.
@@ -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/answering_machine/*.yaml
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: answering-machine
3
+ Version: 0.0.1
4
+ Summary: Machine description
5
+ Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>
6
+ Project-URL: Homepage, https://github.com/org_name/answering_machine
7
+ Project-URL: Bug Tracker, https://github.com/org_name/answering_machine/issues
8
+ Keywords: answering-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: PyGithub>=2.6.0
17
+ Requires-Dist: PyYAML>=6.0.1
18
+ Requires-Dist: urllib3>=2.0.4
19
+ Requires-Dist: requests>=2.32.3
20
+ Requires-Dist: click>=8.3.0
21
+ Dynamic: license-file
22
+
23
+ # Answering Machine
24
+ A machine that answers questions.
25
+ <pre>
26
+ pip install answering-machine
27
+ </pre>
28
+ Then:
29
+ ```Python
30
+ # Python
31
+ import answering_machine
32
+ ```
33
+ Or:
34
+ <pre>
35
+ uvx answering-machine [ARGUMENT] [OPTION]
36
+ </pre>
@@ -0,0 +1,14 @@
1
+ # Answering Machine
2
+ A machine that answers questions.
3
+ <pre>
4
+ pip install answering-machine
5
+ </pre>
6
+ Then:
7
+ ```Python
8
+ # Python
9
+ import answering_machine
10
+ ```
11
+ Or:
12
+ <pre>
13
+ uvx answering-machine [ARGUMENT] [OPTION]
14
+ </pre>
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools>=67.0"]
3
+ build-backend = "setuptools.build_meta"
4
+ [project]
5
+ name = "answering-machine"
6
+ version = "0.0.1"
7
+ authors = [
8
+ {name="Machina Ratiocinatrix", email="machina.ratio@gmail.com"},
9
+ ]
10
+ description = "Machine description"
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 = ["answering-machine"]
20
+
21
+ dependencies = [
22
+ "electroid >= 0.0.16",
23
+ "PyGithub >= 2.6.0",
24
+ "PyYAML >= 6.0.1",
25
+ "urllib3 >= 2.0.4",
26
+ "requests >= 2.32.3",
27
+ "click >= 8.3.0"
28
+ ]
29
+
30
+ [project.scripts]
31
+ answering-machine = "answering_machine.cli:main"
32
+
33
+ [project.urls]
34
+ "Homepage" = "https://github.com/org_name/answering_machine"
35
+ "Bug Tracker" = "https://github.com/org_name/answering_machine/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,15 @@
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 .machine import machine
9
+ from .githf import connect_to_repo, read_file
10
+
11
+ __all__ = [
12
+ 'machine',
13
+ 'connect_to_repo',
14
+ 'read_file'
15
+ ]
@@ -0,0 +1,98 @@
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
+ import os
9
+ import sys
10
+ import json
11
+ import click
12
+
13
+
14
+ @click.command()
15
+ @click.option('--PROVIDER_API_KEY', envvar='PROVIDER_API_KEY',
16
+ default='', help='Language Model API provider key.')
17
+ @click.option('--GITHUB_TOKEN', envvar='GITHUB_TOKEN',
18
+ default='', help='GitHub API token for private repo access.')
19
+ @click.option('--mode', type=click.Choice(['single', 'daemon']),
20
+ default='single',
21
+ help='single: one-shot stdin→stdout. '
22
+ 'interactive: line-delimited JSON loop.')
23
+ def main(provider_api_key, github_token, mode):
24
+ """Generalizing-Machine: an AI agent communicating via stdin/stdout.
25
+
26
+ In 'single' mode (default): reads a full JSON array from stdin,
27
+ responds once, and exits.
28
+
29
+ In 'interactive' mode: reads one JSON line at a time from stdin,
30
+ responds with one JSON line on stdout, and loops until EOF.
31
+ """
32
+ # Set environment variables so electroid and githf pick them up
33
+ if provider_api_key:
34
+ os.environ['PROVIDER_API_KEY'] = provider_api_key
35
+ if github_token:
36
+ os.environ['GITHUB_TOKEN'] = github_token
37
+
38
+ from .machine import machine
39
+
40
+ if mode == 'daemon':
41
+ _run_daemon(machine)
42
+ else:
43
+ _run_single(machine)
44
+
45
+
46
+ def _run_single(machine):
47
+ """One-shot mode: read full JSON from stdin, respond, exit."""
48
+ try:
49
+ messages = json.load(sys.stdin)
50
+ except json.JSONDecodeError as e:
51
+ print(f"Error: invalid JSON on stdin: {e}", file=sys.stderr)
52
+ sys.exit(1)
53
+
54
+ if not isinstance(messages, list):
55
+ print("Error: stdin must contain a JSON array of messages.",
56
+ file=sys.stderr)
57
+ sys.exit(1)
58
+
59
+ text, thoughts = machine(messages)
60
+ json.dump([text, thoughts], sys.stdout)
61
+
62
+
63
+ def _run_daemon(machine):
64
+ """Daemon: line-delimited JSON loop.
65
+
66
+ Each line on stdin is a JSON array of messages.
67
+ Each response is a JSON array [text, thoughts] followed by newline.
68
+ Loops until EOF on stdin.
69
+ """
70
+ print("Generalizing-Machine daemon ready.", file=sys.stderr)
71
+ try:
72
+ # Loop blocks until input is available on stdin
73
+ for line in sys.stdin:
74
+ line = line.strip()
75
+ if not line:
76
+ continue
77
+
78
+ try:
79
+ messages = json.loads(line)
80
+ except json.JSONDecodeError as e:
81
+ print(f"Error: invalid JSON: {e}", file=sys.stderr)
82
+ continue
83
+
84
+ if not isinstance(messages, list):
85
+ print("Error: expected a JSON array of messages.",
86
+ file=sys.stderr)
87
+ continue
88
+
89
+ text, thoughts = machine(messages)
90
+ json.dump([text, thoughts], sys.stdout)
91
+ sys.stdout.write('\n')
92
+ sys.stdout.flush()
93
+ except KeyboardInterrupt:
94
+ sys.exit(0)
95
+
96
+
97
+ if __name__ == '__main__':
98
+ main()
@@ -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,3 @@
1
+ # Copyright (c) Alexander Fedotov, 2026. All rights reserved.
2
+ name: answering-machine
3
+ description: You are a Answering-Machine.
@@ -0,0 +1,70 @@
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
+ import os
9
+ import sys
10
+ import yaml
11
+ from . import githf # from .
12
+
13
+ # Constants for the private GitHub repo holding the system prompt
14
+ MACHINE_ORGANIZATION_NAME = 'answering-machine'
15
+ PRIVATE_REPO_WITH_TEXT = 'answering_machine'
16
+ SYSTEM_PROMPT_FILE = 'machina.yaml'
17
+
18
+
19
+ def _fetch_instructions():
20
+ """Retrieve the system prompt from a private GitHub repo.
21
+ Falls back to the local machina.yaml if GitHub is unreachable.
22
+ Returns the 'description' field from the YAML as the system prompt string.
23
+ """
24
+ try:
25
+ repo = githf.connect_to_repo(
26
+ organization=MACHINE_ORGANIZATION_NAME,
27
+ repository_name=PRIVATE_REPO_WITH_TEXT,
28
+ private=True
29
+ )
30
+ raw_yaml = githf.read_file(
31
+ repository=repo,
32
+ file_path=SYSTEM_PROMPT_FILE
33
+ )
34
+ except Exception as e:
35
+ print(f"Warning: could not fetch prompt from GitHub: {e}",
36
+ file=sys.stderr)
37
+ local_path = os.path.join(os.path.dirname(__file__), 'machina.yaml')
38
+ with open(local_path, 'r') as f:
39
+ raw_yaml = f.read()
40
+
41
+ parsed = yaml.safe_load(raw_yaml)
42
+ return parsed.get('description', 'You are a helpful assistant.')
43
+
44
+
45
+ def machine(messages):
46
+ """Core agent logic.
47
+
48
+ 1. Fetches the system prompt from a private GitHub repo.
49
+ 2. Calls Anthropic via electroid.cloud() with the messages.
50
+ 3. Returns (text, thoughts) tuple.
51
+ """
52
+ # Fetch the confidential system prompt
53
+ system_prompt = _fetch_instructions()
54
+ # print(f"System prompt loaded ({len(system_prompt)} chars).", file=sys.stderr)
55
+
56
+ # Import electroid here (after env vars have been set by cli.py)
57
+ import electroid
58
+
59
+ # Call the Anthropic API via electroid
60
+ text, thoughts = electroid.cloud(
61
+ messages=messages,
62
+ system=system_prompt,
63
+ max_tokens=16000
64
+ )
65
+
66
+ return text, thoughts
67
+
68
+
69
+ if __name__ == '__main__':
70
+ machine([])
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: answering-machine
3
+ Version: 0.0.1
4
+ Summary: Machine description
5
+ Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>
6
+ Project-URL: Homepage, https://github.com/org_name/answering_machine
7
+ Project-URL: Bug Tracker, https://github.com/org_name/answering_machine/issues
8
+ Keywords: answering-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: PyGithub>=2.6.0
17
+ Requires-Dist: PyYAML>=6.0.1
18
+ Requires-Dist: urllib3>=2.0.4
19
+ Requires-Dist: requests>=2.32.3
20
+ Requires-Dist: click>=8.3.0
21
+ Dynamic: license-file
22
+
23
+ # Answering Machine
24
+ A machine that answers questions.
25
+ <pre>
26
+ pip install answering-machine
27
+ </pre>
28
+ Then:
29
+ ```Python
30
+ # Python
31
+ import answering_machine
32
+ ```
33
+ Or:
34
+ <pre>
35
+ uvx answering-machine [ARGUMENT] [OPTION]
36
+ </pre>
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ src/answering_machine/__init__.py
6
+ src/answering_machine/cli.py
7
+ src/answering_machine/githf.py
8
+ src/answering_machine/machina.yaml
9
+ src/answering_machine/machine.py
10
+ src/answering_machine.egg-info/PKG-INFO
11
+ src/answering_machine.egg-info/SOURCES.txt
12
+ src/answering_machine.egg-info/dependency_links.txt
13
+ src/answering_machine.egg-info/entry_points.txt
14
+ src/answering_machine.egg-info/requires.txt
15
+ src/answering_machine.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ answering-machine = answering_machine.cli:main
@@ -0,0 +1,6 @@
1
+ electroid>=0.0.16
2
+ PyGithub>=2.6.0
3
+ PyYAML>=6.0.1
4
+ urllib3>=2.0.4
5
+ requests>=2.32.3
6
+ click>=8.3.0
@@ -0,0 +1 @@
1
+ answering_machine