gh-inference 0.5.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.
Potentially problematic release.
This version of gh-inference might be problematic. Click here for more details.
- gh_inference-0.5.0/LICENSE +21 -0
- gh_inference-0.5.0/PKG-INFO +556 -0
- gh_inference-0.5.0/README.md +535 -0
- gh_inference-0.5.0/gh_ai_runner/__init__.py +65 -0
- gh_inference-0.5.0/gh_ai_runner/agent.py +152 -0
- gh_inference-0.5.0/gh_ai_runner/agent_types.py +35 -0
- gh_inference-0.5.0/gh_ai_runner/artifact.py +117 -0
- gh_inference-0.5.0/gh_ai_runner/batch.py +54 -0
- gh_inference-0.5.0/gh_ai_runner/client.py +496 -0
- gh_inference-0.5.0/gh_ai_runner/core.py +82 -0
- gh_inference-0.5.0/gh_ai_runner/hub.py +134 -0
- gh_inference-0.5.0/gh_ai_runner/integrity.py +40 -0
- gh_inference-0.5.0/gh_ai_runner/job.py +192 -0
- gh_inference-0.5.0/gh_ai_runner/limits.py +86 -0
- gh_inference-0.5.0/gh_ai_runner/logger.py +17 -0
- gh_inference-0.5.0/gh_ai_runner/metadata.py +123 -0
- gh_inference-0.5.0/gh_ai_runner/models.py +185 -0
- gh_inference-0.5.0/gh_ai_runner/polling.py +59 -0
- gh_inference-0.5.0/gh_ai_runner/repo.py +145 -0
- gh_inference-0.5.0/gh_ai_runner/runner.py +364 -0
- gh_inference-0.5.0/gh_ai_runner/types.py +178 -0
- gh_inference-0.5.0/gh_ai_runner/validation.py +57 -0
- gh_inference-0.5.0/gh_ai_runner/worker_agent.py +126 -0
- gh_inference-0.5.0/gh_inference/__init__.py +3 -0
- gh_inference-0.5.0/gh_inference/__main__.py +44 -0
- gh_inference-0.5.0/gh_inference.egg-info/PKG-INFO +556 -0
- gh_inference-0.5.0/gh_inference.egg-info/SOURCES.txt +39 -0
- gh_inference-0.5.0/gh_inference.egg-info/dependency_links.txt +1 -0
- gh_inference-0.5.0/gh_inference.egg-info/entry_points.txt +2 -0
- gh_inference-0.5.0/gh_inference.egg-info/requires.txt +5 -0
- gh_inference-0.5.0/gh_inference.egg-info/top_level.txt +2 -0
- gh_inference-0.5.0/pyproject.toml +42 -0
- gh_inference-0.5.0/setup.cfg +4 -0
- gh_inference-0.5.0/tests/test_context_limits.py +160 -0
- gh_inference-0.5.0/tests/test_editable_limits.py +146 -0
- gh_inference-0.5.0/tests/test_hub.py +105 -0
- gh_inference-0.5.0/tests/test_large_models.py +139 -0
- gh_inference-0.5.0/tests/test_reliability.py +264 -0
- gh_inference-0.5.0/tests/test_remote_agents.py +172 -0
- gh_inference-0.5.0/tests/test_v02.py +245 -0
- gh_inference-0.5.0/tests/test_v03.py +204 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tanish Chauhan
|
|
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,556 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gh-inference
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Tiny agents and quantized AI inference running entirely on GitHub Actions
|
|
5
|
+
Author: Tanish Chauhan
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/TanishC4444/GH-INFERENCE
|
|
8
|
+
Project-URL: Repository, https://github.com/TanishC4444/GH-INFERENCE
|
|
9
|
+
Keywords: ai,llm,inference,github-actions,llama,serverless
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: requests>=2.28
|
|
17
|
+
Requires-Dist: PyNaCl>=1.5
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# GH-INFERENCE
|
|
23
|
+
|
|
24
|
+
**Text in, text out. Quantized models run on GitHub servers.**
|
|
25
|
+
|
|
26
|
+
Your Python client only connects, submits prompts, and retrieves answers. Model
|
|
27
|
+
downloads, model loading, inference, and optional prompt refinement all happen
|
|
28
|
+
inside GitHub Actions. No model runtime or GPU is required on your machine.
|
|
29
|
+
|
|
30
|
+
## Start
|
|
31
|
+
|
|
32
|
+
Install the client in your environment (Python 3.9+):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install gh-inference
|
|
36
|
+
export GH_AI_TOKEN="your-github-token"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Use a classic GitHub token with `repo` and `workflow` scopes. Do not commit it.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from gh_inference import Agent
|
|
43
|
+
|
|
44
|
+
agent = Agent()
|
|
45
|
+
print(agent.run("Explain recursion briefly."))
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
That is the whole flow. The first call automatically creates or reuses the
|
|
49
|
+
`ai-inference-runner` repository, installs the workflow, starts a GitHub worker,
|
|
50
|
+
and returns its answer as a plain string. `agent("prompt")` is equivalent.
|
|
51
|
+
You can also pass `Agent(github_token=...)` instead of setting the environment.
|
|
52
|
+
|
|
53
|
+
`agent.connect()` optionally prepares the repository ahead of the first prompt;
|
|
54
|
+
it is never required. Connecting does not start or reserve a model worker.
|
|
55
|
+
|
|
56
|
+
## Models and every published GGUF variant
|
|
57
|
+
|
|
58
|
+
The 16 pinned aliases below remain convenient defaults. Model support is open:
|
|
59
|
+
use any public, ungated Hugging Face **GGUF** repository supported by the installed
|
|
60
|
+
llama.cpp runtime. Search discovers Qwen, Llama, Gemma, Phi, Mistral, DeepSeek,
|
|
61
|
+
SmolLM and other families, with no project parameter-count ceiling. A model being
|
|
62
|
+
discoverable does not mean it fits your runner or its architecture is supported.
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from gh_inference import Agent, search_models, list_quantizations
|
|
66
|
+
|
|
67
|
+
print(search_models("Qwen3"))
|
|
68
|
+
print(list_quantizations("Qwen/Qwen2.5-0.5B-Instruct-GGUF"))
|
|
69
|
+
agent = Agent(model="Qwen/Qwen2.5-0.5B-Instruct-GGUF", quantization="Q8_0")
|
|
70
|
+
print(agent("Explain quantization in one sentence."))
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`quantization` defaults to `Q4_K_M` for repository selections. All published GGUF
|
|
74
|
+
labels can be selected, including Q2/Q3/Q4/Q5/Q6/Q8, K-quants, IQ, TQ and floating
|
|
75
|
+
point variants when provided and supported by your backend. We do not manufacture
|
|
76
|
+
missing variants or convert weights. AWQ/GPTQ/Safetensors require other backends
|
|
77
|
+
and are not accepted by this GGUF CPU runner. Model licenses still apply.
|
|
78
|
+
|
|
79
|
+
For ambiguous repositories use `Agent(model="owner/repo", filename="exact.gguf")`.
|
|
80
|
+
Split GGUF files are grouped, all shards are checked and downloaded, and the first
|
|
81
|
+
shard is loaded. Incomplete shard groups are excluded. `list_quantizations` lists
|
|
82
|
+
exact filenames and aggregate bytes; projector files are excluded (text only).
|
|
83
|
+
|
|
84
|
+
Selections resolve metadata once per client process and pin a Hub commit plus
|
|
85
|
+
each file's SHA-256 and size. Workers verify downloads before loading. Subsequent
|
|
86
|
+
jobs reuse the Actions weights cache when eligible; `run_many()` keeps one model
|
|
87
|
+
resident in RAM throughout that job. An Actions job ending releases its RAM.
|
|
88
|
+
Use `revision="commit-or-tag"` for reproducibility; `clear_model_cache()` refreshes
|
|
89
|
+
cached branch metadata. Hub metadata calls download no model weights locally.
|
|
90
|
+
|
|
91
|
+
Context defaults to about 8K (or a known smaller ceiling). Existing aliases retain
|
|
92
|
+
their documented limits; arbitrary repositories use Hub GGUF `context_length`
|
|
93
|
+
when supplied. If absent, the advertised ceiling is unknown, not invented.
|
|
94
|
+
RAM estimates for arbitrary models are approximate; architecture and KV cache
|
|
95
|
+
shape affect actual usage. `Limits` and `Agent.experimental()` below remain
|
|
96
|
+
available, but cannot create RAM, extend GitHub quotas, or add backend support.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
gh-inference models Qwen3
|
|
100
|
+
gh-inference variants Qwen/Qwen2.5-0.5B-Instruct-GGUF
|
|
101
|
+
gh-inference run "What is recursion?" --model qwen0.5b --track-time
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
For source development, `pip install -e '.[dev]'` installs this checkout. The
|
|
105
|
+
legacy `gh_ai_runner` import remains supported; new code can use `gh_inference`.
|
|
106
|
+
|
|
107
|
+
## Publishing
|
|
108
|
+
|
|
109
|
+
The `publish.yml` workflow builds and tests the wheel before publishing to PyPI
|
|
110
|
+
using GitHub OIDC, with no stored PyPI token. Configure the PyPI trusted publisher
|
|
111
|
+
for owner `TanishC4444`, repository `GH-INFERENCE`, workflow `publish.yml`, and
|
|
112
|
+
environment `pypi`, then run it with `publish=true` or publish a `v*` release.
|
|
113
|
+
You can also publish by updating `.github/release.json` on `main` to the package
|
|
114
|
+
version; the workflow checks that they match before building and uploading.
|
|
115
|
+
Each version is immutable on PyPI; bump `gh_ai_runner.__version__` for a release.
|
|
116
|
+
|
|
117
|
+
New repositories are **private by default**. Existing visibility is never changed.
|
|
118
|
+
Actions must be enabled. Private Actions usage consumes included minutes and can
|
|
119
|
+
incur charges. Use a dedicated repository: the package manages and can overwrite
|
|
120
|
+
`run_inference.py` and `.github/workflows/inference.yml` there.
|
|
121
|
+
|
|
122
|
+
## Experiments: remove project ceilings
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from gh_ai_runner import Agent
|
|
126
|
+
|
|
127
|
+
agent = Agent.experimental(
|
|
128
|
+
model="qwen0.5b",
|
|
129
|
+
n_ctx=65536, # Deliberately above this model's advertised 32K.
|
|
130
|
+
max_tokens=None, # Ask the runtime to use remaining context for the answer.
|
|
131
|
+
track_time=True,
|
|
132
|
+
)
|
|
133
|
+
print(agent.run("Explain context windows."))
|
|
134
|
+
print(agent.last_result.usage)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`Agent.experimental()` uses `Limits.unrestricted()`, `trim_history=False`, and
|
|
138
|
+
`max_history_turns=None`. It removes our advertised model/output checks, estimated
|
|
139
|
+
RAM/disk rejection, temperature bounds, prompt-character cap, batch-count cap,
|
|
140
|
+
formatting reserves, cache-size threshold, and project workflow-input budget.
|
|
141
|
+
Default context remains 8K (2K for TinyLlama) unless you set `n_ctx`; default answer
|
|
142
|
+
length remains 512 unless you change `max_tokens`. All computation stays on GitHub.
|
|
143
|
+
|
|
144
|
+
This permits an attempt; it does not guarantee that the backend can execute it.
|
|
145
|
+
A bigger `n_ctx` allocates a bigger window. Sending more messages alone does not.
|
|
146
|
+
Going beyond a model's trained/advertised length may require positional scaling
|
|
147
|
+
and can produce poor answers. Disabling memory checks cannot create memory.
|
|
148
|
+
|
|
149
|
+
### Edit individual rules
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from gh_ai_runner import Agent, Limits
|
|
153
|
+
|
|
154
|
+
limits = Limits.unrestricted(
|
|
155
|
+
check_resources=True,
|
|
156
|
+
max_prompts=100,
|
|
157
|
+
max_cached_model_gb=6,
|
|
158
|
+
job_timeout_minutes=90,
|
|
159
|
+
)
|
|
160
|
+
agent = Agent.experimental(limits=limits, n_ctx=16384, max_tokens=2048)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`Limits()` preserves standard checks. `Limits.unrestricted(**overrides)` disables
|
|
164
|
+
project ceilings and applies your overrides. Both accept every field below. Pass
|
|
165
|
+
the configuration to `Agent`, `GitHubAIRunner`, `ai_call`, or an individual
|
|
166
|
+
`InferenceRequest`/`submit()`; request settings override runner defaults.
|
|
167
|
+
Configurations are immutable: make a new one or use `dataclasses.replace()`.
|
|
168
|
+
|
|
169
|
+
| `Limits` field | Standard default | Meaning / override |
|
|
170
|
+
| --- | --- | --- |
|
|
171
|
+
| `enforce_model_limits` | `True` | Advertised context and recorded output ceilings; `False` permits attempts beyond them. |
|
|
172
|
+
| `enforce_output_budget` | `True` | Reject an explicit answer limit at least as large as `n_ctx` and reserve the answer during trimming; `False` delegates answer-space handling to the runtime. |
|
|
173
|
+
| `check_resources` | `True` | Estimated RAM/disk checks on client and worker; `False` lets allocation/downloads proceed to real limits. |
|
|
174
|
+
| `max_prompt_chars` | `60000` | Current prompt plus instructions; `None` removes the project check. |
|
|
175
|
+
| `max_workflow_input_chars` | `65000` | Serialized workflow-input budget; `None` removes this budget. GitHub's service limit remains. |
|
|
176
|
+
| `max_prompts` | `32` | Prompts per `run_many()`; `None` removes the count cap. |
|
|
177
|
+
| `min_temperature`, `max_temperature` | `0.0`, `2.0` | Either bound can be `None`; values must still be finite. |
|
|
178
|
+
| `context_reserve_tokens` | `128` | Conservative extra allowance; can be `0`. |
|
|
179
|
+
| `message_overhead_tokens` | `32` | Formatting allowance per message; can be `0`. Actual formatting still uses tokens. |
|
|
180
|
+
| `max_cached_model_gb` | `6.0` | Cache files below this decimal-GB threshold; `None` permits all sizes, `0` skips caching. |
|
|
181
|
+
| `runtime_overhead_gb` | `1.5` | Estimated RAM above weights/context. |
|
|
182
|
+
| `disk_reserve_gb` | `2.0` | Additional estimated free disk. |
|
|
183
|
+
| `ram_per_1k_ctx_gb` | `None` | Use catalog's estimate; a number overrides it. Changing estimates does not change real allocation. |
|
|
184
|
+
| `job_timeout_minutes` | `30` | Remote timeout; unrestricted preset uses `360`. Hosted GitHub jobs have a six-hour service maximum. |
|
|
185
|
+
| `artifact_retention_days` | `3` | Requested result retention, subject to repository policy. |
|
|
186
|
+
| `download_timeout_seconds` | `30` | Model-download socket timeout. |
|
|
187
|
+
| `provider_timeout_seconds` | `300` | Legacy hosted-provider request timeout. |
|
|
188
|
+
| `refiner_min_tokens` | `128` | Minimum prompt size considered for refinement. |
|
|
189
|
+
| `refiner_max_tokens` | `512` | Rewrite ceiling, also bounded by original length and available context. |
|
|
190
|
+
| `refiner_context_fraction` | `0.25` | Context fraction used to plan the rewrite allowance. |
|
|
191
|
+
|
|
192
|
+
The unrestricted preset sets the three enforcement flags to `False`; optional
|
|
193
|
+
prompt, workflow-budget, batch, temperature, and cache-size limits to `None`;
|
|
194
|
+
formatting reserves to `0`; and remote timeout to `360`. Other defaults remain.
|
|
195
|
+
The experimental agent factory additionally disables trimming and turn-count caps.
|
|
196
|
+
Explicit arguments to the factory override those choices.
|
|
197
|
+
|
|
198
|
+
### Model loading and sampling
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
agent = Agent.experimental(
|
|
202
|
+
n_ctx=65536,
|
|
203
|
+
max_tokens=4096,
|
|
204
|
+
model_options={
|
|
205
|
+
"n_threads": 2,
|
|
206
|
+
"n_batch": 256,
|
|
207
|
+
"rope_scaling_type": "yarn",
|
|
208
|
+
"rope_freq_scale": 0.5,
|
|
209
|
+
"yarn_orig_ctx": 32768,
|
|
210
|
+
"yarn_ext_factor": 1.0,
|
|
211
|
+
},
|
|
212
|
+
generation_options={"top_k": 40, "top_p": 0.9, "repeat_penalty": 1.1, "seed": 42},
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`model_options` forwards JSON-compatible keywords to
|
|
217
|
+
[`llama_cpp.Llama`](https://llama-cpp-python.readthedocs.io/en/latest/api-reference/),
|
|
218
|
+
including CPU threads, batch sizes, KV settings, and positional scaling.
|
|
219
|
+
`rope_scaling_type` accepts a backend integer enum or a name such as `"yarn"` or
|
|
220
|
+
`"linear"`. These are experimental settings, not verified 64K quality claims.
|
|
221
|
+
Increasing context does not retrain the weights. Qwen 7B/14B still apply their
|
|
222
|
+
published factor-4 YaRN recipe above 32K unless you override it. Beyond advertised
|
|
223
|
+
lengths, choose and evaluate scaling yourself. Other entries keep GGUF metadata.
|
|
224
|
+
|
|
225
|
+
`generation_options` forwards sampling keywords to `create_chat_completion`,
|
|
226
|
+
including `top_k`, `top_p`, `min_p`, penalties, `seed`, and `stop`. It applies to
|
|
227
|
+
main answers; refinement uses separate deterministic sampling. Unknown keywords
|
|
228
|
+
are rejected by the installed backend. Use named `n_ctx`, `max_tokens`, and
|
|
229
|
+
`temperature` arguments for those values. Extra-option dictionaries cannot replace
|
|
230
|
+
the managed model path, CPU/RAM placement, messages, or nonstreaming text contract.
|
|
231
|
+
|
|
232
|
+
`max_tokens=None` requests remaining context. Standard model-limit enforcement
|
|
233
|
+
still applies a recorded publisher output ceiling; unrestricted mode does not.
|
|
234
|
+
The runtime can shorten an explicit answer allowance to remaining space and stop
|
|
235
|
+
early at EOS. Input exceeding allocated `n_ctx` is rejected by llama-cpp-python.
|
|
236
|
+
Custom policies/options are sent to the worker and covered by request checksums.
|
|
237
|
+
|
|
238
|
+
### Connection and waiting
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
from gh_ai_runner import Agent, GitHubAIRunner, Limits
|
|
242
|
+
|
|
243
|
+
runner = GitHubAIRunner(
|
|
244
|
+
limits=Limits.unrestricted(job_timeout_minutes=90),
|
|
245
|
+
completion_timeout=5500,
|
|
246
|
+
run_discovery_timeout=300,
|
|
247
|
+
poll_interval=10,
|
|
248
|
+
http_timeout=60,
|
|
249
|
+
artifact_timeout=120,
|
|
250
|
+
workflow_registration_timeout=120,
|
|
251
|
+
)
|
|
252
|
+
agent = Agent.experimental(runner=runner, limits=runner.limits)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Runner defaults, all in seconds: `completion_timeout=1800`,
|
|
256
|
+
`run_discovery_timeout=180`, `poll_interval=8`, `http_timeout=30`,
|
|
257
|
+
`artifact_timeout=60`, `workflow_registration_timeout=60`. Values must be finite
|
|
258
|
+
and positive; there is no project upper bound. HTTP timeout applies per API
|
|
259
|
+
request. Discovery/completion/artifact deadlines apply to their own phases.
|
|
260
|
+
`agent.run(prompt, timeout=...)` bounds waiting/result retrieval after dispatch,
|
|
261
|
+
not repository preparation or model execution. A client timeout does not cancel
|
|
262
|
+
the remote job. Increase client waiting alongside longer remote job timeouts.
|
|
263
|
+
|
|
264
|
+
### External limits remain
|
|
265
|
+
|
|
266
|
+
- [GitHub workflow inputs](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#onworkflow_dispatchinputs)
|
|
267
|
+
have a 65,535-character service limit including history, configuration, escaping,
|
|
268
|
+
and JSON overhead. Characters are not tokens. This version has no alternate
|
|
269
|
+
large-prompt transport, even when model context is 128K or larger.
|
|
270
|
+
- [GitHub Actions limits](https://docs.github.com/en/actions/reference/limits)
|
|
271
|
+
include the six-hour hosted-job maximum, account minutes, concurrency, storage,
|
|
272
|
+
and API limits. A larger configured timeout cannot extend the service maximum.
|
|
273
|
+
- Real RAM/disk, CPU time, backend numeric ranges, supported architectures and
|
|
274
|
+
scaling, and model quality remain constraints. Allocation, disk-full, timeout,
|
|
275
|
+
and worker-termination failures are possible when resource checks are disabled.
|
|
276
|
+
|
|
277
|
+
The curated 16B catalog is not a mathematical parameter-count cap; larger entries
|
|
278
|
+
need verified GGUF download metadata and appropriate workers. Valid input types,
|
|
279
|
+
checksums, and job identity checks remain required in both presets.
|
|
280
|
+
|
|
281
|
+
## Choose a model or role
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
agent = Agent(model="qwen", instructions="You are a concise coding assistant.")
|
|
285
|
+
answer = agent.run("Write a function that merges overlapping intervals.")
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
The default `qwen0.5b` is a roughly 491 MB Q4_K_M starter model. Larger models can
|
|
289
|
+
provide better answers but take more download time, RAM, and CPU time.
|
|
290
|
+
|
|
291
|
+
| Model keys | Parameter sizes |
|
|
292
|
+
| --- | --- |
|
|
293
|
+
| `qwen0.5b`, `tinyllama`, `llama`, `qwen` | 0.5B, 1.1B, 1B, 1.5B |
|
|
294
|
+
| `gemma2`, `qwen3b`, `phi3`, `deepseek` | 2B, 3B, 3.8B, 1.5B |
|
|
295
|
+
| `qwen7b`, `qwen-coder7b`, `llama8b`, `gemma9b` | 7B, 7B, 8B, 9B |
|
|
296
|
+
| `mistral12b`, `qwen14b`, `qwen-coder14b`, `deepseek-coder16b` | 12B, 14B, 14B, 16B |
|
|
297
|
+
|
|
298
|
+
All catalog entries are prequantized GGUF files. Their sizes and SHA-256 hashes
|
|
299
|
+
are recorded in `models.py`; new downloads must match both before loading.
|
|
300
|
+
|
|
301
|
+
## Reuse one loaded model
|
|
302
|
+
|
|
303
|
+
```python
|
|
304
|
+
answers = agent.run_many([
|
|
305
|
+
"Explain a Python list.",
|
|
306
|
+
"Compare it with a tuple.",
|
|
307
|
+
"Give a small example using both.",
|
|
308
|
+
])
|
|
309
|
+
for answer in answers:
|
|
310
|
+
print(answer)
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
By default, up to 32 prompts run sequentially in **one GitHub job**. Change
|
|
314
|
+
`Limits.max_prompts` to raise/remove that cap. The full quantized model
|
|
315
|
+
loads into CPU RAM once and remains loaded for all those prompts and refinement
|
|
316
|
+
steps. Memory mapping and GPU offloading are disabled; memory locking is requested,
|
|
317
|
+
subject to the worker OS's permissions.
|
|
318
|
+
|
|
319
|
+
Separate `run()` calls create separate workers. Hosted GitHub workers cannot keep
|
|
320
|
+
RAM between jobs. Group prompts with `run_many()` to avoid repeated model loading.
|
|
321
|
+
GitHub caches downloaded weights and the Python environment across jobs, although
|
|
322
|
+
caches can be evicted. Model cache keys include the expected weight checksum.
|
|
323
|
+
Setup prefers official prebuilt CPU packages so a new worker normally avoids
|
|
324
|
+
compiling the inference runtime; source compilation is a fallback.
|
|
325
|
+
|
|
326
|
+
By default, files at least 6 GB skip weight caching because uploading their archive can need
|
|
327
|
+
another model-sized copy on the worker's limited disk. They still load once per
|
|
328
|
+
`run_many()` job, but a new job downloads them again.
|
|
329
|
+
Set `max_cached_model_gb=None` to permit all sizes, or `cache=False` on `Agent`
|
|
330
|
+
to skip weight caching. Unrestricted mode permits all sizes; cache archives can
|
|
331
|
+
still fail if the worker's disk or GitHub cache storage is too small.
|
|
332
|
+
|
|
333
|
+
## Timing
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
agent = Agent(track_time=True)
|
|
337
|
+
print(agent.run("What is a B-tree?"))
|
|
338
|
+
print(agent.last_result.timings)
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
The return value stays plain text. Optional details are in `agent.last_result`
|
|
342
|
+
and `agent.last_results`: token usage, download/load/generation timing, weight-cache
|
|
343
|
+
hits, and within-job model reuse. `agent.last_job` exposes the Actions URL and
|
|
344
|
+
low-level status/cancellation handle.
|
|
345
|
+
|
|
346
|
+
`total_seconds` measures worker time for that prompt, including shared setup on
|
|
347
|
+
the first prompt. `remote_seconds` measures the full client operation, including
|
|
348
|
+
repository preparation, queuing, waiting, and result retrieval. For `run_many()`,
|
|
349
|
+
the whole-job remote duration appears on every result; do not sum it.
|
|
350
|
+
Override tracking per call with `agent.run(prompt, track_time=True)`.
|
|
351
|
+
|
|
352
|
+
## Optional prompt refinement
|
|
353
|
+
|
|
354
|
+
```python
|
|
355
|
+
agent = Agent(refine_prompt=True, track_time=True)
|
|
356
|
+
print(agent.run("Your detailed task and constraints ..."))
|
|
357
|
+
print(agent.last_result.refinement.tokens_saved)
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Refinement runs on the **same loaded model on GitHub**, not a separate service or
|
|
361
|
+
second model. Short prompts are skipped. A rewrite is accepted only when it uses
|
|
362
|
+
fewer main-model tokens, finishes normally, and preserves protected numbers, URLs,
|
|
363
|
+
double-quoted literals, and code. Otherwise the original prompt is retained.
|
|
364
|
+
|
|
365
|
+
It can reduce the main generation's input processing, but adds its own tokens
|
|
366
|
+
and time. Total usage includes that work; `last_result.refinement.usage` reports
|
|
367
|
+
it separately. Shorter input does not shrink model weights or automatically reduce
|
|
368
|
+
the allocated context cache. Literal checks do not guarantee unchanged meaning.
|
|
369
|
+
|
|
370
|
+
## Conversation and limits
|
|
371
|
+
|
|
372
|
+
Conversation is remembered on the agent object and passed to subsequent GitHub
|
|
373
|
+
jobs. `run_many()` manages it within the same worker. No prompt/output history is
|
|
374
|
+
automatically written to disk by `Agent`. Use `remember=False` for independent
|
|
375
|
+
prompts and `agent.reset()` to forget previous turns.
|
|
376
|
+
|
|
377
|
+
Older conversation turns are dropped as needed to leave room for the new prompt
|
|
378
|
+
and answer. Current prompt text is never silently truncated. The main options are:
|
|
379
|
+
|
|
380
|
+
| Option | Default | Limit |
|
|
381
|
+
| --- | --- | --- |
|
|
382
|
+
| `max_tokens` | 512 | Positive integer or `None`; standard policy checks output/context ceilings |
|
|
383
|
+
| `n_ctx` | 8,192; TinyLlama: 2,048 | Positive integer; advertised ceiling and resource checks are editable policies |
|
|
384
|
+
| `temperature` | 0.7 | Finite number; standard bounds are 0 to 2 |
|
|
385
|
+
| `max_history_turns` | 6 | Any positive integer, or `None` for no exchange-count cap |
|
|
386
|
+
| `trim_history` | `True` | Set `False` to retain all exchanges and pass overflow to the model runtime |
|
|
387
|
+
|
|
388
|
+
Context includes instructions, history, formatting, and the answer. Worker
|
|
389
|
+
tokenization supplies actual usage; context planning includes a conservative
|
|
390
|
+
formatting allowance. The model can stop before reaching `max_tokens`.
|
|
391
|
+
|
|
392
|
+
### Context ceilings
|
|
393
|
+
|
|
394
|
+
The old blanket 8,192-context and 4,096-output caps are removed. Standard starting windows are
|
|
395
|
+
8,192 total tokens, except TinyLlama, whose supported maximum is only 2,048.
|
|
396
|
+
These advertised ceilings are enforced by standard policy and bypassable with
|
|
397
|
+
`enforce_model_limits=False`. They describe support, not a promise that a worker has enough
|
|
398
|
+
RAM or CPU time to use them. The catalog includes each limit's publisher source
|
|
399
|
+
in `MODELS[key]["context_source"]`.
|
|
400
|
+
|
|
401
|
+
| Model keys | Maximum total context | Separate published output ceiling |
|
|
402
|
+
| --- | ---: | ---: |
|
|
403
|
+
| `tinyllama` | 2,048 | — |
|
|
404
|
+
| `gemma2`, `gemma9b` | 8,192 | — |
|
|
405
|
+
| `qwen0.5b`, `qwen`, `qwen3b` | 32,768 | 8,192 |
|
|
406
|
+
| `qwen7b`, `qwen14b` | 131,072 | 8,192 |
|
|
407
|
+
| `qwen-coder7b`, `qwen-coder14b` | 131,072 | — |
|
|
408
|
+
| `llama`, `llama8b`, `phi3`, `deepseek` | 131,072 | — |
|
|
409
|
+
| `mistral12b`, `deepseek-coder16b` | 131,072 (128K) | — |
|
|
410
|
+
|
|
411
|
+
`—` means no separate output ceiling is recorded; the available total context
|
|
412
|
+
still bounds generation. It does not mean unlimited or tested long-form output.
|
|
413
|
+
Sources include the [Qwen 0.5B model card](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct),
|
|
414
|
+
[Qwen 7B long-context recipe](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct#processing-long-texts),
|
|
415
|
+
[Gemma 2 model card](https://ai.google.dev/gemma/docs/core/model_card_2), and the
|
|
416
|
+
individual publisher links in the catalog.
|
|
417
|
+
|
|
418
|
+
```python
|
|
419
|
+
agent = Agent(model="qwen0.5b", n_ctx=32768, max_tokens=8192)
|
|
420
|
+
print(agent.run("Explain the design in detail."))
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
The answer allowance shares the window with instructions, history, and your prompt.
|
|
424
|
+
Increasing context increases RAM usage even if the current prompt is short. The
|
|
425
|
+
worker automatically enables Qwen's factor-4 YaRN settings above 32,768 tokens for
|
|
426
|
+
the 7B/14B Qwen and Qwen Coder entries. Other models retain the scaling encoded in
|
|
427
|
+
their GGUF files. Long-context quality and peak RAM are not verified at every ceiling.
|
|
428
|
+
|
|
429
|
+
### When a conversation grows past its window
|
|
430
|
+
|
|
431
|
+
A 32K model can participate in a conversation totaling 64K tokens across many
|
|
432
|
+
calls. It can only receive one window's worth on any given call. This agent keeps
|
|
433
|
+
the instructions and current prompt, reserves the requested answer allowance,
|
|
434
|
+
and removes the oldest complete user/assistant pairs until the request fits.
|
|
435
|
+
It does not automatically summarize or retrieve the removed messages. Details
|
|
436
|
+
that appeared only in those messages are no longer available to the model.
|
|
437
|
+
|
|
438
|
+
The default history cap is also six previous exchanges, even when context has
|
|
439
|
+
space. Increase `max_history_turns` or set it to `None` to retain more exchanges; the token
|
|
440
|
+
budget and workflow transport can still trim them earlier. `n_ctx=32768` must be
|
|
441
|
+
set explicitly to use a 32K window instead of the 8K default.
|
|
442
|
+
|
|
443
|
+
```python
|
|
444
|
+
agent = Agent(model="qwen0.5b", n_ctx=32768, max_history_turns=32)
|
|
445
|
+
print(agent.run("Continue our discussion."))
|
|
446
|
+
print(agent.last_result.dropped_history_turns) # history removed to fit context/transport
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
With the default trimming policy, one oversized current prompt is rejected, rather than cut silently. A 64K-token
|
|
450
|
+
prompt cannot fit an allocated 32K window. Standard policy rejects allocations
|
|
451
|
+
above the advertised maximum; experimental mode allows those attempts to reach
|
|
452
|
+
the runtime.
|
|
453
|
+
|
|
454
|
+
### Experiment without automatic history removal
|
|
455
|
+
|
|
456
|
+
```python
|
|
457
|
+
agent = Agent(
|
|
458
|
+
model="qwen0.5b",
|
|
459
|
+
n_ctx=8192, # Try 16384 or 32768 in a separate experiment.
|
|
460
|
+
trim_history=False,
|
|
461
|
+
track_time=True,
|
|
462
|
+
)
|
|
463
|
+
print(agent.run("Remember this fact: my project is called Cedar."))
|
|
464
|
+
print(agent.run("What is my project called?"))
|
|
465
|
+
print(agent.last_result.usage)
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
`trim_history=False` disables all automatic history removal: the exchange-count
|
|
469
|
+
cap, token-budget trimming on GitHub, and client-side transport trimming.
|
|
470
|
+
`max_history_turns` is ignored in this mode. Completed exchanges stay on the agent
|
|
471
|
+
until you call `reset()` or discard the object; `remember=False` still disables
|
|
472
|
+
conversation memory entirely. This does not restore messages removed earlier.
|
|
473
|
+
|
|
474
|
+
The full retained history is passed to llama-cpp-python without our pre-generation
|
|
475
|
+
fit check. It does **not** enlarge `n_ctx`, bypass model ceilings or RAM checks, or
|
|
476
|
+
promise that the runtime accepts overflow. The runtime may reject an oversized
|
|
477
|
+
input or shorten generation to the remaining context. Use `Agent.experimental()`
|
|
478
|
+
or custom `Limits` to bypass the separate advertised-ceiling/resource policies.
|
|
479
|
+
Check the Actions job/logs
|
|
480
|
+
via `agent.last_job.actions_url` if a call fails. A failed call does not replace
|
|
481
|
+
the client's previously retained conversation or append its failed prompt.
|
|
482
|
+
|
|
483
|
+
GitHub's workflow-input transport limit still applies. When it is exceeded, the
|
|
484
|
+
call fails instead of dropping history, before starting a new worker. Setting a
|
|
485
|
+
32K context and sending 64K of messages therefore does not create 64K memory.
|
|
486
|
+
For controlled comparisons, start fresh agents with the same prompts, disable
|
|
487
|
+
refinement (the default), and vary `n_ctx` while keeping answer length fixed.
|
|
488
|
+
|
|
489
|
+
Standard policy limits prompt plus instructions to 60,000 characters, and the complete
|
|
490
|
+
workflow-input payload must fit GitHub's limit. Oversized jobs are rejected before
|
|
491
|
+
provisioning. These are **separate transport limits**, not token limits: a model
|
|
492
|
+
can allow 128K context while this version cannot transmit a full 128K-token prompt
|
|
493
|
+
or history through workflow inputs. With `trim_history=True`, history may be trimmed to satisfy transport
|
|
494
|
+
before it reaches the model. Workflow timeout and client completion wait default
|
|
495
|
+
to 30 minutes; both are editable as described above.
|
|
496
|
+
A client timeout does not automatically cancel a job; use `agent.last_job` when
|
|
497
|
+
you need to inspect or cancel it.
|
|
498
|
+
|
|
499
|
+
Tools, file access, Python callbacks, and shell execution are deliberately out of
|
|
500
|
+
scope. This version is text in, text out.
|
|
501
|
+
|
|
502
|
+
## Larger workers
|
|
503
|
+
|
|
504
|
+
The default client budget is 8 GB RAM and 14 GB workspace disk. GitHub lists 8 GB
|
|
505
|
+
RAM for standard private Linux workers and 16 GB for public ones. See
|
|
506
|
+
[GitHub runner specifications](https://docs.github.com/en/actions/reference/runners/github-hosted-runners).
|
|
507
|
+
|
|
508
|
+
```python
|
|
509
|
+
from gh_ai_runner import Agent, GitHubAIRunner
|
|
510
|
+
|
|
511
|
+
runner = GitHubAIRunner(
|
|
512
|
+
runner_label="your-linux-32gb-runner",
|
|
513
|
+
runner_ram_gb=32,
|
|
514
|
+
runner_disk_gb=40,
|
|
515
|
+
)
|
|
516
|
+
agent = Agent(model="deepseek-coder16b", runner=runner)
|
|
517
|
+
print(agent.run("Explain this algorithm."))
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
The runner label must already be available to your repository; changing budgets
|
|
521
|
+
does not purchase hardware. To deliberately create a public standard runner,
|
|
522
|
+
configure a new `repo_name`, `private=False`, and `runner_ram_gb=16`. Existing
|
|
523
|
+
visibility is never changed automatically.
|
|
524
|
+
|
|
525
|
+
RAM/disk estimates are checked before dispatch and available resources are checked
|
|
526
|
+
again on the worker. Large CPU models can be slow even when they fit.
|
|
527
|
+
|
|
528
|
+
Quantization shrinks weight storage, not the parameter count. Idealized 16B weights
|
|
529
|
+
take 32 GB at 16 bits or 8 GB at 4 bits; actual Q4_K_M mixes precisions and includes
|
|
530
|
+
scales/metadata. The catalog's 16B file is 10.36 GB. RAM also needs context/KV cache
|
|
531
|
+
and computation buffers. See [llama.cpp quantization](https://github.com/ggml-org/llama.cpp/blob/master/tools/quantize/README.md).
|
|
532
|
+
|
|
533
|
+
## Existing APIs
|
|
534
|
+
|
|
535
|
+
`ai_call(token, prompt, ...)` remains a blocking text-returning helper. Explicit
|
|
536
|
+
`track_time=True` returns an `InferenceResult` with `.output` and `.timings`.
|
|
537
|
+
`GitHubAIRunner()` also reads `GH_AI_TOKEN` automatically and retains submission,
|
|
538
|
+
batch/comparison, polling, cancellation, retry, resume, and hosted-provider APIs.
|
|
539
|
+
|
|
540
|
+
`submit_batch()` launches independent workflows; `Agent.run_many()` reuses one
|
|
541
|
+
worker/model. Only failed workflow conclusions are automatically retried when
|
|
542
|
+
requested by `RetryPolicy`, avoiding duplicate work after uncertain dispatches.
|
|
543
|
+
|
|
544
|
+
## Privacy and verification
|
|
545
|
+
|
|
546
|
+
Prompts, history, and answers are sent to GitHub. Results are Actions artifacts,
|
|
547
|
+
retained for three days. Public repository permissions and Actions logs matter.
|
|
548
|
+
Checksums verify job identity, requests, output, and structured agent results; they
|
|
549
|
+
are not signatures protecting against a compromised worker/repository.
|
|
550
|
+
|
|
551
|
+
Test/build CI runs on GitHub. The manual **GitHub model smoke test** workflow also
|
|
552
|
+
downloads a real small model and checks that two prompts reuse it in RAM. Client
|
|
553
|
+
orchestration tests use simulated API/model responses. No model runtime is installed
|
|
554
|
+
by this package on the client.
|
|
555
|
+
|
|
556
|
+
MIT license. See [LICENSE](LICENSE).
|