modi-cogitandi 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.
Files changed (32) hide show
  1. modi_cogitandi-0.0.1/LICENSE +21 -0
  2. modi_cogitandi-0.0.1/MANIFEST.in +1 -0
  3. modi_cogitandi-0.0.1/PKG-INFO +76 -0
  4. modi_cogitandi-0.0.1/README.md +60 -0
  5. modi_cogitandi-0.0.1/pyproject.toml +32 -0
  6. modi_cogitandi-0.0.1/setup.cfg +4 -0
  7. modi_cogitandi-0.0.1/src/modi_cogitandi/__init__.py +20 -0
  8. modi_cogitandi-0.0.1/src/modi_cogitandi/cli.py +151 -0
  9. modi_cogitandi-0.0.1/src/modi_cogitandi/config.py +43 -0
  10. modi_cogitandi-0.0.1/src/modi_cogitandi/functions.py +493 -0
  11. modi_cogitandi-0.0.1/src/modi_cogitandi/githf.py +83 -0
  12. modi_cogitandi-0.0.1/src/modi_cogitandi/machina.yaml +70 -0
  13. modi_cogitandi-0.0.1/src/modi_cogitandi/main.py +167 -0
  14. modi_cogitandi-0.0.1/src/modi_cogitandi/providers/__init__.py +7 -0
  15. modi_cogitandi-0.0.1/src/modi_cogitandi/providers/camelids.py +161 -0
  16. modi_cogitandi-0.0.1/src/modi_cogitandi/providers/depsek.py +164 -0
  17. modi_cogitandi-0.0.1/src/modi_cogitandi/providers/fireworks.py +185 -0
  18. modi_cogitandi-0.0.1/src/modi_cogitandi/providers/metai.py +170 -0
  19. modi_cogitandi-0.0.1/src/modi_cogitandi/providers/openai.py +169 -0
  20. modi_cogitandi-0.0.1/src/modi_cogitandi/providers/strangelove.py +170 -0
  21. modi_cogitandi-0.0.1/src/modi_cogitandi/providers/tinker.py +200 -0
  22. modi_cogitandi-0.0.1/src/modi_cogitandi/utilities.py +433 -0
  23. modi_cogitandi-0.0.1/src/modi_cogitandi.egg-info/PKG-INFO +76 -0
  24. modi_cogitandi-0.0.1/src/modi_cogitandi.egg-info/SOURCES.txt +30 -0
  25. modi_cogitandi-0.0.1/src/modi_cogitandi.egg-info/dependency_links.txt +1 -0
  26. modi_cogitandi-0.0.1/src/modi_cogitandi.egg-info/entry_points.txt +2 -0
  27. modi_cogitandi-0.0.1/src/modi_cogitandi.egg-info/requires.txt +1 -0
  28. modi_cogitandi-0.0.1/src/modi_cogitandi.egg-info/top_level.txt +1 -0
  29. modi_cogitandi-0.0.1/tests/test_cli.py +20 -0
  30. modi_cogitandi-0.0.1/tests/test_e2e.py +45 -0
  31. modi_cogitandi-0.0.1/tests/test_llm_soup.py +71 -0
  32. modi_cogitandi-0.0.1/tests/test_utilities.py +69 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 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/modi_cogitandi/*.yaml
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.4
2
+ Name: modi-cogitandi
3
+ Version: 0.0.1
4
+ Summary: Modes of thought.
5
+ Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>, Alexander Fedotov <alex.fedotov@aol.com>
6
+ Project-URL: Homepage, https://github.com/modi-cogitandi/modi-cogitandi
7
+ Keywords: modi-cogitandi
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: pyyaml==6.0.3
15
+ Dynamic: license-file
16
+
17
+ # Modi-Cogitandi
18
+ Modes of thought
19
+
20
+ In order to launch it from the command line or as a Python subprocess:
21
+ ```bash
22
+ echo "Theodotos-Alexandreus: What mode of thought should we use, machine?" \
23
+ | uvx modi-cogitandi \
24
+ --provider-api-key=sk-proj-... \
25
+ --github-token=ghp_...
26
+ ```
27
+
28
+ Or, with a local pip installation:
29
+ ```bash
30
+ pip install modi-cogitandi
31
+ ```
32
+ Set the environment variables:
33
+ ```bash
34
+ export PROVIDER_API_KEY="sk-proj-..."
35
+ export GITHUB_TOKEN="ghp_..."
36
+ ```
37
+ Then:
38
+ ```bash
39
+ modi-cogitandi multilogue.txt
40
+ ```
41
+ Or:
42
+ ```bash
43
+ modi-cogitandi multilogue.txt > output.txt
44
+ ```
45
+ Or:
46
+ ```bash
47
+ modi-cogitandi multilogue.txt > tmp && mv tmp multilogue.txt
48
+ ```
49
+ Or:
50
+ ```bash
51
+ cat multilogue.txt new_turn.txt | modi-cogitandi
52
+ ```
53
+ Or:
54
+ ```bash
55
+ cat multilogue.txt new_turn.txt | modi-cogitandi > tmp && mv tmp multilogue.txt
56
+ ```
57
+ Or:
58
+ ```bash
59
+ (cat multilogue.txt; echo:"Theodotos: What do you think, Modi-Cogitandi?") \
60
+ | modi-cogitandi
61
+ ```
62
+ Or:
63
+ ```bash
64
+ cat multilogue.txt new_turn.txt | modi-cogitandi > tmp && mv tmp multilogue.txt
65
+ ```
66
+ Or, if you have installed other machines:
67
+ ```bash
68
+ cat multilogue.md | modi-cogitandi \
69
+ | summarizing-machine | judging-machine > summary_judgment.md
70
+ ```
71
+
72
+ Or use it in your Python code:
73
+ ```Python
74
+ # Python
75
+ import modi_cogitandi
76
+ ```
@@ -0,0 +1,60 @@
1
+ # Modi-Cogitandi
2
+ Modes of thought
3
+
4
+ In order to launch it from the command line or as a Python subprocess:
5
+ ```bash
6
+ echo "Theodotos-Alexandreus: What mode of thought should we use, machine?" \
7
+ | uvx modi-cogitandi \
8
+ --provider-api-key=sk-proj-... \
9
+ --github-token=ghp_...
10
+ ```
11
+
12
+ Or, with a local pip installation:
13
+ ```bash
14
+ pip install modi-cogitandi
15
+ ```
16
+ Set the environment variables:
17
+ ```bash
18
+ export PROVIDER_API_KEY="sk-proj-..."
19
+ export GITHUB_TOKEN="ghp_..."
20
+ ```
21
+ Then:
22
+ ```bash
23
+ modi-cogitandi multilogue.txt
24
+ ```
25
+ Or:
26
+ ```bash
27
+ modi-cogitandi multilogue.txt > output.txt
28
+ ```
29
+ Or:
30
+ ```bash
31
+ modi-cogitandi multilogue.txt > tmp && mv tmp multilogue.txt
32
+ ```
33
+ Or:
34
+ ```bash
35
+ cat multilogue.txt new_turn.txt | modi-cogitandi
36
+ ```
37
+ Or:
38
+ ```bash
39
+ cat multilogue.txt new_turn.txt | modi-cogitandi > tmp && mv tmp multilogue.txt
40
+ ```
41
+ Or:
42
+ ```bash
43
+ (cat multilogue.txt; echo:"Theodotos: What do you think, Modi-Cogitandi?") \
44
+ | modi-cogitandi
45
+ ```
46
+ Or:
47
+ ```bash
48
+ cat multilogue.txt new_turn.txt | modi-cogitandi > tmp && mv tmp multilogue.txt
49
+ ```
50
+ Or, if you have installed other machines:
51
+ ```bash
52
+ cat multilogue.md | modi-cogitandi \
53
+ | summarizing-machine | judging-machine > summary_judgment.md
54
+ ```
55
+
56
+ Or use it in your Python code:
57
+ ```Python
58
+ # Python
59
+ import modi_cogitandi
60
+ ```
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools==82.0.1"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "modi-cogitandi"
7
+ version = "0.0.1"
8
+ authors = [
9
+ {name="Machina Ratiocinatrix", email="machina.ratio@gmail.com"},
10
+ {name="Alexander Fedotov", email="alex.fedotov@aol.com"}
11
+ ]
12
+ description = "Modes of thought."
13
+ readme = "README.md"
14
+ requires-python = ">=3.10"
15
+ classifiers=[
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+ keywords = ["modi-cogitandi"]
21
+ dependencies = [
22
+ "pyyaml == 6.0.3"
23
+ ]
24
+
25
+ [project.scripts]
26
+ modi-cogitandi = "modi_cogitandi.cli:run"
27
+
28
+ [project.urls]
29
+ "Homepage" = "https://github.com/modi-cogitandi/modi-cogitandi"
30
+
31
+ [dependency-groups]
32
+ dev = ["pytest>=8.0.0"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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 .main import machina
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
+ 'machina',
18
+ 'fetch_instructions',
19
+ 'Config'
20
+ ]
@@ -0,0 +1,151 @@
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
+ parser = argparse.ArgumentParser(
20
+ description="Machina-Ratiocinatrix ratiocinates.",
21
+ epilog="Example: machina input_text.txt > output_text.txt"
22
+ )
23
+
24
+ # Give the access key and token, or set the environment variables in advance.
25
+ parser.add_argument('-p', '--provider-api-key',
26
+ default=os.getenv('PROVIDER_API_KEY', 'no_key'),
27
+ help="LLM provider API key (defaults to $PROVIDER_API_KEY)")
28
+ parser.add_argument('-g', '--github-token',
29
+ default=os.getenv('GITHUB_TOKEN', 'no_token'),
30
+ help="GitHub API token (defaults to $GITHUB_TOKEN)")
31
+
32
+ parser.add_argument('-a', '--append',
33
+ action='store_true',
34
+ help="Append the proceeds to the input.")
35
+
36
+ parser.add_argument('-d', '--debug',
37
+ action='store_true',
38
+ help="Debug flag.")
39
+
40
+ parser.add_argument('-i', '--interactive',
41
+ action='store_true',
42
+ help="Enable interactive mode (defaults to False)")
43
+
44
+ # Positional arguments (files)
45
+ # '*' captures zero or more arguments into a list, nargs='+' one or more.
46
+ parser.add_argument('filenames',
47
+ nargs='*',
48
+ help="Zero (when text comes though a pipe) or more files to process.")
49
+ return parser
50
+
51
+
52
+ def run():
53
+ """After installation, on Linux prompt
54
+ $ machina file1.txt file2.txt > output.txt
55
+ """
56
+ args = options_and_arguments().parse_args()
57
+
58
+ # If no files are provided AND no data is being piped in - exit.
59
+ # if not args.filenames:
60
+ # # Check if stdin (fd 0) is ready to be read
61
+ # readable, _, _ = select.select([sys.stdin], [], [], 0.1)
62
+ # if not readable:
63
+ # print("Error: No input files or piped text stream.")
64
+ # options_and_arguments().print_help()
65
+ # sys.exit(1)
66
+
67
+ # Ingest files line by line. Join is here for long files.
68
+ # lines = []
69
+ # for line in fileinput.input(files=args.filenames or ['-'], encoding="utf-8"):
70
+ # lines.append(line)
71
+ # raw_input = "".join(lines)
72
+
73
+ config = Config()
74
+
75
+ if args.provider_api_key:
76
+ if args.provider_api_key.startswith('sk-'):
77
+ if args.provider_api_key.startswith('sk-proj-'):
78
+ config.provider = 'OpenAI'
79
+ os.environ['OPENAI_API_KEY'] = args.provider_api_key
80
+ elif args.provider_api_key.startswith('sk-ant-'):
81
+ config.provider = 'Anthropic'
82
+ os.environ['ANTHROPIC_API_KEY'] = args.provider_api_key
83
+ elif args.provider_api_key.startswith('LLM_'):
84
+ config.provider = 'MetAI'
85
+ os.environ['METAI_API_KEY'] = args.provider_api_key
86
+ elif args.provider_api_key.startswith('tml-'):
87
+ config.provider = 'Tinker'
88
+ os.environ['TINKER_API_KEY'] = args.provider_api_key
89
+ else:
90
+ if config.provider == '':
91
+ raise ValueError(f"Unrecognized API key prefix and no provider specified.")
92
+ else:
93
+ if config.provider == 'Baseten':
94
+ os.environ['BASETEN_API_KEY'] = args.provider_api_key
95
+ elif config.provider == 'Fireworks':
96
+ os.environ['FIREWORKS_API_KEY'] = args.provider_api_key
97
+ elif config.provider == 'Lightning':
98
+ os.environ['LIGHTNING_API_KEY'] = args.provider_api_key
99
+ elif config.provider == 'DepSek':
100
+ os.environ['DEPSEK_API_KEY'] = args.provider_api_key
101
+ else:
102
+ raise ValueError(f"Unsupported provider specified.")
103
+
104
+
105
+ config.provider_api_key = args.provider_api_key
106
+
107
+ if args.github_token:
108
+ config.github_token = args.github_token
109
+ os.environ['GITHUB_TOKEN'] = args.github_token
110
+
111
+ # Ingest files line by line. Join is here for long files.
112
+ lines = []
113
+ for line in fileinput.input(files=args.filenames or ['-'], encoding="utf-8"):
114
+ lines.append(line)
115
+ raw_input = "".join(lines)
116
+
117
+ from .main import machina
118
+
119
+ try:
120
+ thoughts, text = machina(raw_input, config)
121
+ output = new_plato_text(thoughts, text, config.name)
122
+ if args.append:
123
+ output = raw_input + '\n\n' + output
124
+ sys.stdout.write(output)
125
+ sys.stdout.flush()
126
+
127
+ # Assesment and signals.
128
+
129
+ utterance = "Machina is ready"
130
+ # Open syslog connection
131
+ syslog.openlog(
132
+ ident="machina-ratiocinatrix",
133
+ logoption=syslog.LOG_NDELAY,
134
+ facility=syslog.LOG_USER
135
+ )
136
+ # Signal (single line less than 4096 only!)
137
+ syslog.syslog(syslog.LOG_INFO, utterance)
138
+ syslog.closelog()
139
+
140
+ except Exception as e:
141
+ if args.debug:
142
+ import traceback
143
+ traceback.print_exc()
144
+ else:
145
+ sys.stderr.write(f'Machina did not work {e}\n')
146
+ sys.stderr.flush()
147
+ sys.exit(1)
148
+
149
+
150
+ if __name__ == '__main__':
151
+ run()
@@ -0,0 +1,43 @@
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, fields, 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
+ machine_organization_name: str = field(
20
+ default_factory=lambda: environ.get('ORGANIZATION_NAME', 'machina-ratiocinatrix'))
21
+ private_repo_with_text: str = field(
22
+ default_factory=lambda: environ.get('REPO_WITH_INSTRUCTIONS', 'machina_ratiocinatrix'))
23
+ system_prompt_file: str = field(default_factory=lambda: environ.get('SYSTEM_INSTRUCTIONS_FILE', 'machina.yaml'))
24
+ name: str = field(default_factory=lambda: environ.get('NAME', ''))
25
+ instructions: str = field(default_factory=lambda: environ.get('INSTRUCTIONS', ''))
26
+ verb: str = field(default_factory=lambda: environ.get('VERB', ''))
27
+ tools: str = field(
28
+ default_factory=lambda: environ.get('TOOLS', '')) # Swapped [] to '' for consistency with str annotation
29
+ rubric: str = field(default_factory=lambda: environ.get('RUBRIC', ''))
30
+
31
+ def to_dict(self):
32
+ return asdict(self)
33
+
34
+ def update_from_dict(self, data: dict):
35
+ # Now self.__dict__ is fully populated, but fields() is still safer!
36
+ valid_fields = {f.name for f in fields(self)}
37
+ for key, value in data.items():
38
+ if key in valid_fields:
39
+ setattr(self, key, value)
40
+
41
+
42
+ if __name__ == '__main__':
43
+ ...