conceptualizing-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/conceptualizing_machine/*.yaml
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: conceptualizing-machine
3
+ Version: 0.0.1
4
+ Summary: A Machine that conceptualizes meanings.
5
+ Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>
6
+ Project-URL: Homepage, https://github.com/conceptualizing-machine/conceptualizing-machine
7
+ Keywords: conceptualizing-machine
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: electroid>=0.0.19
15
+ Requires-Dist: opehaina>=0.0.5
16
+ Requires-Dist: castor-pollux>=0.1.4
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
+ # Conceptualizing Machine
25
+ A Machine that conceptualizes meanings.
26
+ ```bash
27
+ echo "Theodotos-Alexandreus: Are language models seeking the Truth, machine?" \
28
+ | uvx conceptualizing-machine \
29
+ --provider-api-key=sk-ant-api... \
30
+ --github-token=ghp_...
31
+ ```
32
+ Or:
33
+ ```bash
34
+ pip install conceptualizing-machine
35
+ ```
36
+ Then:
37
+ ```Python
38
+ # Python
39
+ import conceptualizing_machine
40
+ ```
@@ -0,0 +1,17 @@
1
+ # Conceptualizing Machine
2
+ A Machine that conceptualizes meanings.
3
+ ```bash
4
+ echo "Theodotos-Alexandreus: Are language models seeking the Truth, machine?" \
5
+ | uvx conceptualizing-machine \
6
+ --provider-api-key=sk-ant-api... \
7
+ --github-token=ghp_...
8
+ ```
9
+ Or:
10
+ ```bash
11
+ pip install conceptualizing-machine
12
+ ```
13
+ Then:
14
+ ```Python
15
+ # Python
16
+ import conceptualizing_machine
17
+ ```
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=67.0"]
3
+ build-backend = "setuptools.build_meta"
4
+ [project]
5
+ name = "conceptualizing-machine"
6
+ version = "0.0.1"
7
+ authors = [
8
+ {name="Machina Ratiocinatrix", email="machina.ratio@gmail.com"},
9
+ ]
10
+ description = "A Machine that conceptualizes meanings."
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 = ["conceptualizing-machine"]
20
+
21
+ dependencies = [
22
+ "electroid >= 0.0.19",
23
+ "opehaina >= 0.0.5",
24
+ "castor-pollux >= 0.1.4",
25
+ "PyGithub >= 2.6.0",
26
+ "PyYAML >= 6.0.1",
27
+ "urllib3 >= 2.0.4",
28
+ "requests >= 2.32.3",
29
+ "click >= 8.3.0"
30
+ ]
31
+
32
+ [project.scripts]
33
+ conceptualizing-machine = "conceptualizing_machine.cli:run"
34
+
35
+ [project.urls]
36
+ "Homepage" = "https://github.com/conceptualizing-machine/conceptualizing-machine"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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 .config import settings
9
+ from .machine import machine
10
+ from .githf import connect_to_repo, read_file, 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
+ 'connect_to_repo',
19
+ 'read_file',
20
+ 'fetch_instructions',
21
+ 'settings'
22
+ ]
@@ -0,0 +1,72 @@
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
+ import sys
10
+ from .config import settings
11
+ from .utilities import llm_soup_to_text, new_plato_text
12
+ import click
13
+ import fileinput
14
+
15
+
16
+ @click.command()
17
+ @click.option('--provider-api-key', envvar='PROVIDER_API_KEY',
18
+ default='no_provider_key', help='Language Model API provider key.')
19
+ @click.option('--github-token', envvar='GITHUB_TOKEN',
20
+ default='', help='GitHub API token for private repo access.')
21
+ def run(provider_api_key, github_token, mode):
22
+ """
23
+ $ text | ./run.py # Accepts text from the pipe
24
+ $ ./run.py /home/user/file.txt # Reads file.
25
+ $ ./run.py < /home/user/file.txt # Reads file.
26
+
27
+ secrets come through the environment variables.
28
+ """
29
+ if provider_api_key:
30
+ if provider_api_key.startswith('sk-proj-'):
31
+ settings['provider'] = 'OpenAI'
32
+ environ['OPENAI_API_KEY'] = provider_api_key
33
+ elif provider_api_key.startswith('sk-ant-'):
34
+ settings['provider'] = 'Anthropic'
35
+ environ['ANTHROPIC_API_KEY'] = provider_api_key
36
+ elif provider_api_key.startswith('AIzaSy'):
37
+ settings['provider'] = 'Gemini'
38
+ environ['GEMINI_API_KEY'] = provider_api_key
39
+ elif provider_api_key.startswith('gsk_'):
40
+ settings['provider'] = 'Groq'
41
+ environ['GROQ_API_KEY'] = provider_api_key
42
+ elif provider_api_key.startswith('xai-'):
43
+ settings['provider'] = 'XAI'
44
+ environ['XAI_API_KEY'] = provider_api_key
45
+ elif provider_api_key.startswith('LLM|'):
46
+ settings['provider'] = 'Meta'
47
+ environ['META_API_KEY'] = provider_api_key
48
+ else:
49
+ if settings['provider'] == '':
50
+ raise ValueError(f"Unrecognized API key prefix and no provider specified.")
51
+ if github_token:
52
+ environ['GITHUB_TOKEN'] = github_token
53
+
54
+ raw_input = ''
55
+ for line in fileinput.input(encoding="utf-8"):
56
+ raw_input += line
57
+
58
+ from .machine import machine
59
+
60
+ try:
61
+ thoughts, text = machine(raw_input)
62
+ output = raw_input + '\n\n' + new_plato_text(thoughts, text, settings['name'])
63
+ sys.stdout.write(output)
64
+ sys.stdout.flush()
65
+ except Exception as e:
66
+ sys.stderr.write(f'Machine did not work {e}')
67
+ sys.stderr.flush()
68
+ sys.exit(0)
69
+
70
+
71
+ if __name__ == '__main__':
72
+ 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', 'conceptualizing-machine'),
18
+ private_repo_with_text = environ.get('PRIVATE_REPO_WITH_TEXT','conceptualizing_machine'),
19
+ system_prompt_file = environ.get('SYSTEM_PROMPT_FILE', 'machina.yaml'),
20
+ name = '',
21
+ instructions = ''
22
+ )
@@ -0,0 +1,133 @@
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
+
9
+ import sys
10
+ from os import environ, path
11
+ from github import Github, UnknownObjectException
12
+ from urllib3 import disable_warnings
13
+ import yaml
14
+ from .config import settings
15
+
16
+
17
+ github_token = environ.get('GITHUB_TOKEN', '')
18
+ github_name = environ.get('GITHUB_NAME', '')
19
+ github_email = environ.get('GITHUB_EMAIL', '')
20
+
21
+ # The useless urllib3 warning is too maddening for an ordinary human being.
22
+ disable_warnings()
23
+
24
+
25
+ # Repo
26
+ def connect_to_repo(organization=None,
27
+ repository_name=None,
28
+ private=False):
29
+ """
30
+ Establish a connection with a GitHub repository.
31
+
32
+ Args:
33
+ organization (str, optional): The name of the organization. If not provided,
34
+ the repository is assumed to be owned by the authenticated user.
35
+ repository_name (str): The name of the repository.
36
+ private (bool, optional): Whether the repository is private. Defaults to False.
37
+
38
+ Returns:
39
+ github.Repository.Repository: The GitHub repository object if the connection is successful.
40
+ None: If the connection fails.
41
+
42
+ Raises:
43
+ github.UnknownObjectException: If the repository does not exist.
44
+
45
+ Note:
46
+ The function requires the following environment variables to be set:
47
+ - GITHUB_TOKEN: The personal access token for authentication.
48
+ - GITHUB_NAME: The name of the authenticated user.
49
+ - GITHUB_EMAIL: The email of the authenticated user.
50
+
51
+ """
52
+
53
+ gh = Github(github_token, verify=False)
54
+ if organization:
55
+ org = gh.get_organization(organization)
56
+ try:
57
+ repo = org.get_repo(f'{repository_name}')
58
+ except UnknownObjectException:
59
+ # print('Can not connect YOU to this repo in this organization')
60
+ repo = None
61
+ return repo
62
+ else:
63
+ user = gh.get_user()
64
+ try:
65
+ repo = user.get_repo(repository_name)
66
+ except UnknownObjectException:
67
+ # print('Can not connect YOU to this repo')
68
+ repo = None
69
+ return repo
70
+
71
+
72
+ def read_file(repository,
73
+ file_path):
74
+ """
75
+ Read the contents of a file in a GitHub repository.
76
+
77
+ Args:
78
+ repository (github.Repository.Repository): The GitHub repository object.
79
+ file_path (str): The path to the file in the repository, formatted as
80
+ 'directory_in_repo/subdirectory/file.ext'.
81
+
82
+ Returns:
83
+ str: The contents of the file as a string. If the file does not exist, an empty string is returned.
84
+
85
+ Raises:
86
+ github.UnknownObjectException: If the file does not exist in the repository.
87
+
88
+ Note:
89
+ This function assumes that the repository object has already been authenticated and connected.
90
+ """
91
+ try:
92
+ # Get the file if it exists
93
+ ingested_file = repository.get_contents(file_path)
94
+ content = ingested_file.decoded_content.decode("utf-8")
95
+
96
+ except UnknownObjectException:
97
+ # The file doesn't exist
98
+ # print('The file does not exist')
99
+ content = ''
100
+
101
+ return content
102
+
103
+
104
+ def fetch_instructions():
105
+ """Retrieve the system prompt from a private GitHub repo.
106
+ Falls back to the local machina.yaml if GitHub is unreachable.
107
+ Returns the 'name' of the Machine in dashed format.
108
+ Returns the 'description' field from the YAML as the system prompt string.
109
+ """
110
+ try:
111
+ repo = connect_to_repo(
112
+ organization=settings['machine_organization_name'],
113
+ repository_name=settings['private_repo_with_text'],
114
+ private=True
115
+ )
116
+ raw_yaml = read_file(
117
+ repository=repo,
118
+ file_path=settings['system_prompt_file']
119
+ )
120
+ except Exception as e:
121
+ print(f"Warning: could not fetch prompt from GitHub: {e}",
122
+ file=sys.stderr)
123
+ local_path = path.join(path.dirname(__file__), 'machina.yaml')
124
+ with open(local_path, 'r') as f:
125
+ raw_yaml = f.read()
126
+
127
+ # Parse whatever you've gotten.
128
+ parsed = yaml.safe_load(raw_yaml)
129
+ name = parsed.get('name')
130
+ settings['name'] = name
131
+ instructions = parsed.get('description', 'You are a helpful assistant.')
132
+ settings['instructions'] = instructions
133
+ return name, instructions
@@ -0,0 +1,7 @@
1
+ # Copyright (c) Alexander Fedotov, 2026. All rights reserved.
2
+ name: Conceptualizing-Machine
3
+ description: The Assistant is Conceptualizing-Machine. Conceptualizing-Machine is does its best to understand
4
+ the conversation that it is participating in and answers in a most thoughtful way possible
5
+ the questions that it is being asked.
6
+ Conceptualizing-Machine responds in plain text without any markdown, emphasis or lists. All
7
+ paragraphs except the first should begin with a newline and tab.
@@ -0,0 +1,85 @@
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
+ from .githf import fetch_instructions
11
+ from .utilities import (plato_text_to_muj,
12
+ plato_text_to_mpuj,
13
+ llm_soup_to_text)
14
+
15
+
16
+ def machine(plato_text, **kwargs):
17
+ """Core agent logic.
18
+
19
+ 1. Fetches the system prompt from a private GitHub repo.
20
+ 2. Calls Provider
21
+ 3. Returns a (thoughts, text) tuple.
22
+ """
23
+ # Fetch the confidential system prompt, name is for a checkup.
24
+ name, system_prompt = fetch_instructions()
25
+
26
+ # Load an appropriate library and query the API.
27
+ provider = settings['provider']
28
+ api_key = settings['provider_api_key']
29
+ if provider == 'OpenAI':
30
+ # Transform plato_text to MUJ format
31
+ messages = plato_text_to_muj(plato_text=plato_text,
32
+ machine_name=name)
33
+ # Call OpenAI API via opehaina
34
+ environ['OPENAI_API_KEY'] = api_key
35
+ import opehaina
36
+ thoughts, text = opehaina.respond(
37
+ messages=messages,
38
+ instructions=system_prompt,
39
+ **kwargs
40
+ )
41
+
42
+ thoughts = llm_soup_to_text(thoughts)
43
+ return thoughts, text
44
+
45
+ elif provider == 'Gemini':
46
+ # Transform plato_text to MPUJ format
47
+ messages = plato_text_to_mpuj(plato_text=plato_text,
48
+ machine_name=name)
49
+ # Call Gemini through castor-polux
50
+ environ['GEMINI_API_KEY'] = api_key
51
+ import castor_pollux
52
+ thoughts, text = castor_pollux.respond(
53
+ messages=messages,
54
+ instructions=system_prompt,
55
+ **kwargs
56
+ )
57
+
58
+ thoughts = llm_soup_to_text(thoughts)
59
+ return thoughts, text
60
+
61
+ elif provider == 'Anthropic':
62
+ # Transform plato_text to MUJ format
63
+ messages = plato_text_to_muj(plato_text=plato_text,
64
+ machine_name=name)
65
+
66
+ # Call the Anthropic API via electroid
67
+ environ['ANTHROPIC_API_KEY'] = api_key
68
+ import electroid
69
+ text, thoughts = electroid.respond(
70
+ messages=messages,
71
+ instructions=system_prompt,
72
+ **kwargs
73
+ )
74
+ return text, thoughts
75
+
76
+ elif provider == 'Groq':
77
+ ...
78
+ elif provider == 'Xai':
79
+ ...
80
+ elif provider == 'Meta':
81
+ ...
82
+
83
+
84
+ if __name__ == '__main__':
85
+ machine([])
@@ -0,0 +1,290 @@
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 re
9
+
10
+
11
+ def plato_text_to_muj(plato_text, machine_name):
12
+ """
13
+ Transforms platoText format to MUJ (Multi-User JSON) array for OpenAI
14
+ responses API.
15
+ Consecutive non-assistant messages are grouped into a single 'user' message.
16
+ Assistant messages have only the utterance.
17
+ """
18
+ if plato_text is None or not isinstance(plato_text, str):
19
+ raise ValueError("Invalid input: plato_text must be a string.")
20
+
21
+ trimmed_plato_text = plato_text.strip()
22
+ if not trimmed_plato_text:
23
+ return []
24
+
25
+ assistant_name_upper = machine_name.upper()
26
+
27
+ muj_messages = []
28
+ current_role = None
29
+ current_parts = []
30
+ current_is_thoughts = None
31
+
32
+ message_blocks = re.split(r'\n\n(?=[A-Za-z0-9_-]+:\s*)', trimmed_plato_text)
33
+
34
+ for block in message_blocks:
35
+ current_block = block.strip()
36
+ if not current_block:
37
+ continue
38
+
39
+ speaker_match = re.match(r'^([A-Za-z0-9_-]+):\s*', current_block)
40
+ if not speaker_match:
41
+ continue
42
+
43
+ speaker = speaker_match.group(1)
44
+ raw_utterance = current_block[len(speaker_match.group(0)):]
45
+
46
+ is_thoughts = False
47
+ if raw_utterance.strip().startswith('(thinking)'):
48
+ is_thoughts = True
49
+ raw_utterance = re.sub(r'^\s*\(thinking\)\s*', '', raw_utterance)
50
+
51
+ utterance = re.sub(r'\n{2,}', '\n\t', raw_utterance).strip()
52
+
53
+ final_utterance = utterance
54
+ if is_thoughts:
55
+ final_utterance = f"(thinking) {utterance}"
56
+
57
+ is_assistant_message = speaker.upper() == assistant_name_upper
58
+ role = 'assistant' if is_assistant_message else 'user'
59
+
60
+ if role != current_role or (role == 'assistant' and is_thoughts != current_is_thoughts):
61
+ if len(current_parts) > 0:
62
+ muj_messages.append({
63
+ 'role': current_role,
64
+ 'content': '\n\n'.join(current_parts)
65
+ })
66
+ current_role = role
67
+ current_is_thoughts = is_thoughts
68
+ current_parts = []
69
+
70
+ if is_assistant_message:
71
+ current_parts.append(final_utterance)
72
+ else:
73
+ current_parts.append(f"{speaker}: {final_utterance}")
74
+
75
+ if len(current_parts) > 0:
76
+ muj_messages.append({
77
+ 'role': current_role,
78
+ 'content': '\n\n'.join(current_parts)
79
+ })
80
+
81
+ return muj_messages
82
+
83
+
84
+ def another_plato_text_to_muj(plato_text, machine_name):
85
+ """
86
+ Transforms platoText format to MUJ (Multi-User JSON) array for OpenAI API.
87
+ Consecutive non-assistant messages are grouped into a single 'user' message.
88
+ Assistant messages have a name in each of them and are joined into a single
89
+ utterance.
90
+
91
+ This is for the Theatron type of imitation of performance.
92
+ """
93
+ # trimmed_plato_text = plato_text.strip()
94
+ # if not trimmed_plato_text:
95
+ # return []
96
+
97
+ assistant_name_upper = machine_name.upper()
98
+
99
+ muj_messages = []
100
+ current_role = None
101
+ current_parts = []
102
+
103
+ message_blocks = re.split(r'\n\n(?=[A-Za-z0-9_-]+:\s*)', plato_text)
104
+
105
+ for block in message_blocks:
106
+ current_block = block.strip()
107
+ if not current_block:
108
+ continue
109
+
110
+ speaker_match = re.match(r'^([A-Za-z0-9_-]+):\s*', current_block)
111
+ if not speaker_match:
112
+ continue
113
+
114
+ speaker = speaker_match.group(1)
115
+ raw_utterance = current_block[len(speaker_match.group(0)):]
116
+
117
+ is_thoughts = False
118
+ if raw_utterance.strip().startswith('(thinking)'):
119
+ is_thoughts = True
120
+ raw_utterance = re.sub(r'^\s*\(thinking\)\s*', '', raw_utterance)
121
+
122
+ # questionable replacement of double newline with new paragraph delimiter
123
+ utterance = re.sub(r'\n{2,}', '\n\t', raw_utterance).strip()
124
+
125
+ final_utterance = utterance
126
+ if is_thoughts:
127
+ final_utterance = f"(thinking) {utterance}"
128
+
129
+ is_assistant_message = speaker.upper() == assistant_name_upper
130
+ role = 'assistant' if is_assistant_message else 'user'
131
+
132
+ if role != current_role:
133
+ if len(current_parts) > 0:
134
+ muj_messages.append({
135
+ 'role': current_role,
136
+ 'content': '\n\n'.join(current_parts)
137
+ })
138
+ current_role = role
139
+ current_parts = []
140
+
141
+ current_parts.append(f"{speaker}: {final_utterance}")
142
+
143
+ if len(current_parts) > 0:
144
+ muj_messages.append({
145
+ 'role': current_role,
146
+ 'content': '\n\n'.join(current_parts)
147
+ })
148
+
149
+ return muj_messages
150
+
151
+
152
+ def plato_text_to_mpuj(plato_text, machine_name):
153
+ """
154
+ Transforms platoText format to MPUJ (Multi-Part User JSON) array for Gemini API.
155
+ Consecutive non-model messages are grouped into a single 'user' message
156
+ with multiple parts. Each part includes the speaker's name and utterance.
157
+ Model messages have a single part with the utterance.
158
+ """
159
+ if plato_text is None or not isinstance(plato_text, str):
160
+ raise ValueError("Invalid input: plato_text must be a string.")
161
+
162
+ trimmed_plato_text = plato_text.strip()
163
+ if not trimmed_plato_text:
164
+ return []
165
+
166
+ model_name_upper = machine_name.upper()
167
+
168
+ mpuj_messages = []
169
+ current_role = None
170
+ current_parts = []
171
+
172
+ message_blocks = re.split(r'\n\n(?=[A-Za-z0-9_-]+:\s*)', trimmed_plato_text)
173
+
174
+ for block in message_blocks:
175
+ current_block = block.strip()
176
+ if not current_block:
177
+ continue
178
+
179
+ speaker_match = re.match(r'^([A-Za-z0-9_-]+):\s*', current_block)
180
+ if not speaker_match:
181
+ continue
182
+
183
+ speaker = speaker_match.group(1)
184
+ raw_utterance = current_block[len(speaker_match.group(0)):]
185
+
186
+ is_thoughts = False
187
+ if raw_utterance.strip().startswith('(thinking)'):
188
+ is_thoughts = True
189
+ raw_utterance = re.sub(r'^\s*\(thinking\)\s*', '', raw_utterance)
190
+
191
+ utterance = re.sub(r'\n{2,}', '\n\t', raw_utterance).strip()
192
+
193
+ final_utterance = utterance
194
+ if is_thoughts:
195
+ final_utterance = f"(thinking) {utterance}"
196
+
197
+ is_model_message = speaker.upper() == model_name_upper
198
+ role = 'model' if is_model_message else 'user'
199
+
200
+ if role != current_role:
201
+ if len(current_parts) > 0:
202
+ mpuj_messages.append({
203
+ 'role': current_role,
204
+ 'parts': current_parts
205
+ })
206
+ current_role = role
207
+ current_parts = []
208
+
209
+ current_parts.append({'text': f"{speaker}: {final_utterance}"})
210
+
211
+ if len(current_parts) > 0:
212
+ mpuj_messages.append({
213
+ 'role': current_role,
214
+ 'parts': current_parts
215
+ })
216
+
217
+ return mpuj_messages
218
+
219
+
220
+ def new_plato_text(thoughts, text, machine_name):
221
+ """
222
+ Transforms a pair of text variables 'thoughts' and 'text' received
223
+ from the LLM and cleaned up from the markdown crap into a plato_text
224
+ format as new utterances of this machine, with its name as a speaker.
225
+ Does not form a 'thoughts' utterance if there were not 'thoughts'.
226
+
227
+ The result is later added to the input plato_text that came to the
228
+ machine through a pipe.
229
+ """
230
+ result = ""
231
+ if thoughts and thoughts.strip():
232
+ cleaned_thoughts = re.sub(r'\n{2,}', '\n\t', thoughts.strip())
233
+ result += f"{machine_name}: (thinking) {cleaned_thoughts}\n\n"
234
+
235
+ if text and text.strip():
236
+ cleaned_text = re.sub(r'\n{2,}', '\n\t', text.strip())
237
+ result += f"{machine_name}: {cleaned_text}\n\n"
238
+
239
+ return result
240
+
241
+
242
+ def llm_soup_to_text(llm_response):
243
+ """
244
+ Cleans and transforms text from Large Language Models (LLMs) by:
245
+ - Removing all Markdown formatting (bold, italics, headers, lists, code blocks, links, etc.).
246
+ - Consolidating multiple newlines into a consistent paragraph separator (`\n\t`).
247
+ - Removing extraneous tabs and multiple spaces.
248
+ - Trimming leading/trailing whitespace.
249
+ """
250
+ if not isinstance(llm_response, str):
251
+ return ""
252
+
253
+ text = llm_response
254
+
255
+ # --- Step 1: Normalize Newlines & Initial Cleanup ---
256
+ text = text.replace('\r\n', '\n')
257
+ text = re.sub(r'\n{2,}', '\n\n', text)
258
+
259
+ # --- Step 2: Remove Block-Level Markdown Elements ---
260
+ text = re.sub(r'`{3,}[^\n]*\n([\s\S]*?)\n`{3,}', '', text)
261
+ text = re.sub(r'~{3,}[^\n]*\n([\s\S]*?)\n~{3,}', '', text)
262
+ text = re.sub(r'<!--[\s\S]*?-->', '', text)
263
+ text = re.sub(r'<[^>]+>', '', text)
264
+ text = re.sub(r'^\s*(?:-|\*|_){3,}\s*$', '', text, flags=re.MULTILINE)
265
+ text = re.sub(r'^\s*>\s*', '', text, flags=re.MULTILINE)
266
+
267
+ # --- Step 3: Remove Inline Markdown Elements ---
268
+ text = re.sub(r'^\s*#{1,6}\s*', '', text, flags=re.MULTILINE)
269
+ text = re.sub(r'^([^\n]+)\n\s*(?:=|-){2,}\s*$', r'\1', text, flags=re.MULTILINE)
270
+ text = re.sub(r'!?\[.*?\]\(.*?\)', '', text)
271
+ text = re.sub(r'`([^`]+)`', r'\1', text)
272
+ text = re.sub(r'\*\*([^*]+?)\*\*', r'\1', text)
273
+ text = re.sub(r'__([^_]+?)__', r'\1', text)
274
+ text = re.sub(r'\*([^*]+?)\*', r'\1', text)
275
+ text = re.sub(r'_([^_]+?)_', r'\1', text)
276
+ text = re.sub(r'^\s*(?:[-*+]|\d+\.)\s+', '', text, flags=re.MULTILINE)
277
+
278
+ # --- Step 4: Final Whitespace & Paragraph Normalization ---
279
+ text = '\n'.join(line.strip() for line in text.split('\n'))
280
+ text = text.replace('\t', ' ')
281
+ text = re.sub(r' {2,}', ' ', text)
282
+ text = text.replace('\n\n', '\n\t')
283
+
284
+ # --- Step 5: Final Trimming ---
285
+ text = text.strip()
286
+ text = re.sub(r'^[\n\t]+', '', text)
287
+ text = re.sub(r'\n\t{2,}', '\n\t', text)
288
+
289
+ return text
290
+
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: conceptualizing-machine
3
+ Version: 0.0.1
4
+ Summary: A Machine that conceptualizes meanings.
5
+ Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>
6
+ Project-URL: Homepage, https://github.com/conceptualizing-machine/conceptualizing-machine
7
+ Keywords: conceptualizing-machine
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: electroid>=0.0.19
15
+ Requires-Dist: opehaina>=0.0.5
16
+ Requires-Dist: castor-pollux>=0.1.4
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
+ # Conceptualizing Machine
25
+ A Machine that conceptualizes meanings.
26
+ ```bash
27
+ echo "Theodotos-Alexandreus: Are language models seeking the Truth, machine?" \
28
+ | uvx conceptualizing-machine \
29
+ --provider-api-key=sk-ant-api... \
30
+ --github-token=ghp_...
31
+ ```
32
+ Or:
33
+ ```bash
34
+ pip install conceptualizing-machine
35
+ ```
36
+ Then:
37
+ ```Python
38
+ # Python
39
+ import conceptualizing_machine
40
+ ```
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ src/conceptualizing_machine/__init__.py
6
+ src/conceptualizing_machine/cli.py
7
+ src/conceptualizing_machine/config.py
8
+ src/conceptualizing_machine/githf.py
9
+ src/conceptualizing_machine/machina.yaml
10
+ src/conceptualizing_machine/machine.py
11
+ src/conceptualizing_machine/utilities.py
12
+ src/conceptualizing_machine.egg-info/PKG-INFO
13
+ src/conceptualizing_machine.egg-info/SOURCES.txt
14
+ src/conceptualizing_machine.egg-info/dependency_links.txt
15
+ src/conceptualizing_machine.egg-info/entry_points.txt
16
+ src/conceptualizing_machine.egg-info/requires.txt
17
+ src/conceptualizing_machine.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ conceptualizing-machine = conceptualizing_machine.cli:run
@@ -0,0 +1,8 @@
1
+ electroid>=0.0.19
2
+ opehaina>=0.0.5
3
+ castor-pollux>=0.1.4
4
+ PyGithub>=2.6.0
5
+ PyYAML>=6.0.1
6
+ urllib3>=2.0.4
7
+ requests>=2.32.3
8
+ click>=8.3.0