hugpy-engine 0.3.16__tar.gz → 0.4.0__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 (167) hide show
  1. hugpy_engine-0.4.0/PKG-INFO +52 -0
  2. hugpy_engine-0.4.0/README.md +42 -0
  3. hugpy_engine-0.4.0/pyproject.toml +23 -0
  4. hugpy_engine-0.4.0/src/hugpy_engine/__init__.py +19 -0
  5. hugpy_engine-0.4.0/src/hugpy_engine/__main__.py +5 -0
  6. hugpy_engine-0.4.0/src/hugpy_engine/cli/__init__.py +4 -0
  7. hugpy_engine-0.4.0/src/hugpy_engine/cli/cli.py +414 -0
  8. hugpy_engine-0.4.0/src/hugpy_engine/imports/__init__.py +10 -0
  9. hugpy_engine-0.4.0/src/hugpy_engine/imports/constants.py +119 -0
  10. hugpy_engine-0.4.0/src/hugpy_engine/imports/init_imports.py +26 -0
  11. hugpy_engine-0.4.0/src/hugpy_engine/imports/module_imports.py +54 -0
  12. hugpy_engine-0.4.0/src/hugpy_engine/install/__init__.py +20 -0
  13. hugpy_engine-0.4.0/src/hugpy_engine/install/install.py +506 -0
  14. hugpy_engine-0.4.0/src/hugpy_engine/launch/__init__.py +9 -0
  15. hugpy_engine-0.4.0/src/hugpy_engine/launch/launch.py +319 -0
  16. hugpy_engine-0.4.0/src/hugpy_engine/launch/requests.py +64 -0
  17. hugpy_engine-0.4.0/src/hugpy_engine/launch/templates.py +89 -0
  18. hugpy_engine-0.4.0/src/hugpy_engine/observe/__init__.py +4 -0
  19. hugpy_engine-0.4.0/src/hugpy_engine/observe/observe.py +63 -0
  20. hugpy_engine-0.4.0/src/hugpy_engine/profiles/__init__.py +17 -0
  21. hugpy_engine-0.4.0/src/hugpy_engine/profiles/manifests.py +113 -0
  22. hugpy_engine-0.4.0/src/hugpy_engine/profiles/profiles.py +175 -0
  23. hugpy_engine-0.4.0/src/hugpy_engine/registry/__init__.py +18 -0
  24. hugpy_engine-0.4.0/src/hugpy_engine/registry/registry.py +127 -0
  25. hugpy_engine-0.4.0/src/hugpy_engine/registry/requirements.py +573 -0
  26. hugpy_engine-0.4.0/src/hugpy_engine/registry/specs.py +251 -0
  27. hugpy_engine-0.4.0/src/hugpy_engine/report/__init__.py +4 -0
  28. hugpy_engine-0.4.0/src/hugpy_engine/report/report.py +86 -0
  29. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/PROVENANCE.md +227 -0
  30. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/__init__.py +8 -0
  31. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/cli/__init__.py +2 -0
  32. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/cli/scout_evidence.py +343 -0
  33. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/__init__.py +1 -0
  34. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/backends.py +168 -0
  35. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/bnb4_convert.py +171 -0
  36. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/comfy_families.py +185 -0
  37. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/dequant.py +309 -0
  38. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/discovery.py +231 -0
  39. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/minimax_repack.py +163 -0
  40. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/moe_split.py +41 -0
  41. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/placement.py +64 -0
  42. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/profiles.py +600 -0
  43. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/RIFE_LICENSE.txt +21 -0
  44. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/__init__.py +489 -0
  45. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/asr.py +351 -0
  46. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/char360.py +428 -0
  47. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/comfy.py +600 -0
  48. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/embed.py +173 -0
  49. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/imagegen.py +650 -0
  50. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/keywords.py +209 -0
  51. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/mesh3d.py +519 -0
  52. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/rife_network.py +173 -0
  53. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/rife_warp.py +17 -0
  54. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/summarize.py +384 -0
  55. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/tts.py +692 -0
  56. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/videogen.py +1993 -0
  57. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/videointerp.py +156 -0
  58. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/videoupres.py +297 -0
  59. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/runners/wan_s2v.py +40 -0
  60. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/shared.py +291 -0
  61. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/task_child.py +540 -0
  62. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/tf_child.py +620 -0
  63. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/engines/vision_child.py +569 -0
  64. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/__init__.py +33 -0
  65. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/classes/__init__.py +24 -0
  66. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/classes/runners.py +54 -0
  67. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/__init__.py +891 -0
  68. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/admission.py +13 -0
  69. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/audio.py +70 -0
  70. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/authentication.py +23 -0
  71. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/cli.py +158 -0
  72. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/context.py +69 -0
  73. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/cpu.py +23 -0
  74. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/discovery.py +431 -0
  75. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/engines.py +171 -0
  76. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/environment.py +113 -0
  77. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/estimation.py +61 -0
  78. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/hardware.py +27 -0
  79. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/memory.py +11 -0
  80. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/models.py +45 -0
  81. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/observability.py +39 -0
  82. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/placement.py +199 -0
  83. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/policy.py +14 -0
  84. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/prediction.py +5 -0
  85. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/runners.py +215 -0
  86. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/serving.py +432 -0
  87. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/storage.py +17 -0
  88. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/constants/video.py +116 -0
  89. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/functions/__init__.py +29 -0
  90. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/functions/children.py +19 -0
  91. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/functions/environment.py +46 -0
  92. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/functions/paths.py +40 -0
  93. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/imports/init_imports.py +246 -0
  94. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/probes/__init__.py +1 -0
  95. hugpy_engine-0.4.0/src/hugpy_engine/runtime/kg_engines/probes/calibration.py +34 -0
  96. hugpy_engine-0.4.0/src/hugpy_engine/settings/__init__.py +21 -0
  97. hugpy_engine-0.4.0/src/hugpy_engine/settings/settings.py +157 -0
  98. hugpy_engine-0.4.0/src/hugpy_engine/sql/__init__.py +8 -0
  99. hugpy_engine-0.4.0/src/hugpy_engine/sql/installed.py +59 -0
  100. hugpy_engine-0.4.0/src/hugpy_engine/sql/state.py +97 -0
  101. hugpy_engine-0.4.0/src/hugpy_engine/sql/state_tables.py +292 -0
  102. hugpy_engine-0.4.0/src/hugpy_engine/state/__init__.py +4 -0
  103. hugpy_engine-0.4.0/src/hugpy_engine/state/state.py +205 -0
  104. hugpy_engine-0.4.0/src/hugpy_engine/system/__init__.py +21 -0
  105. hugpy_engine-0.4.0/src/hugpy_engine/system/system.py +96 -0
  106. hugpy_engine-0.4.0/src/hugpy_engine/telemetry/__init__.py +4 -0
  107. hugpy_engine-0.4.0/src/hugpy_engine/telemetry/telemetry.py +90 -0
  108. hugpy_engine-0.4.0/src/hugpy_engine/tui/__init__.py +4 -0
  109. hugpy_engine-0.4.0/src/hugpy_engine/tui/tui.py +229 -0
  110. hugpy_engine-0.4.0/src/hugpy_engine.egg-info/PKG-INFO +52 -0
  111. hugpy_engine-0.4.0/src/hugpy_engine.egg-info/SOURCES.txt +115 -0
  112. hugpy_engine-0.4.0/src/hugpy_engine.egg-info/entry_points.txt +2 -0
  113. hugpy_engine-0.4.0/src/hugpy_engine.egg-info/requires.txt +3 -0
  114. hugpy_engine-0.4.0/tests/test_task_inputs.py +99 -0
  115. hugpy_engine-0.3.16/PKG-INFO +0 -182
  116. hugpy_engine-0.3.16/README.md +0 -163
  117. hugpy_engine-0.3.16/pyproject.toml +0 -41
  118. hugpy_engine-0.3.16/src/hugpy_engine/__init__.py +0 -49
  119. hugpy_engine-0.3.16/src/hugpy_engine/categories.py +0 -142
  120. hugpy_engine-0.3.16/src/hugpy_engine/config/__init__.py +0 -0
  121. hugpy_engine-0.3.16/src/hugpy_engine/config/main.py +0 -84
  122. hugpy_engine-0.3.16/src/hugpy_engine/config/models/__init__.py +0 -0
  123. hugpy_engine-0.3.16/src/hugpy_engine/config/models/models_config.py +0 -308
  124. hugpy_engine-0.3.16/src/hugpy_engine/config/models/models_default.py +0 -150
  125. hugpy_engine-0.3.16/src/hugpy_engine/core_auth.py +0 -14
  126. hugpy_engine-0.3.16/src/hugpy_engine/dispatch/__init__.py +0 -36
  127. hugpy_engine-0.3.16/src/hugpy_engine/dispatch/dispatch.py +0 -1358
  128. hugpy_engine-0.3.16/src/hugpy_engine/fit/__init__.py +0 -0
  129. hugpy_engine-0.3.16/src/hugpy_engine/fit/types.py +0 -458
  130. hugpy_engine-0.3.16/src/hugpy_engine/imports/__init__.py +0 -12
  131. hugpy_engine-0.3.16/src/hugpy_engine/imports/classes.py +0 -5
  132. hugpy_engine-0.3.16/src/hugpy_engine/imports/constants.py +0 -57
  133. hugpy_engine-0.3.16/src/hugpy_engine/imports/functions.py +0 -46
  134. hugpy_engine-0.3.16/src/hugpy_engine/imports/init_imports.py +0 -13
  135. hugpy_engine-0.3.16/src/hugpy_engine/llama/__init__.py +0 -0
  136. hugpy_engine-0.3.16/src/hugpy_engine/llama/runners/__init__.py +0 -0
  137. hugpy_engine-0.3.16/src/hugpy_engine/llama/runners/fitevict_runner.py +0 -203
  138. hugpy_engine-0.3.16/src/hugpy_engine/name_match.py +0 -287
  139. hugpy_engine-0.3.16/src/hugpy_engine/placement.py +0 -471
  140. hugpy_engine-0.3.16/src/hugpy_engine/py.typed +0 -0
  141. hugpy_engine-0.3.16/src/hugpy_engine/resolvers/__init__.py +0 -24
  142. hugpy_engine-0.3.16/src/hugpy_engine/resolvers/assure_model_key.py +0 -622
  143. hugpy_engine-0.3.16/src/hugpy_engine/resolvers/categories/__init__.py +0 -22
  144. hugpy_engine-0.3.16/src/hugpy_engine/resolvers/categories/builders.py +0 -173
  145. hugpy_engine-0.3.16/src/hugpy_engine/resolvers/categories/frameworks.py +0 -75
  146. hugpy_engine-0.3.16/src/hugpy_engine/resolvers/model_resolver.py +0 -643
  147. hugpy_engine-0.3.16/src/hugpy_engine/resolvers/task_resolution.py +0 -644
  148. hugpy_engine-0.3.16/src/hugpy_engine/schemas/__init__.py +0 -0
  149. hugpy_engine-0.3.16/src/hugpy_engine/schemas/chat_schemas.py +0 -355
  150. hugpy_engine-0.3.16/src/hugpy_engine/schemas/event_schemas.py +0 -68
  151. hugpy_engine-0.3.16/src/hugpy_engine/schemas/metadata_schemas.py +0 -63
  152. hugpy_engine-0.3.16/src/hugpy_engine/schemas/model_schemas.py +0 -101
  153. hugpy_engine-0.3.16/src/hugpy_engine/schemas/runner_schemas.py +0 -33
  154. hugpy_engine-0.3.16/src/hugpy_engine/schemas/task_schemas.py +0 -55
  155. hugpy_engine-0.3.16/src/hugpy_engine/task_deps.py +0 -67
  156. hugpy_engine-0.3.16/src/hugpy_engine/task_endpoints.py +0 -410
  157. hugpy_engine-0.3.16/src/hugpy_engine/tasks.py +0 -349
  158. hugpy_engine-0.3.16/src/hugpy_engine/utils/__init__.py +0 -1
  159. hugpy_engine-0.3.16/src/hugpy_engine/utils/json_scavenge.py +0 -111
  160. hugpy_engine-0.3.16/src/hugpy_engine/utils/model_marker.py +0 -35
  161. hugpy_engine-0.3.16/src/hugpy_engine/utils/no_think.py +0 -323
  162. hugpy_engine-0.3.16/src/hugpy_engine.egg-info/PKG-INFO +0 -182
  163. hugpy_engine-0.3.16/src/hugpy_engine.egg-info/SOURCES.txt +0 -51
  164. hugpy_engine-0.3.16/src/hugpy_engine.egg-info/requires.txt +0 -3
  165. {hugpy_engine-0.3.16 → hugpy_engine-0.4.0}/setup.cfg +0 -0
  166. {hugpy_engine-0.3.16 → hugpy_engine-0.4.0}/src/hugpy_engine.egg-info/dependency_links.txt +0 -0
  167. {hugpy_engine-0.3.16 → hugpy_engine-0.4.0}/src/hugpy_engine.egg-info/top_level.txt +0 -0
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: hugpy-engine
3
+ Version: 0.4.0
4
+ Summary: The engines of a host: install them, report what is there, start one on a model
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: hugpy-resources<0.2,>=0.1.17.29
8
+ Requires-Dist: hugpy-settings<0.2,>=0.1.18
9
+ Requires-Dist: abstract_essentials>=0.0.0.31
10
+
11
+ # hugpy-engine
12
+
13
+ The 0.4 series manages inference engines on a worker. It detects drivers and installed runtimes, describes the models and inputs each backend accepts, and prepares launch commands for Hugpy Wrapper.
14
+
15
+ ## Installation
16
+
17
+ Install the worker edition in a Python 3.11 or later environment. Media and Oracle use the earlier Engine client library in a separate environment.
18
+
19
+ ```sh
20
+ python -m pip install 'hugpy-engine>=0.4,<0.5'
21
+ ```
22
+
23
+ ## Quick start
24
+
25
+ Inspect the host before downloading any backend.
26
+
27
+ ```sh
28
+ hugpy-engine engines
29
+ hugpy-engine drivers
30
+ hugpy-engine requirements
31
+ hugpy-engine install all --plan
32
+ ```
33
+
34
+ Choose an engine name from the report. Run `hugpy-engine install ENGINE` to install it, then `hugpy-engine use ENGINE` to see its launch and request examples.
35
+
36
+ ## Worker interface
37
+
38
+ `hugpy-engine inputs` reports the required and optional inputs for each task. `hugpy-engine ask ENGINE MODEL --say "Hello"` starts an engine on a compatible local model, sends a chat request and stops the process. `hugpy-engine calls` displays recent launch and call records.
39
+
40
+ `hugpy-engine sync` refreshes `export.sqlite3`. Discovery and Wrapper read backend declarations from the export. Wrapper uses `hugpy-engine request` for launch details and `hugpy-engine record` to return execution records. The Engine database retains the host’s settings, environment inventory and history.
41
+
42
+ ## Compatibility with media services
43
+
44
+ For this release, the arms build uses `hugpy-engine 0.3.16.1`. That distribution provides Python client APIs such as `execute_prompt`. The worker build uses `0.4.0.21` and provides the `hugpy-engine` executable and export interface. Both builds have the same distribution name. Keep the worker and arms installations in separate virtual environments, and let Media or Oracle resolve the client requirement in the arms environment.
45
+
46
+ For an isolated check of the 0.3 arms environment, import the client there:
47
+
48
+ ```python
49
+ from hugpy_engine import execute_prompt
50
+ ```
51
+
52
+ A worker installation can be inspected separately with `hugpy-engine report --json`. This separation lets a media application submit work to the fleet without installing its inference backends in the application environment.
@@ -0,0 +1,42 @@
1
+ # hugpy-engine
2
+
3
+ The 0.4 series manages inference engines on a worker. It detects drivers and installed runtimes, describes the models and inputs each backend accepts, and prepares launch commands for Hugpy Wrapper.
4
+
5
+ ## Installation
6
+
7
+ Install the worker edition in a Python 3.11 or later environment. Media and Oracle use the earlier Engine client library in a separate environment.
8
+
9
+ ```sh
10
+ python -m pip install 'hugpy-engine>=0.4,<0.5'
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ Inspect the host before downloading any backend.
16
+
17
+ ```sh
18
+ hugpy-engine engines
19
+ hugpy-engine drivers
20
+ hugpy-engine requirements
21
+ hugpy-engine install all --plan
22
+ ```
23
+
24
+ Choose an engine name from the report. Run `hugpy-engine install ENGINE` to install it, then `hugpy-engine use ENGINE` to see its launch and request examples.
25
+
26
+ ## Worker interface
27
+
28
+ `hugpy-engine inputs` reports the required and optional inputs for each task. `hugpy-engine ask ENGINE MODEL --say "Hello"` starts an engine on a compatible local model, sends a chat request and stops the process. `hugpy-engine calls` displays recent launch and call records.
29
+
30
+ `hugpy-engine sync` refreshes `export.sqlite3`. Discovery and Wrapper read backend declarations from the export. Wrapper uses `hugpy-engine request` for launch details and `hugpy-engine record` to return execution records. The Engine database retains the host’s settings, environment inventory and history.
31
+
32
+ ## Compatibility with media services
33
+
34
+ For this release, the arms build uses `hugpy-engine 0.3.16.1`. That distribution provides Python client APIs such as `execute_prompt`. The worker build uses `0.4.0.21` and provides the `hugpy-engine` executable and export interface. Both builds have the same distribution name. Keep the worker and arms installations in separate virtual environments, and let Media or Oracle resolve the client requirement in the arms environment.
35
+
36
+ For an isolated check of the 0.3 arms environment, import the client there:
37
+
38
+ ```python
39
+ from hugpy_engine import execute_prompt
40
+ ```
41
+
42
+ A worker installation can be inspected separately with `hugpy-engine report --json`. This separation lets a media application submit work to the fleet without installing its inference backends in the application environment.
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "hugpy-engine"
7
+ version = "0.4.0"
8
+ description = "The engines of a host: install them, report what is there, start one on a model"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ dependencies = ["hugpy-resources>=0.1.17.29,<0.2", "hugpy-settings>=0.1.18,<0.2", "abstract_essentials>=0.0.0.31"]
12
+
13
+ [project.scripts]
14
+ hugpy-engine = "hugpy_engine.cli:main"
15
+
16
+ [tool.setuptools]
17
+ package-dir = {"" = "src"}
18
+
19
+ [tool.setuptools.packages.find]
20
+ where = ["src"]
21
+
22
+ [tool.setuptools.package-data]
23
+ "hugpy_engine" = ["runtime/**/*"]
@@ -0,0 +1,19 @@
1
+ """hugpy-engine: the engines of a host. It installs them, says what is there, and gives their minimal use.
2
+ (The queue and the front door are hugpy-wrapper. hugpy-engine before 0.4 was a client library; nothing of it is here.)
3
+
4
+ from hugpy_engine import engines, report, start, call, stop
5
+
6
+ install fetch what the engines need (install.py) and build each engine's environment (profiles.py)
7
+ registry every engine as data: what it serves, how it is started
8
+ report the settings, environments and engines of this host: the record other components read
9
+ launch start an engine on a model, call it, stop it
10
+
11
+ It manages no memory, queue or drives: whoever does passes what it decided to ``launch.start``.
12
+ """
13
+ from . import install, launch, profiles, registry, report as _report, settings
14
+ from .launch import EngineError, Running, call, command, environment, health_ok, start, stop
15
+ from .registry import by_endpoint, engines, get
16
+ from .report import report
17
+
18
+ __all__ = ["engines", "get", "by_endpoint", "report", "command", "environment", "start", "health_ok", "call", "stop",
19
+ "Running", "EngineError"]
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,4 @@
1
+ """The command line of hugpy-engine."""
2
+ from .cli import main, run
3
+
4
+ __all__ = ['main', 'run']
@@ -0,0 +1,414 @@
1
+ """hugpy-engine: the engines of this host. Install them, see what is there, and start one on a model.
2
+
3
+ hugpy-engine in a terminal: the screen (tui)
4
+ hugpy-engine tui the screen: every setting, engine and engine environment, changed
5
+ in place (Settings, Engines, Environments, Installed)
6
+ hugpy-engine engines every engine: what it serves and whether it can start here
7
+ hugpy-engine requirements [ENGINE...] [--json] each engine's venv, interpreter and path, and everything it
8
+ needs installed, one line each: [x] there, [ ] not there
9
+ hugpy-engine inputs [ENGINE...] [--json] for every task of each engine: what a call must carry and may
10
+ hugpy-engine use [ENGINE...] [--json] for every task of each engine: the command that starts it on a
11
+ model, how it is known to answer, the endpoint of the task and
12
+ the simplest call it answers ({placeholders} are the caller's)
13
+ hugpy-engine drivers [--json] the card driver's files on this host, and what each engine reaches
14
+ a card through (the libraries a program is linked to, the torch
15
+ build and CUDA libraries of an engine's environment)
16
+ hugpy-engine report [--json] [--sizes] the settings, the engine environments and the engines (the record
17
+ other components read)
18
+ hugpy-engine install [--plan] ENGINE...|all bring the named engines (all: every one) to where they can start
19
+ here; --plan only says what each needs and what is there
20
+ hugpy-engine environments [build NAME...] the engine environments; build the named ones (all: every one)
21
+ hugpy-engine settings every setting, its value and where it comes from
22
+ hugpy-engine set KEY VALUE save one setting in the database
23
+ hugpy-engine reset KEY... drop a saved setting: its default applies again
24
+ hugpy-engine migrate-settings [FILE] once: the engine settings of an earlier settings.json into the database
25
+ hugpy-engine run ENGINE MODEL [options] start ENGINE on MODEL, say where it answers, run until Ctrl+C
26
+ hugpy-engine ask ENGINE MODEL --say "text" start it, send one chat message, print the answer, stop it
27
+ (after --, arguments are passed to the engine as they are)
28
+ hugpy-engine sync write the engines' state into the database (what each is, its
29
+ install state, what it asks of a model and of a call) and refresh
30
+ the export other tools read
31
+ hugpy-engine observe ENGINE MODEL run ENGINE once on MODEL and keep every file it looked for in the
32
+ model folder: what it is seen to read becomes what it asks for
33
+ hugpy-engine calls [--limit N] [--json] the raw record: the latest starts and calls, with their rates
34
+ hugpy-engine record keep the start and call records of another tool: one JSON object
35
+ per line on the standard input (telemetry/telemetry.py)
36
+ hugpy-engine request answer one request of another tool: a JSON message on the standard
37
+ input, the JSON reply on the standard output (launch/requests.py)
38
+ hugpy-engine system install|status|uninstall as a tool of the whole host: its data in /var/lib/hugpy/engine,
39
+ shared by the group hugpy (system/system.py; install as root)
40
+ """
41
+ from ..imports import (
42
+ argparse,
43
+ data_folder_refusal,
44
+ driver_files,
45
+ ENV_FILE,
46
+ json,
47
+ os,
48
+ share_new_files,
49
+ sys,
50
+ time,
51
+ )
52
+ from ..observe import observe
53
+ from ..sql import connect, rows_of
54
+ from ..state import refresh
55
+ from ..telemetry import call_record, record, start_record
56
+ from .. import launch
57
+ from ..report import report
58
+ from .. import install as installer
59
+ from ..registry import engines
60
+ from .. import settings
61
+ from .. import profiles
62
+ from ..tui import tui
63
+ from ..system import main as system_main
64
+
65
+
66
+ def _options(parser):
67
+ parser.add_argument('engine')
68
+ parser.add_argument('model', help='a GGUF file (llama-server, ollama) or a model directory (every other engine)')
69
+ parser.add_argument('--port', type=int, help='default: a free loopback port')
70
+ parser.add_argument('--ctx', type=int, default=8192)
71
+ parser.add_argument('--device', choices=('auto', 'cpu'), default='auto', help='auto: on the card; cpu: host memory only')
72
+ parser.add_argument('--bnb4', action='store_true', help='load 4-bit on the card (child engines that can)')
73
+ parser.add_argument('--offload', choices=('model', 'sequential', 'disk-mmap'),
74
+ help='pipeline offload, or Transformers disk mmap with --max-memory CPU bytes')
75
+ parser.add_argument('--max-memory', type=json.loads, help='JSON, e.g. {"0": "8000MiB", "cpu": "16000MiB"}')
76
+ parser.add_argument('--gpu-fraction', type=float, default=0.90, help='vLLM / SGLang: the share of the card')
77
+ parser.add_argument('--projector', help='llama-server: the mmproj file of a vision GGUF')
78
+
79
+
80
+ def _start(args):
81
+ extra = args.extra
82
+ return launch.start(args.engine, os.path.abspath(args.model), port=args.port, say=lambda text: print(text, flush=True),
83
+ ctx=args.ctx, device=args.device, bnb4=args.bnb4, offload=args.offload,
84
+ max_memory=args.max_memory, gpu_fraction=args.gpu_fraction, projector=args.projector, extra=extra)
85
+
86
+
87
+ def run(argv=None):
88
+ parser = argparse.ArgumentParser(prog='hugpy-engine', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
89
+ sub = parser.add_subparsers(dest='command', required=True)
90
+ sub.add_parser('tui', help='the screen: settings, engines and environments, changed in place')
91
+ sub.add_parser('engines', help='every engine and whether it can start here')
92
+ for name, text in (('requirements', "each engine's venv and path, and everything it needs installed: there or not"),
93
+ ('inputs', 'for every task of each engine: what a call must carry and may'),
94
+ ('use', 'for every task of each engine: how it is started on a model and the simplest call it answers')):
95
+ listed = sub.add_parser(name, help=text)
96
+ listed.add_argument('names', nargs='*', metavar='ENGINE', help='the engines to show (none: every engine)')
97
+ listed.add_argument('--json', action='store_true')
98
+ sub.add_parser('drivers', help="the card driver's files here, and what each engine reaches a card through"
99
+ ).add_argument('--json', action='store_true')
100
+ report_parser = sub.add_parser('report', help='settings, environments and engines')
101
+ report_parser.add_argument('--json', action='store_true')
102
+ report_parser.add_argument('--sizes', action='store_true', help="each built environment's bytes on its drive")
103
+ install_parser = sub.add_parser('install', help='fetch what the engines need')
104
+ install_parser.add_argument('names', nargs='+', metavar='ENGINE', help='engine names, or all')
105
+ install_parser.add_argument('--plan', action='store_true', help='say what each engine needs and what is there; change nothing')
106
+ install_parser.add_argument('--account', help='as root: the account that then owns what was fetched')
107
+ env_parser = sub.add_parser('environments', help='the engine environments; build NAME... or build all')
108
+ env_parser.add_argument('action', nargs='?', choices=('build',))
109
+ env_parser.add_argument('names', nargs='*')
110
+ sub.add_parser('settings', help='every setting, its value and where it comes from')
111
+ sub.add_parser('sync', help="write the engines' state into the database and refresh the export")
112
+ observe_parser = sub.add_parser('observe', help='run an engine once on a model and keep every file it looked for')
113
+ observe_parser.add_argument('engine')
114
+ observe_parser.add_argument('model')
115
+ calls_parser = sub.add_parser('calls', help='the raw record: the latest starts and calls')
116
+ calls_parser.add_argument('--limit', type=int, default=20)
117
+ calls_parser.add_argument('--json', action='store_true')
118
+ sub.add_parser('record', help="keep another tool's start and call records (JSON lines on the standard input)")
119
+ sub.add_parser('request', help='answer one request of another tool (JSON in, JSON out)')
120
+ sub.add_parser('system', help='install | status | uninstall: this tool for the whole host (hugpy-engine system --help)')
121
+ set_parser = sub.add_parser('set', help='save one setting in the database')
122
+ set_parser.add_argument('key')
123
+ set_parser.add_argument('value')
124
+ reset_parser = sub.add_parser('reset', help='drop saved settings: their defaults apply again')
125
+ reset_parser.add_argument('keys', nargs='+')
126
+ migrate_parser = sub.add_parser('migrate-settings', help='once: the engine settings of an earlier settings.json into the database')
127
+ migrate_parser.add_argument('file', nargs='?')
128
+ _options(sub.add_parser('run', help='start an engine on a model and keep it running'))
129
+ ask_parser = sub.add_parser('ask', help='start an engine, send one chat message, print the answer, stop it')
130
+ _options(ask_parser)
131
+ ask_parser.add_argument('--say', required=True, help='the message to send')
132
+ ask_parser.add_argument('--max-tokens', type=int, default=64)
133
+ argv = sys.argv[1:] if argv is None else list(argv)
134
+ if argv[:1] == ['system']: # the host layer: its own options, and the host's data directory
135
+ return system_main(argv[1:])
136
+ if not argv: # no command: the screen in a terminal, the help without one
137
+ argv = ['tui'] if sys.stdin.isatty() and sys.stdout.isatty() else ['--help']
138
+ extra = []
139
+ if '--' in argv: # after --: arguments passed to the engine as they are
140
+ argv, extra = argv[:argv.index('--')], argv[argv.index('--') + 1:]
141
+ args = parser.parse_args(argv)
142
+ args.extra = extra
143
+ refusal = data_folder_refusal(settings.home()) # the host's engines, and this account not of their group
144
+ if refusal:
145
+ raise SystemExit(f'hugpy-engine: {refusal}')
146
+ share_new_files(settings.home()) # in the host's folder, what is made is the group's to write
147
+
148
+ if args.command == 'sync':
149
+ done = refresh()
150
+ print(f"{done['ready']} of {done['engines']} engines can start here; {done['environments']} environments"
151
+ + (f" ({done['error']})" if done['error'] else ''))
152
+ print(f"export -> {done['path']} (generation {done['generation']})")
153
+ return 0
154
+ if args.command == 'request':
155
+ try:
156
+ message = json.loads(sys.stdin.read() or '{}')
157
+ except ValueError as exc:
158
+ message = dict(op=None, bad=str(exc))
159
+ print(json.dumps(launch.answer(message), default=str), flush=True)
160
+ return 0
161
+ if args.command == 'record':
162
+ done = record(sys.stdin)
163
+ refresh()
164
+ print(json.dumps(done))
165
+ return 1 if done['refused'] else 0
166
+ if args.command == 'observe':
167
+ try:
168
+ seen = observe(args.engine, args.model)
169
+ except (RuntimeError, ValueError, FileNotFoundError) as exc:
170
+ raise SystemExit(f'hugpy-engine: {exc}')
171
+ refresh()
172
+ print(f"{args.engine} on {seen['model']}")
173
+ for title, names in (('opened', seen['opened']), ('looked for, not there or not opened', seen['looked_for']),
174
+ ('in the folder, never looked for', seen['not_looked_for'])):
175
+ print(f' {title}: ' + (', '.join(names) or 'nothing'))
176
+ return 0
177
+ if args.command == 'calls':
178
+ conn = connect()
179
+ try:
180
+ starts = rows_of(conn, 'SELECT * FROM starts ORDER BY started_at DESC LIMIT ?', (args.limit,))
181
+ calls = rows_of(conn, 'SELECT * FROM calls ORDER BY at DESC LIMIT ?', (args.limit,))
182
+ finally:
183
+ conn.close()
184
+ if args.json:
185
+ print(json.dumps(dict(starts=starts, calls=calls), indent=2))
186
+ return 0
187
+ print('starts:')
188
+ for r in starts:
189
+ print(f" {time.strftime('%m-%d %H:%M:%S', time.localtime(r['started_at'] or 0))} {r['source']:<14} {r['engine'] or '':<13} "
190
+ f"ready in {format(r['ready_s'], '.2f') if r['ready_s'] is not None else '?':>6} s {os.path.basename(r['model'] or '')}"
191
+ + (f" [{r['error']}]" if r['error'] else ''))
192
+ print('calls:')
193
+ for r in calls:
194
+ rate = f"{r['tokens_per_s']:.1f} tok/s" if r['tokens_per_s'] else ''
195
+ print(f" {time.strftime('%m-%d %H:%M:%S', time.localtime(r['at'] or 0))} {r['source']:<14} {r['engine'] or '':<13} "
196
+ f"{r['status'] or '':<9} {format(r['elapsed_s'], '.2f') if r['elapsed_s'] is not None else '?':>7} s in {r['tokens_in']} out {r['tokens_out']} {rate}"
197
+ + (f" [{r['error']}]" if r['error'] else ''))
198
+ return 0
199
+ if args.command == 'tui':
200
+ try:
201
+ return tui()
202
+ except ValueError as exc:
203
+ raise SystemExit(f'hugpy-engine: {exc}')
204
+ if args.command in ('requirements', 'inputs', 'use', 'drivers'):
205
+ every = [e['engine'] for e in engines()]
206
+ names = getattr(args, 'names', None) or every
207
+ unknown = [name for name in names if name not in every]
208
+ if unknown:
209
+ raise SystemExit(f"hugpy-engine: no engine named {', '.join(unknown)}: " + ', '.join(every))
210
+ if args.command == 'requirements':
211
+ held = {}
212
+ data = {name: dict(installer.where(name), requirements=installer.requirements(name, held)) for name in names}
213
+ if args.json:
214
+ print(json.dumps(data, indent=2))
215
+ return 0
216
+ lacking = 0
217
+ for name, at in data.items():
218
+ rows = at['requirements']
219
+ missing = sum(1 for r in rows if not r['installed'])
220
+ lacking += bool(missing)
221
+ print(f"{name}: {len(rows) - missing} of {len(rows)} installed")
222
+ print(f" venv {at['venv'] or '(none: a program)'}")
223
+ print(f" python {at['python'] or '(none)'}")
224
+ print(f" path {at['path'] or '(none)'}" + (f"\n runner {at['runner_path']}" if at['runner_path'] else ''))
225
+ for r in rows:
226
+ odd = '' if r['satisfied'] is not False else f" <- its list asks for {r['wanted']}"
227
+ print(f" [{'x' if r['installed'] else ' '}] {r['source']:<11} {r['kind']:<11} {r['wanted'] or r['requirement']:<44} "
228
+ f"{r['found'] or ('not installed' if not r['installed'] else '')}{odd}")
229
+ print(f"{len(data) - lacking} of {len(data)} engines have everything installed" + (f"; {lacking} do not" if lacking else ''))
230
+ return 0
231
+ if args.command == 'use':
232
+ data = {e['engine']: {task: dict(start=launch.start_template(e, task), call=launch.call_template(e, task),
233
+ files=e['task_files'][task]) for task in e['task_inputs']}
234
+ for e in engines() if e['engine'] in names}
235
+ if args.json:
236
+ print(json.dumps(data, indent=2))
237
+ return 0
238
+ for name, tasks in data.items():
239
+ same = {}
240
+ for task, said in tasks.items():
241
+ same.setdefault(json.dumps(said, sort_keys=True), []).append(task)
242
+ for said, named in same.items():
243
+ said = json.loads(said)
244
+ print(f"{name}: {', '.join(named)}")
245
+ print(f" start {' '.join(said['start']['argv'])}")
246
+ print(f" ready {said['start']['ready']['method']} {said['start']['ready']['url']} -> {said['start']['ready']['status']}")
247
+ print(f" call {said['call']['method']} {said['call']['url']} {json.dumps(said['call']['body'])}")
248
+ for f in said['files']:
249
+ print(f" opens the model's {f['role']}")
250
+ if not tasks:
251
+ print(f"{name}: answers no task")
252
+ return 0
253
+ if args.command == 'inputs':
254
+ data = {e['engine']: e['task_inputs'] for e in engines() if e['engine'] in names}
255
+ if args.json:
256
+ print(json.dumps(data, indent=2))
257
+ return 0
258
+ for name, shapes in data.items():
259
+ same = {}
260
+ for task, shape in shapes.items():
261
+ same.setdefault(json.dumps(shape, sort_keys=True), []).append(task)
262
+ for said, tasks in same.items():
263
+ print(f"{name}: {', '.join(tasks)}")
264
+ for i in json.loads(said):
265
+ print(f" {'required' if i['required'] else 'optional':<9} {i['name']:<24} {i['kind']:<9} "
266
+ f"{' | '.join(i['fields']):<44} {i['why']}")
267
+ if not shapes:
268
+ print(f"{name}: answers no task")
269
+ return 0
270
+ data = dict(host=driver_files(), engines={name: installer.card_files(name) for name in names})
271
+ if args.json:
272
+ print(json.dumps(data, indent=2))
273
+ return 0
274
+ print('the card driver on this host:')
275
+ for f in data['host']:
276
+ print(f" [{'x' if f['there'] else ' '}] {f['kind']:<8} {f['name']:<20} {f['version'] or '':<12} {f['path'] or 'not there'}")
277
+ print('what each engine reaches a card through:')
278
+ for name, files in data['engines'].items():
279
+ if not files:
280
+ print(f" {name:<14} nothing of its own here")
281
+ continue
282
+ builds = [f for f in files if f['kind'] == 'build']
283
+ others = [f for f in files if f['kind'] != 'build']
284
+ lost = [f['name'] for f in others if not f['there']]
285
+ said = builds[0]['version'] if builds else 'linked to ' + ', '.join(f"{f['name']} {f['version'] or ''}".strip() for f in others)
286
+ carried = f"; carries {len(others)} CUDA libraries" if builds and others else ''
287
+ print(f" {name:<14} {said}{carried}" + (f" NOT FOUND: {', '.join(lost)}" if lost else ''))
288
+ return 0
289
+ if args.command in ('engines', 'report'):
290
+ data = report(sizes=getattr(args, 'sizes', False))
291
+ if getattr(args, 'json', False):
292
+ print(json.dumps(data, indent=2))
293
+ return 0
294
+ if args.command == 'report':
295
+ print(f"database: {data['database']} .env: {data['env_file']}")
296
+ for row in data['settings']:
297
+ print(f" {row['key']:<20} {row['state']:<8} {row['value'] or ''} [{row['source'].split(':')[0]}]")
298
+ print('engine environments:' + (f" {data['environments_error']}" if data['environments_error'] else ''))
299
+ for env in data['environments']:
300
+ size = f" {env['bytes'] / 2 ** 30:6.2f} GiB" if env['bytes'] is not None else ''
301
+ print(f" {env['name']:<14} {'built' if env['built'] else 'not built':<10}{size} {env['why'] or ''}")
302
+ print('engines:')
303
+ for e in data['engines']:
304
+ serves = ', '.join(e['tasks']) or ('asked for by name; serves what ' + ', '.join(e['serves']) + ' does' if e['serves'] else '')
305
+ print(f" {e['engine']:<14} {'ready' if e['ready'] else 'NOT READY':<10} {e['endpoint']:<28} {serves}"
306
+ + ('' if e['ready'] else f" [{e['why']}]"))
307
+ return 0
308
+ if args.command == 'install':
309
+ try:
310
+ names = [e['engine'] for e in engines()] if args.names == ['all'] else args.names
311
+ if args.plan:
312
+ rows = {name: installer.needs(name) for name in names}
313
+ else:
314
+ rows = installer.install(args.names, account=args.account)
315
+ except ValueError as exc:
316
+ raise SystemExit(f'hugpy-engine: {exc}')
317
+ lacking = 0
318
+ for name in names:
319
+ if args.plan:
320
+ print(f'{name}:')
321
+ for row in rows[name]:
322
+ print(f" {row['state']:<8} {row['what']} {row['path']}" + ('' if row['state'] == 'there' else f" <- {row['how']}"))
323
+ lacking += any(row['state'] != 'there' for row in rows[name])
324
+ print(f"{len(names) - lacking} of {len(names)} engines have everything they need here"
325
+ + (f"; {lacking} do not" if lacking else ''))
326
+ refresh()
327
+ return 1 if lacking and not args.plan else 0
328
+ if args.command == 'settings':
329
+ print(f'database: {settings.database()} .env: {ENV_FILE}')
330
+ for key, row in settings.resolve().items():
331
+ print(f" {key:<20} {row['value'] or '(none)'} [{row['source']}]")
332
+ return 0
333
+ if args.command == 'reset':
334
+ had = settings.reset(args.keys)
335
+ print('default again: ' + (', '.join(had) or 'none of them had a saved value'))
336
+ refresh()
337
+ return 0
338
+ if args.command == 'migrate-settings':
339
+ try:
340
+ changed = installer.migrate(args.file)
341
+ except OSError as exc:
342
+ raise SystemExit(f'hugpy-engine: {exc}')
343
+ print('saved in the database: ' + (', '.join(changed) or 'nothing (every value is already the one in effect)'))
344
+ refresh()
345
+ return 0
346
+ if args.command == 'environments':
347
+ if args.action == 'build':
348
+ names = list(profiles.manifests()) if args.names in ([], ['all']) else args.names
349
+ for name, outcome in profiles.prepare(names).items():
350
+ print(f" {name}: {outcome.get('state') or outcome}")
351
+ for name, row in sorted(profiles.report().items()):
352
+ print(f" {name:<14} {'built' if row['built'] else 'not built':<10} {row['python']}")
353
+ refresh()
354
+ return 0
355
+ if args.command == 'set':
356
+ try:
357
+ changed = settings.save({args.key: args.value})
358
+ except ValueError as exc:
359
+ raise SystemExit(f'hugpy-engine: {exc}')
360
+ print(f"{args.key}: " + (f"{changed[args.key][0]!r} -> {changed[args.key][1]!r}" if changed else 'unchanged')
361
+ + f" (saved in {settings.database()})")
362
+ refresh()
363
+ return 0
364
+ asked = time.time()
365
+ try:
366
+ running = _start(args)
367
+ except (RuntimeError, ValueError, FileNotFoundError) as exc:
368
+ record([json.dumps(dict(kind='start', source='hugpy-engine', engine=args.engine, model=os.path.abspath(args.model),
369
+ started_at=asked, error=str(exc)))])
370
+ raise SystemExit(f'hugpy-engine: {exc}')
371
+ # the raw record of this start, and of each call made to it (telemetry/telemetry.py)
372
+ started = start_record(running, asked, dict(ctx=args.ctx, device=args.device, bnb4=args.bnb4, offload=args.offload,
373
+ max_memory=args.max_memory, gpu_fraction=args.gpu_fraction,
374
+ projector=args.projector, extra=args.extra))
375
+ record([json.dumps(started, default=str)])
376
+ try:
377
+ print(f"{args.engine} answers at {running.url}{running.engine['endpoint']} (pid {running.proc.pid})", flush=True)
378
+ if args.command == 'ask':
379
+ began, at = time.monotonic(), time.time()
380
+ body = dict(model=running.name or launch.served_name(running.model), max_tokens=args.max_tokens,
381
+ messages=[dict(role='user', content=args.say)])
382
+ try:
383
+ reply = launch.call(running.port, running.engine['endpoint'], body, timeout=600, model=running.name)
384
+ except launch.EngineError as exc:
385
+ record([json.dumps(call_record(started['start_id'], running, running.engine['endpoint'], body, at, error=str(exc)),
386
+ default=str)])
387
+ raise SystemExit(f'hugpy-engine: {exc}')
388
+ record([json.dumps(call_record(started['start_id'], running, running.engine['endpoint'], body, at, reply), default=str)])
389
+ choice = (reply.get('choices') or [{}])[0]
390
+ print('answer: ' + str((choice.get('message') or {}).get('content') or reply).strip())
391
+ print(f"({time.monotonic() - began:.1f} s; usage {reply.get('usage')})")
392
+ return 0
393
+ print('Ctrl+C stops it.', flush=True)
394
+ while running.alive():
395
+ time.sleep(0.5)
396
+ raise SystemExit(f'hugpy-engine: {args.engine} ended on its own (exit {running.proc.returncode}); see {running.log}')
397
+ except KeyboardInterrupt:
398
+ return 0
399
+ finally:
400
+ took = launch.stop(running)
401
+ record([json.dumps(dict(kind='start', start_id=started['start_id'], source='hugpy-engine', stopped_at=time.time(),
402
+ stop_s=round(took, 3), exit_code=running.proc.returncode))])
403
+ print(f'stopped {args.engine} in {took:.1f} s', flush=True)
404
+
405
+
406
+ def main(argv=None):
407
+ try:
408
+ return run(argv)
409
+ except RuntimeError as exc: # a setting that cannot be read or has no value: said, not a traceback
410
+ raise SystemExit(f'hugpy-engine: {exc}')
411
+
412
+
413
+ if __name__ == '__main__':
414
+ sys.exit(main())
@@ -0,0 +1,10 @@
1
+ """The one import surface of hugpy-engine: every feature imports from here.
2
+
3
+ Standard-library imports (init_imports), external imports (module_imports: the function library, hugpy_resources)
4
+ and constants, re-exported as they are. hugpy-engine keeps no general functions of its own."""
5
+ from .init_imports import * # noqa: F401,F403
6
+ from .module_imports import * # noqa: F401,F403
7
+ from .constants import * # noqa: F401,F403
8
+ from . import constants as _constants, init_imports as _init_imports, module_imports as _module_imports
9
+
10
+ __all__ = sorted({*_init_imports.__all__, *_module_imports.__all__, *_constants.__all__})