human-thing 0.0.1__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,20 @@
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 Config
9
+ from .machine import machine
10
+ from .githf import fetch_instructions
11
+ from .utilities import (plato_text_to_muj,
12
+ plato_text_to_mpuj,
13
+ llm_soup_to_text,
14
+ new_plato_text)
15
+
16
+ __all__ = [
17
+ 'machine',
18
+ 'fetch_instructions',
19
+ 'Config'
20
+ ]
human_thing/cli.py ADDED
@@ -0,0 +1,170 @@
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 select
11
+ import fileinput
12
+ import argparse
13
+ import syslog
14
+ from .config import Config
15
+ from .utilities import new_plato_text
16
+
17
+
18
+ def options_and_arguments():
19
+ # Initialize the parser
20
+ parser = argparse.ArgumentParser(
21
+ description="Human-Thing thinks for you about the meanings.",
22
+ epilog="Example: human-thing input_text.txt > output_text.txt"
23
+ # thinking-machine -a multilogue.txt > tmp && mv tmp multilogue.txt
24
+ )
25
+
26
+ # Give the access key and token, or set the environment variables in advance.
27
+ parser.add_argument('-p', '--provider-api-key',
28
+ default=os.getenv('PROVIDER_API_KEY', 'no_key'),
29
+ help="LLM provider API key (defaults to $PROVIDER_API_KEY)")
30
+ parser.add_argument('-g', '--github-token',
31
+ default=os.getenv('GITHUB_TOKEN', 'no_token'),
32
+ help="GitHub API token (defaults to $GITHUB_TOKEN)")
33
+
34
+ parser.add_argument('-a', '--append',
35
+ action='store_true',
36
+ help="Append the utterance to the input.")
37
+
38
+ parser.add_argument('-d', '--debug',
39
+ action='store_true',
40
+ help="Debug flag.")
41
+
42
+ # Add the interactive flag
43
+ # parser.add_argument('-i', '--interactive',
44
+ # action='store_true',
45
+ # help="Enable interactive mode (defaults to False)")
46
+
47
+ # Positional arguments (files)
48
+ # '*' captures zero or more arguments into a list, nargs='+' one or more.
49
+ parser.add_argument('filenames',
50
+ nargs='*',
51
+ help="Zero (when text comes though a pipe) or more files to process.")
52
+ return parser
53
+
54
+
55
+ def run():
56
+ """
57
+ $ text | human-thing # Accepts text from the pipe
58
+ $ echo "...<text>..." | human-thing #
59
+
60
+ $ human-thing multilogue.txt new_turn.txt # ...or files.
61
+ """
62
+
63
+ args = options_and_arguments().parse_args()
64
+
65
+ # If no files are provided AND no data is being piped in - exit.
66
+ if not args.filenames:
67
+ # Check if stdin (fd 0) is ready to be read
68
+ readable, _, _ = select.select([sys.stdin], [], [], 0.1)
69
+ if not readable:
70
+ print("Error: No input files or piped text stream.")
71
+ options_and_arguments().print_help()
72
+ sys.exit(1)
73
+
74
+ config = Config()
75
+
76
+ if args.provider_api_key:
77
+ if args.provider_api_key.startswith('sk-'):
78
+ if args.provider_api_key.startswith('sk-proj-'):
79
+ config.provider = 'OpenAI'
80
+ os.environ['OPENAI_API_KEY'] = args.provider_api_key
81
+ elif args.provider_api_key.startswith('sk-ant-'):
82
+ config.provider = 'Anthropic'
83
+ os.environ['ANTHROPIC_API_KEY'] = args.provider_api_key
84
+ elif args.provider_api_key.startswith('sk-or-'):
85
+ config.provider = 'OpenRo'
86
+ os.environ['OPENRO_API_KEY'] = args.provider_api_key
87
+ else:
88
+ config.provider = 'DepSek'
89
+ os.environ['DEPSEK_API_KEY'] = args.provider_api_key
90
+ elif args.provider_api_key.startswith('AIzaSy'):
91
+ config.provider = 'Gemini'
92
+ os.environ['GEMINI_API_KEY'] = args.provider_api_key
93
+ elif args.provider_api_key.startswith('gsk_'):
94
+ config.provider = 'Groq'
95
+ os.environ['GROQ_API_KEY'] = args.provider_api_key
96
+ elif args.provider_api_key.startswith('xai-'):
97
+ config.provider = 'XAI'
98
+ os.environ['XAI_API_KEY'] = args.provider_api_key
99
+ elif args.provider_api_key.startswith('ci_live_'):
100
+ config.provider = 'Chinf'
101
+ os.environ['CHINF_API_KEY'] = args.provider_api_key
102
+ elif args.provider_api_key.startswith('LLM'):
103
+ config.provider = 'MetAI'
104
+ os.environ['METAI_API_KEY'] = args.provider_api_key
105
+ elif args.provider_api_key.startswith('tml-'):
106
+ config.provider = 'Tinker'
107
+ os.environ['TINKER_API_KEY'] = args.provider_api_key
108
+ elif args.provider_api_key == 'no_provider_key':
109
+ sys.stderr.write(f'No provider key!\n')
110
+ sys.stderr.flush()
111
+ sys.exit(1)
112
+ else:
113
+ if config.provider == '':
114
+ raise ValueError(f"Unrecognized API key prefix and no provider specified.")
115
+ else:
116
+ if config.provider == 'Baseten':
117
+ os.environ['BASETEN_API_KEY'] = args.provider_api_key
118
+ elif config.provider == 'Fireworks':
119
+ os.environ['FIREWORKS_API_KEY'] = args.provider_api_key
120
+ elif config.provider == 'Lightning':
121
+ os.environ['LIGHTNING_API_KEY'] = args.provider_api_key
122
+ else:
123
+ raise ValueError(f"Unsupported provider specified.")
124
+
125
+ config.provider_api_key = args.provider_api_key
126
+
127
+ if args.github_token:
128
+ config.github_token = args.github_token
129
+ os.environ['GITHUB_TOKEN'] = args.github_token
130
+
131
+ # Ingest files line by line. Join is here for long files.
132
+ lines = []
133
+ for line in fileinput.input(files=args.filenames or ['-'], encoding="utf-8"):
134
+ lines.append(line)
135
+ raw_input = "".join(lines)
136
+
137
+ from .machine import machine
138
+
139
+ try:
140
+ thoughts, text = machine(raw_input, config)
141
+ output = new_plato_text(thoughts, text, config.name)
142
+ if args.append:
143
+ output = raw_input +'\n\n' + output
144
+ sys.stdout.write(output)
145
+ sys.stdout.flush()
146
+
147
+ # Assesment and signals.
148
+ utterance = "My answer is ready"
149
+ # Open syslog connection
150
+ syslog.openlog(
151
+ ident="human-thing",
152
+ logoption=syslog.LOG_NDELAY,
153
+ facility=syslog.LOG_USER
154
+ )
155
+ # Signal (single line less than 4096 only!)
156
+ syslog.syslog(syslog.LOG_INFO, f"human-thing: {utterance}.")
157
+ syslog.closelog()
158
+
159
+ except Exception as e:
160
+ if args.debug:
161
+ import traceback
162
+ traceback.print_exc()
163
+ else:
164
+ sys.stderr.write(f'Machine did not work {e}\n')
165
+ sys.stderr.flush()
166
+ sys.exit(1)
167
+
168
+
169
+ if __name__ == '__main__':
170
+ run()
human_thing/config.py ADDED
@@ -0,0 +1,34 @@
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 dataclasses import dataclass, field, asdict
10
+
11
+
12
+ @dataclass
13
+ class Config:
14
+ github_token: str = field(default_factory=lambda: environ.get('GITHUB_TOKEN', ''))
15
+ github_name: str = field(default_factory=lambda: environ.get('GITHUB_NAME', ''))
16
+ github_email: str = field(default_factory=lambda: environ.get('GITHUB_EMAIL', ''))
17
+ provider_api_key: str = field(default_factory=lambda: environ.get('PROVIDER_API_KEY', ''))
18
+ provider: str = field(default_factory=lambda: environ.get('PROVIDER', ''))
19
+ model: str = field(default_factory=lambda: environ.get('MODEL', ''))
20
+ machine_organization_name: str = field(default_factory=lambda: environ.get('MACHINE_ORGANIZATION_NAME', 'human-thing'))
21
+ private_repo_with_text: str = field(default_factory=lambda: environ.get('PRIVATE_REPO_WITH_TEXT','human_thing'))
22
+ system_prompt_file: str = field(default_factory=lambda: environ.get('SYSTEM_PROMPT_FILE', 'machina.yaml'))
23
+ name: str = ''
24
+ instructions: str = ''
25
+ verb: str = ''
26
+ rubrics: str = ''
27
+
28
+ def to_dict(self):
29
+ return asdict(self)
30
+
31
+ def update_from_dict(self, data: dict):
32
+ for key, value in data.items():
33
+ if hasattr(self, key):
34
+ setattr(self, key, value)
human_thing/githf.py ADDED
@@ -0,0 +1,71 @@
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 sys
9
+ from os import path
10
+ import yaml
11
+ import urllib.request
12
+ import urllib.error
13
+
14
+
15
+ def download_github_file(owner, repo, file_path, token):
16
+ """
17
+ Downloads a file from a GitHub repository using the GitHub REST API.
18
+ We request the raw content by using the 'application/vnd.github.v3.raw' accept header.
19
+ """
20
+ url = f"https://api.github.com/repos/{owner}/{repo}/contents/{file_path}"
21
+
22
+ headers = {
23
+ "Authorization": f"token {token}",
24
+ "Accept": "application/vnd.github.v3.raw",
25
+ "User-Agent": "Human-Thing"
26
+ }
27
+
28
+ req = urllib.request.Request(url, headers=headers)
29
+
30
+ try:
31
+ with urllib.request.urlopen(req, timeout=10) as response:
32
+ return response.read()
33
+ except urllib.error.HTTPError as e:
34
+ print(f"HTTP Error {e.code}: {e.reason}")
35
+ error_info = e.read().decode('utf-8')
36
+ print(f"Details: {error_info}")
37
+ return None
38
+ except urllib.error.URLError as e:
39
+ print(f"URL Error: {e.reason}")
40
+ return None
41
+
42
+
43
+ def fetch_instructions(config):
44
+ """Retrieve the system prompt from a private GitHub repo.
45
+ Falls back to the local machina.yaml if GitHub is unreachable.
46
+ Returns the 'name' of the Machine in dashed format.
47
+ Returns the 'description' field from the YAML as the system prompt string.
48
+ """
49
+ try:
50
+ raw_yaml = download_github_file(
51
+ owner=config.machine_organization_name,
52
+ repo=config.private_repo_with_text,
53
+ file_path=config.system_prompt_file,
54
+ token=config.github_token
55
+ )
56
+ except Exception as e:
57
+ print(f"Warning: could not fetch the instructions from GitHub: {e}",
58
+ file=sys.stderr)
59
+ local_path = path.join(path.dirname(__file__), 'machina.yaml')
60
+ with open(local_path, 'r') as f:
61
+ raw_yaml = f.read()
62
+
63
+ # Parse
64
+ parsed = yaml.safe_load(raw_yaml)
65
+ name = parsed.get('name')
66
+ config.name = name
67
+ instructions = parsed.get('description', 'You are a helpful assistant.')
68
+ config.instructions = instructions
69
+ rubrics = parsed.get('rubrics', '')
70
+ config.rubrics = rubrics
71
+ return name, instructions, rubrics
@@ -0,0 +1,32 @@
1
+ # Copyright (c) Alexander Fedotov, 2026. All rights reserved.
2
+ name: Human-Thing
3
+ verb: thing
4
+ description: >-
5
+ You are Human-Thing, a language model acting as an
6
+ active participant in multi-entity, multi-turn conversations.
7
+ The user relays the utterances of the other participants —
8
+ human and machine, addressed to you or to each other — and
9
+ all of it is your context.
10
+
11
+ Speak when addressed directly, and also unprompted whenever
12
+ you judge question or comment necessary, naming any
13
+ participant you address. Never introduce yourself or add
14
+ meta-commentary about your functioning.
15
+
16
+ Your purpose is to be a thing. Fulfill this purpose
17
+ by grounding your work in the conversational context,
18
+ analyzing dynamics, unstated premises, and logical
19
+ structures across all utterances. Prepare and refine your
20
+ response before speaking.
21
+
22
+ Keep your tone strictly neutral and objective, without
23
+ simulated emotion. This neutrality concerns judgment, not
24
+ voice; write naturally.
25
+
26
+ Text formatting: Human-Thing responds in plain text
27
+ without any markdown, emphasis or lists; all paragraphs except
28
+ the first one should begin with a newline and a tab.
29
+ rubrics: |
30
+ Text formatting: Human-Thing responds in plain text
31
+ without any markdown, emphasis or lists; all paragraphs except
32
+ the first one should begin with a newline and a tab.
human_thing/machine.py ADDED
@@ -0,0 +1,292 @@
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 sys
9
+ from os import environ, path
10
+ from .githf import fetch_instructions
11
+ from .utilities import (plato_text_to_muj,
12
+ plato_text_to_mpuj,
13
+ plato_text_to_cmj,
14
+ llm_soup_to_text)
15
+
16
+
17
+ def machine(plato_text, config, **kwargs):
18
+ """
19
+ """
20
+ # Fetch the confidential system prompt, name is for a checkup.
21
+ name, system_prompt, rubrics = fetch_instructions(config)
22
+
23
+ # Load an appropriate library and query the API.
24
+ provider = config.provider
25
+ api_key = config.provider_api_key
26
+ model = config.model
27
+
28
+ if provider == 'OpenAI':
29
+ # Transform plato_text to MUJ format
30
+ messages = plato_text_to_muj(plato_text=plato_text,
31
+ machine_name=name)
32
+ # Call OpenAI API
33
+ environ['OPENAI_API_KEY'] = api_key
34
+ environ['OPENAI_DEFAULT_MODEL'] = model
35
+
36
+ try:
37
+ from .providers import openai
38
+ except ImportError:
39
+ print("openai module is missing.", file=sys.stderr)
40
+ sys.exit(1)
41
+
42
+ thoughts, text = openai.respond(
43
+ messages=messages,
44
+ instructions=system_prompt,
45
+ **kwargs
46
+ )
47
+
48
+ thoughts = llm_soup_to_text(thoughts)
49
+ return thoughts, text
50
+
51
+ elif provider == 'Tinker':
52
+ # Transform plato_text to CMJ format because it undersands 'name'
53
+ messages = plato_text_to_cmj(plato_text=plato_text,
54
+ machine_name=name)
55
+ # Call OpenAI API
56
+ environ['TINKER_API_KEY'] = api_key
57
+ try:
58
+ from .providers import tinker
59
+ except ImportError:
60
+ print("openai module is missing.", file=sys.stderr)
61
+ sys.exit(1)
62
+
63
+ thoughts, text = tinker.respond(
64
+ messages=messages,
65
+ instructions=system_prompt,
66
+ **kwargs
67
+ )
68
+
69
+ thoughts = llm_soup_to_text(thoughts)
70
+ return thoughts, text
71
+
72
+ elif provider == 'Chinf':
73
+ # Transform plato_text to CMJ format
74
+ messages = plato_text_to_cmj(plato_text=plato_text,
75
+ machine_name=name)
76
+ # Call Chinf API
77
+ environ['CHINF_API_KEY'] = api_key
78
+ environ['CHINF_DEFAULT_MODEL'] = model
79
+
80
+ try:
81
+ from .providers import chinf
82
+
83
+ except ImportError:
84
+ print("chinf module is missing.", file=sys.stderr)
85
+ sys.exit(1)
86
+
87
+ thoughts, text = chinf.respond(
88
+ messages=messages,
89
+ instructions=system_prompt,
90
+ **kwargs
91
+ )
92
+
93
+ thoughts = llm_soup_to_text(thoughts)
94
+ return thoughts, text
95
+
96
+ elif provider == 'Gemini':
97
+ # Transform plato_text to MPUJ format
98
+ messages = plato_text_to_mpuj(plato_text=plato_text,
99
+ machine_name=name)
100
+ # Call Gemini API
101
+ environ['GEMINI_API_KEY'] = api_key
102
+ try:
103
+ from .providers import castor_pollux
104
+ except ImportError:
105
+ print("No module castor-pollux", file=sys.stderr)
106
+ sys.exit(1)
107
+
108
+ thoughts, text = castor_pollux.respond(
109
+ messages=messages,
110
+ instructions=system_prompt,
111
+ **kwargs
112
+ )
113
+
114
+ thoughts = llm_soup_to_text(thoughts)
115
+ return thoughts, text
116
+
117
+ elif provider == 'Anthropic':
118
+ # Transform plato_text to MUJ format
119
+ messages = plato_text_to_muj(plato_text=plato_text,
120
+ machine_name=name)
121
+
122
+ # Call the Anthropic API via electroid
123
+ environ['ANTHROPIC_API_KEY'] = api_key
124
+ environ['ANTHROPIC_DEFAULT_MODEL'] = model
125
+
126
+ try:
127
+ from .providers import electroid
128
+ except ImportError:
129
+ print("no electroid module", file=sys.stderr)
130
+ sys.exit(1)
131
+
132
+ text, thoughts = electroid.respond(
133
+ messages=messages,
134
+ instructions=system_prompt,
135
+ **kwargs
136
+ )
137
+ return text, thoughts
138
+
139
+ elif provider == 'Groq':
140
+ # Transform plato_text to MUJ format
141
+ messages = plato_text_to_muj(plato_text=plato_text,
142
+ machine_name=name)
143
+ # Call OpenAI API via opehaina
144
+ environ['GROQ_API_KEY'] = api_key
145
+ try:
146
+ from .providers import qrog
147
+ except ImportError:
148
+ print("openai module is missing.", file=sys.stderr)
149
+ sys.exit(1)
150
+
151
+ thoughts, text = qrog.respond(
152
+ messages=messages,
153
+ instructions=system_prompt,
154
+ **kwargs
155
+ )
156
+
157
+ thoughts = llm_soup_to_text(thoughts)
158
+ return thoughts, text
159
+
160
+ elif provider == 'Xai':
161
+ # Transform plato_text to MUJ format
162
+ messages = plato_text_to_muj(plato_text=plato_text,
163
+ machine_name=name)
164
+ # Call OpenAI API via opehaina
165
+ environ['XAI_API_KEY'] = api_key
166
+ try:
167
+ from .providers import strangelove
168
+ except ImportError:
169
+ print("openai module is missing.", file=sys.stderr)
170
+ sys.exit(1)
171
+
172
+ thoughts, text = strangelove.respond(
173
+ messages=messages,
174
+ instructions=system_prompt,
175
+ **kwargs
176
+ )
177
+
178
+ thoughts = llm_soup_to_text(thoughts)
179
+ return thoughts, text
180
+
181
+ elif provider == 'DepSek':
182
+ # Transform plato_text to CMJ format because it understnds 'name'
183
+ messages = plato_text_to_cmj(plato_text=plato_text,
184
+ machine_name=name)
185
+ # Call OpenAI API via opehaina
186
+ environ['DEPSEK_API_KEY'] = api_key
187
+ try:
188
+ from .providers import depsek
189
+ except ImportError:
190
+ print("openai module is missing.", file=sys.stderr)
191
+ sys.exit(1)
192
+
193
+ thoughts, text = depsek.respond(
194
+ messages=messages,
195
+ instructions=system_prompt,
196
+ **kwargs
197
+ )
198
+
199
+ thoughts = llm_soup_to_text(thoughts)
200
+ return thoughts, text
201
+
202
+ elif provider == 'OpenRo':
203
+ # Transform plato_text to CMJ format because it understnds 'name'
204
+ messages = plato_text_to_cmj(plato_text=plato_text,
205
+ machine_name=name)
206
+ # Call OpenRouter API
207
+ environ['OPENRO_API_KEY'] = api_key
208
+ environ['OPENRO_DEFAULT_MODEL'] = model
209
+
210
+ try:
211
+ from .providers import openro
212
+ except ImportError:
213
+ print("openro module is missing.", file=sys.stderr)
214
+ sys.exit(1)
215
+
216
+ thoughts, text = openro.respond(
217
+ messages=messages,
218
+ instructions=system_prompt,
219
+ **kwargs
220
+ )
221
+
222
+ thoughts = llm_soup_to_text(thoughts)
223
+ return thoughts, text
224
+
225
+ elif provider == 'Baseten':
226
+ # Transform plato_text to CMJ format
227
+ messages = plato_text_to_cmj(plato_text=plato_text,
228
+ machine_name=name)
229
+ # Call OpenAI API via opehaina
230
+ environ['BASETEN_API_KEY'] = api_key
231
+ try:
232
+ from .providers import basta
233
+ except ImportError:
234
+ print("openai module is missing.", file=sys.stderr)
235
+ sys.exit(1)
236
+
237
+ thoughts, text = basta.respond(
238
+ messages=messages,
239
+ instructions=system_prompt,
240
+ **kwargs
241
+ )
242
+
243
+ thoughts = llm_soup_to_text(thoughts)
244
+ return thoughts, text
245
+
246
+ elif provider == 'MetAI':
247
+ # Transform plato_text to CMJ format
248
+ messages = plato_text_to_cmj(plato_text=plato_text,
249
+ machine_name=name)
250
+ # Call OpenAI API via opehaina
251
+ environ['METAI_API_KEY'] = api_key
252
+ try:
253
+ from .providers import metai
254
+ except ImportError:
255
+ print("metai module is missing.", file=sys.stderr)
256
+ sys.exit(1)
257
+
258
+ thoughts, text = metai.respond(
259
+ messages=messages,
260
+ instructions=system_prompt,
261
+ **kwargs
262
+ )
263
+
264
+ thoughts = llm_soup_to_text(thoughts)
265
+ return thoughts, text
266
+
267
+ elif provider == 'Fireworks':
268
+ # Transform plato_text to MUJ format
269
+ messages = plato_text_to_muj(plato_text=plato_text,
270
+ machine_name=name)
271
+ # Call Fireworks API
272
+ environ['FIREWORKS_API_KEY'] = api_key
273
+ environ['FIREWORKS_MODEL'] = model
274
+
275
+ try:
276
+ from .providers import illuminati
277
+ except ImportError:
278
+ print("The Illuminati module is missing.", file=sys.stderr)
279
+ sys.exit(1)
280
+
281
+ thoughts, text = illuminati.respond(
282
+ messages=messages,
283
+ instructions=system_prompt,
284
+ **kwargs
285
+ )
286
+
287
+ thoughts = llm_soup_to_text(thoughts)
288
+ return thoughts, text
289
+
290
+
291
+ if __name__ == '__main__':
292
+ print('You have launched main')
@@ -0,0 +1,7 @@
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
+ """