rikis 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.
- rikis-0.0.1/PKG-INFO +64 -0
- rikis-0.0.1/README.md +51 -0
- rikis-0.0.1/pyproject.toml +24 -0
- rikis-0.0.1/src/rikis/__init__.py +12 -0
- rikis-0.0.1/src/rikis/agent.py +138 -0
- rikis-0.0.1/src/rikis/commands.py +115 -0
- rikis-0.0.1/src/rikis/config.py +55 -0
- rikis-0.0.1/src/rikis/runtimes/__init__.py +20 -0
- rikis-0.0.1/src/rikis/runtimes/base.py +97 -0
- rikis-0.0.1/src/rikis/runtimes/llama_cpp.py +15 -0
- rikis-0.0.1/src/rikis/runtimes/lmstudio.py +16 -0
- rikis-0.0.1/src/rikis/runtimes/ollama.py +15 -0
rikis-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: rikis
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Lightweight agent that pulls and runs LLM benchmarks from Protorikis Bench
|
|
5
|
+
Author: protorikis
|
|
6
|
+
Author-email: protorikis <code@protorikis.com>
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Requires-Dist: httpx>=0.28.1
|
|
9
|
+
Requires-Dist: typer>=0.25.1
|
|
10
|
+
Requires-Python: >=3.13
|
|
11
|
+
Project-URL: Homepage, https://bench.protorikis.com
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# rikis
|
|
15
|
+
|
|
16
|
+
Lightweight agent that connects your local LLM runtimes to [Protorikis Bench](https://bench.protorikis.com) and runs benchmark jobs on them.
|
|
17
|
+
|
|
18
|
+
> rikis only runs inference - it never executes generated code locally
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
pipx install rikis
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
**1. Get a token** from [Protorikis Bench](https://bench.protorikis.com) → Endpoints → Add Endpoint
|
|
29
|
+
|
|
30
|
+
**2. Log in:**
|
|
31
|
+
```
|
|
32
|
+
rikis login --token <token>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**3. Add a runtime:**
|
|
36
|
+
```
|
|
37
|
+
rikis config --add-runtime ollama --url http://localhost:11434
|
|
38
|
+
rikis config --add-runtime llama.cpp --url http://localhost:8080
|
|
39
|
+
rikis config --add-runtime lmstudio --url http://localhost:1234
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**4. Start the agent:**
|
|
43
|
+
```
|
|
44
|
+
rikis start
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The agent polls Protorikis Bench for benchmark jobs, runs inference locally, and returns results.
|
|
48
|
+
|
|
49
|
+
## Commands
|
|
50
|
+
|
|
51
|
+
| Command | Description |
|
|
52
|
+
|---------|-------------|
|
|
53
|
+
| `rikis login --token <token>` | Authenticate with Protorikis Bench |
|
|
54
|
+
| `rikis config --add-runtime <type> --url <url>` | Add a local LLM runtime |
|
|
55
|
+
| `rikis config --remove-runtime <url>` | Remove a runtime |
|
|
56
|
+
| `rikis start` | Start the agent |
|
|
57
|
+
| `rikis status` | Show current configuration |
|
|
58
|
+
|
|
59
|
+
## Dependencies
|
|
60
|
+
|
|
61
|
+
rikis is intentionally lightweight and uses only these libraries:
|
|
62
|
+
|
|
63
|
+
- `httpx` - HTTP client
|
|
64
|
+
- `Typer` - CLI framework
|
rikis-0.0.1/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# rikis
|
|
2
|
+
|
|
3
|
+
Lightweight agent that connects your local LLM runtimes to [Protorikis Bench](https://bench.protorikis.com) and runs benchmark jobs on them.
|
|
4
|
+
|
|
5
|
+
> rikis only runs inference - it never executes generated code locally
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pipx install rikis
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
**1. Get a token** from [Protorikis Bench](https://bench.protorikis.com) → Endpoints → Add Endpoint
|
|
16
|
+
|
|
17
|
+
**2. Log in:**
|
|
18
|
+
```
|
|
19
|
+
rikis login --token <token>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**3. Add a runtime:**
|
|
23
|
+
```
|
|
24
|
+
rikis config --add-runtime ollama --url http://localhost:11434
|
|
25
|
+
rikis config --add-runtime llama.cpp --url http://localhost:8080
|
|
26
|
+
rikis config --add-runtime lmstudio --url http://localhost:1234
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**4. Start the agent:**
|
|
30
|
+
```
|
|
31
|
+
rikis start
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The agent polls Protorikis Bench for benchmark jobs, runs inference locally, and returns results.
|
|
35
|
+
|
|
36
|
+
## Commands
|
|
37
|
+
|
|
38
|
+
| Command | Description |
|
|
39
|
+
|---------|-------------|
|
|
40
|
+
| `rikis login --token <token>` | Authenticate with Protorikis Bench |
|
|
41
|
+
| `rikis config --add-runtime <type> --url <url>` | Add a local LLM runtime |
|
|
42
|
+
| `rikis config --remove-runtime <url>` | Remove a runtime |
|
|
43
|
+
| `rikis start` | Start the agent |
|
|
44
|
+
| `rikis status` | Show current configuration |
|
|
45
|
+
|
|
46
|
+
## Dependencies
|
|
47
|
+
|
|
48
|
+
rikis is intentionally lightweight and uses only these libraries:
|
|
49
|
+
|
|
50
|
+
- `httpx` - HTTP client
|
|
51
|
+
- `Typer` - CLI framework
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rikis"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Lightweight agent that pulls and runs LLM benchmarks from Protorikis Bench"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "protorikis", email = "code@protorikis.com" }
|
|
8
|
+
]
|
|
9
|
+
license = { text = "Apache-2.0" }
|
|
10
|
+
requires-python = ">=3.13"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"httpx>=0.28.1",
|
|
13
|
+
"typer>=0.25.1",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Homepage = "https://bench.protorikis.com"
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
rikis = "rikis:main"
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["uv_build>=0.10.9,<0.11.0"]
|
|
24
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Copyright 2026 Protorikis
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import time
|
|
5
|
+
import httpx
|
|
6
|
+
import typer
|
|
7
|
+
from rikis import config
|
|
8
|
+
from rikis.runtimes import Runtime
|
|
9
|
+
|
|
10
|
+
JOB_POLL_INTERVAL = 15 # seconds
|
|
11
|
+
|
|
12
|
+
def run(token: str, runtimes: dict[str, Runtime]) -> None:
|
|
13
|
+
server_url = config.load_server_url()
|
|
14
|
+
auth = {"Authorization": f"Bearer {token}"}
|
|
15
|
+
|
|
16
|
+
waiting = False
|
|
17
|
+
while True:
|
|
18
|
+
ran = _pull_and_run_job(server_url, auth, runtimes)
|
|
19
|
+
if not ran:
|
|
20
|
+
if not waiting:
|
|
21
|
+
typer.echo("Waiting for jobs...")
|
|
22
|
+
waiting = True
|
|
23
|
+
time.sleep(JOB_POLL_INTERVAL)
|
|
24
|
+
else:
|
|
25
|
+
waiting = False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _pull_and_run_job(server_url: str, auth: dict, runtimes: dict[str, Runtime]) -> bool:
|
|
29
|
+
try:
|
|
30
|
+
res = httpx.post(f"{server_url}/api/jobs/next", headers=auth, timeout=10)
|
|
31
|
+
except httpx.RequestError as e:
|
|
32
|
+
typer.echo(f"Error: could not reach server: {e}. Retrying in {JOB_POLL_INTERVAL}s...", err=True)
|
|
33
|
+
return False
|
|
34
|
+
if res.status_code == 401:
|
|
35
|
+
typer.echo("Error: authentication failed. Re-run: rikis login --token <token>", err=True)
|
|
36
|
+
raise typer.Exit(1)
|
|
37
|
+
if not res.is_success:
|
|
38
|
+
typer.echo(f"Error: server returned {res.status_code}. Retrying in {JOB_POLL_INTERVAL}s...", err=True)
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
job = res.json()
|
|
42
|
+
if not job:
|
|
43
|
+
return False
|
|
44
|
+
|
|
45
|
+
runtime_url = job.get("runtime_url")
|
|
46
|
+
model = job.get("model")
|
|
47
|
+
|
|
48
|
+
if not model:
|
|
49
|
+
typer.echo(f"Job {job['id']}: no model specified, skipping.", err=True)
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
if not runtime_url or runtime_url not in runtimes:
|
|
53
|
+
typer.echo(f"Job {job['id']}: runtime '{runtime_url}' not available, skipping.", err=True)
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
runtime = runtimes[runtime_url]
|
|
57
|
+
|
|
58
|
+
typer.echo(f"Running job {job['id']} ({len(job['sub_jobs'])} sub-jobs) [{model}]")
|
|
59
|
+
params = job.get("llm_params", {})
|
|
60
|
+
multi_turn = params.get("multi_turn", False) or params.get("preserve_thinking", False)
|
|
61
|
+
history: list = []
|
|
62
|
+
|
|
63
|
+
for i, sub_job in enumerate(job["sub_jobs"], 1):
|
|
64
|
+
if sub_job.get("status") != "pending":
|
|
65
|
+
continue
|
|
66
|
+
label = sub_job.get("prompt_label") or sub_job["id"]
|
|
67
|
+
sub_job_id = sub_job.get("sub_job_id")
|
|
68
|
+
id_str = f" ({sub_job_id})" if sub_job_id is not None else ""
|
|
69
|
+
typer.echo(f" [{i}/{len(job['sub_jobs'])}]{id_str} {label}")
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
start_res = httpx.post(
|
|
73
|
+
f"{server_url}/api/jobs/{job['id']}/sub_jobs/{sub_job['id']}/start",
|
|
74
|
+
headers=auth,
|
|
75
|
+
timeout=10,
|
|
76
|
+
)
|
|
77
|
+
if not start_res.is_success:
|
|
78
|
+
typer.echo(f" Error: {start_res.status_code}", err=True)
|
|
79
|
+
continue
|
|
80
|
+
else:
|
|
81
|
+
match start_res.json().get("status"):
|
|
82
|
+
case "job_cancelled":
|
|
83
|
+
typer.echo(f" job {job['id']} cancelled, stopping")
|
|
84
|
+
break
|
|
85
|
+
case "skipped":
|
|
86
|
+
typer.echo(f" sub-job {sub_job['id']}: skipped")
|
|
87
|
+
continue
|
|
88
|
+
except httpx.RequestError as e:
|
|
89
|
+
typer.echo(f" Error: could not reach server on sub-job start: {e}", err=True)
|
|
90
|
+
continue
|
|
91
|
+
|
|
92
|
+
prompt = sub_job["prompt"]
|
|
93
|
+
result: dict
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
llm_result = runtime.run_prompt(
|
|
97
|
+
prompt,
|
|
98
|
+
model,
|
|
99
|
+
temperature=params.get("temperature"),
|
|
100
|
+
thinking=params.get("thinking", True),
|
|
101
|
+
preserve_thinking=params.get("preserve_thinking"),
|
|
102
|
+
history=history if multi_turn else None,
|
|
103
|
+
)
|
|
104
|
+
result = {
|
|
105
|
+
"status": "ok",
|
|
106
|
+
"error": None,
|
|
107
|
+
"reasoning": llm_result.reasoning,
|
|
108
|
+
"response": llm_result.response,
|
|
109
|
+
"ttft_seconds": llm_result.ttft_seconds,
|
|
110
|
+
"generation_seconds": llm_result.generation_seconds,
|
|
111
|
+
"tokens_generated": llm_result.tokens_generated,
|
|
112
|
+
"tokens_per_second": llm_result.tokens_per_second,
|
|
113
|
+
}
|
|
114
|
+
except Exception as e:
|
|
115
|
+
typer.echo(f" sub-job {sub_job['id']} error: {e}", err=True)
|
|
116
|
+
result = {"status": "error", "error": str(e)}
|
|
117
|
+
|
|
118
|
+
if multi_turn:
|
|
119
|
+
reasoning = result.get("reasoning") or ""
|
|
120
|
+
response = result.get("response") or ""
|
|
121
|
+
assistant_content = f"<think>\n{reasoning}\n</think>\n\n{response}" if params.get("preserve_thinking") and reasoning else response
|
|
122
|
+
history.append({"role": "user", "content": prompt})
|
|
123
|
+
history.append({"role": "assistant", "content": assistant_content})
|
|
124
|
+
|
|
125
|
+
try:
|
|
126
|
+
httpx.post(
|
|
127
|
+
f"{server_url}/api/jobs/{job['id']}/sub_jobs/{sub_job['id']}/result",
|
|
128
|
+
json=result,
|
|
129
|
+
headers=auth,
|
|
130
|
+
timeout=10,
|
|
131
|
+
)
|
|
132
|
+
except httpx.RequestError as e:
|
|
133
|
+
typer.echo(f"Error: could not submit result for sub-job {sub_job['id']}: {e}", err=True)
|
|
134
|
+
|
|
135
|
+
if result["status"] == "ok":
|
|
136
|
+
typer.echo(f" sub-job {sub_job['id']}: ok | {result['tokens_generated']} tokens | {result['tokens_per_second']:.1f} tok/s | ttft={result['ttft_seconds']:.2f}s")
|
|
137
|
+
|
|
138
|
+
return True
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Copyright 2026 Protorikis
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import socket
|
|
5
|
+
import httpx
|
|
6
|
+
import typer
|
|
7
|
+
from rikis import config as cfg, agent
|
|
8
|
+
from rikis.runtimes import create_runtime, RUNTIME_TYPES
|
|
9
|
+
|
|
10
|
+
app = typer.Typer()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@app.command()
|
|
14
|
+
def login(
|
|
15
|
+
token: str = typer.Option(..., help="Token generated from Protorikis Bench"),
|
|
16
|
+
name: str = typer.Option(None, "--name", help="Display name for this endpoint"),
|
|
17
|
+
):
|
|
18
|
+
"""Authenticate this machine with Protorikis Bench."""
|
|
19
|
+
server_url = cfg.load_server_url()
|
|
20
|
+
hostname = socket.gethostname()
|
|
21
|
+
payload: dict = {"token": token, "hostname": hostname}
|
|
22
|
+
if name:
|
|
23
|
+
payload["name"] = name
|
|
24
|
+
try:
|
|
25
|
+
res = httpx.post(
|
|
26
|
+
f"{server_url}/api/endpoints/register",
|
|
27
|
+
json=payload,
|
|
28
|
+
timeout=60,
|
|
29
|
+
)
|
|
30
|
+
if res.status_code != 200:
|
|
31
|
+
typer.echo("Invalid token. Please generate a new one from Protorikis Bench.", err=True)
|
|
32
|
+
raise typer.Exit(1)
|
|
33
|
+
except httpx.RequestError:
|
|
34
|
+
typer.echo(f"Could not reach server at {server_url}. Is the backend accessible?", err=True)
|
|
35
|
+
raise typer.Exit(1)
|
|
36
|
+
|
|
37
|
+
cfg.save_token(token)
|
|
38
|
+
typer.echo(f"Logged in successfully as {hostname}.")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@app.command()
|
|
42
|
+
def config(
|
|
43
|
+
add_runtime: str = typer.Option(None, "--add-runtime", help=f"Add a runtime. Type: {', '.join(RUNTIME_TYPES)}"),
|
|
44
|
+
remove_runtime: str = typer.Option(None, "--remove-runtime", help="Remove a runtime by URL"),
|
|
45
|
+
url: str = typer.Option(None, "--url", help="Runtime base URL (e.g. http://localhost:11434)"),
|
|
46
|
+
):
|
|
47
|
+
"""Configure rikis."""
|
|
48
|
+
if add_runtime is not None:
|
|
49
|
+
if not url:
|
|
50
|
+
typer.echo("--url is required with --add-runtime.", err=True)
|
|
51
|
+
raise typer.Exit(1)
|
|
52
|
+
if add_runtime not in RUNTIME_TYPES:
|
|
53
|
+
typer.echo(f"Unknown runtime type '{add_runtime}'. Available: {', '.join(RUNTIME_TYPES)}", err=True)
|
|
54
|
+
raise typer.Exit(1)
|
|
55
|
+
cfg.add_runtime(add_runtime, url)
|
|
56
|
+
typer.echo(f"Runtime added: {add_runtime} @ {url}")
|
|
57
|
+
return
|
|
58
|
+
if remove_runtime is not None:
|
|
59
|
+
if not cfg.remove_runtime(remove_runtime):
|
|
60
|
+
typer.echo(f"No runtime found with URL '{remove_runtime}'.", err=True)
|
|
61
|
+
raise typer.Exit(1)
|
|
62
|
+
typer.echo(f"Runtime removed: {remove_runtime}")
|
|
63
|
+
return
|
|
64
|
+
typer.echo("Nothing to configure. Use --add-runtime or --remove-runtime.", err=True)
|
|
65
|
+
raise typer.Exit(1)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@app.command()
|
|
69
|
+
def start():
|
|
70
|
+
"""Start the rikis agent (pulls jobs from server and runs them)."""
|
|
71
|
+
token = cfg.load_token()
|
|
72
|
+
if not token:
|
|
73
|
+
typer.echo("Not logged in. Run: rikis login --token <token>", err=True)
|
|
74
|
+
raise typer.Exit(1)
|
|
75
|
+
|
|
76
|
+
runtime_configs = cfg.load_runtimes()
|
|
77
|
+
if not runtime_configs:
|
|
78
|
+
typer.echo("No runtimes configured. Run: rikis config --add-runtime <type> --url <url>", err=True)
|
|
79
|
+
raise typer.Exit(1)
|
|
80
|
+
|
|
81
|
+
runtimes: dict = {rc["url"]: create_runtime(rc["type"], rc["url"]) for rc in runtime_configs}
|
|
82
|
+
|
|
83
|
+
profiles = []
|
|
84
|
+
typer.echo("Checking runtimes...")
|
|
85
|
+
for rc in runtime_configs:
|
|
86
|
+
try:
|
|
87
|
+
models = runtimes[rc["url"]].list_models()
|
|
88
|
+
profiles.append({"type": rc["type"], "url": rc["url"], "models": models})
|
|
89
|
+
typer.echo(f" {rc['type']} @ {rc['url']}: {len(models)} model(s)")
|
|
90
|
+
except Exception as e:
|
|
91
|
+
profiles.append({"type": rc["type"], "url": rc["url"], "models": []})
|
|
92
|
+
typer.echo(f" {rc['type']} @ {rc['url']}: unreachable ({e})")
|
|
93
|
+
|
|
94
|
+
auth = {"Authorization": f"Bearer {token}"}
|
|
95
|
+
server_url = cfg.load_server_url()
|
|
96
|
+
try:
|
|
97
|
+
httpx.post(f"{server_url}/api/endpoints/runtimes", json={"runtimes": profiles}, headers=auth, timeout=10)
|
|
98
|
+
except httpx.RequestError:
|
|
99
|
+
typer.echo("Warning: could not push runtime profiles to server.", err=True)
|
|
100
|
+
|
|
101
|
+
agent.run(token, runtimes)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@app.command()
|
|
105
|
+
def status():
|
|
106
|
+
"""Show current agent configuration."""
|
|
107
|
+
token = cfg.load_token()
|
|
108
|
+
runtimes = cfg.load_runtimes()
|
|
109
|
+
typer.echo("Logged in." if token else "Not logged in.")
|
|
110
|
+
if runtimes:
|
|
111
|
+
typer.echo(f"{len(runtimes)} runtime(s) configured:")
|
|
112
|
+
for r in runtimes:
|
|
113
|
+
typer.echo(f" {r['type']} @ {r['url']}")
|
|
114
|
+
else:
|
|
115
|
+
typer.echo("No runtimes configured.")
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright 2026 Protorikis
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
CONFIG_PATH = Path.home() / ".rikis" / "config.json"
|
|
8
|
+
|
|
9
|
+
DEFAULT_SERVER_URL = "https://bench.protorikis.com"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def save_token(token: str) -> None:
|
|
13
|
+
_save({"token": token})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def load_token() -> str | None:
|
|
17
|
+
return _load_raw().get("token")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def load_server_url() -> str:
|
|
21
|
+
return _load_raw().get("server_url", DEFAULT_SERVER_URL)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def add_runtime(type: str, url: str) -> None:
|
|
25
|
+
data = _load_raw()
|
|
26
|
+
runtimes = [r for r in data.get("runtimes", []) if r["url"] != url]
|
|
27
|
+
runtimes.append({"type": type, "url": url})
|
|
28
|
+
_save({"runtimes": runtimes})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def remove_runtime(url: str) -> bool:
|
|
32
|
+
data = _load_raw()
|
|
33
|
+
runtimes = data.get("runtimes", [])
|
|
34
|
+
filtered = [r for r in runtimes if r["url"] != url]
|
|
35
|
+
if len(filtered) == len(runtimes):
|
|
36
|
+
return False
|
|
37
|
+
_save({"runtimes": filtered})
|
|
38
|
+
return True
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def load_runtimes() -> list[dict]:
|
|
42
|
+
return _load_raw().get("runtimes", [])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _save(updates: dict) -> None:
|
|
46
|
+
CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
47
|
+
data = _load_raw()
|
|
48
|
+
data.update(updates)
|
|
49
|
+
CONFIG_PATH.write_text(json.dumps(data, indent=2))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _load_raw() -> dict:
|
|
53
|
+
if not CONFIG_PATH.exists():
|
|
54
|
+
return {}
|
|
55
|
+
return json.loads(CONFIG_PATH.read_text())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copyright 2026 Protorikis
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
from rikis.runtimes.base import Runtime, LLMResult
|
|
5
|
+
from rikis.runtimes.llama_cpp import LlamaCppRuntime
|
|
6
|
+
from rikis.runtimes.lmstudio import LMStudioRuntime
|
|
7
|
+
from rikis.runtimes.ollama import OllamaRuntime
|
|
8
|
+
|
|
9
|
+
RUNTIME_TYPES: dict[str, type[Runtime]] = {
|
|
10
|
+
"llama.cpp": LlamaCppRuntime,
|
|
11
|
+
"lmstudio": LMStudioRuntime,
|
|
12
|
+
"ollama": OllamaRuntime,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def create_runtime(type: str, url: str) -> Runtime:
|
|
17
|
+
cls = RUNTIME_TYPES.get(type)
|
|
18
|
+
if not cls:
|
|
19
|
+
raise ValueError(f"Unknown runtime type: {type!r}. Available: {', '.join(RUNTIME_TYPES)}")
|
|
20
|
+
return cls(url)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Copyright 2026 Protorikis
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import time
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class LLMResult:
|
|
14
|
+
response: str
|
|
15
|
+
reasoning: str
|
|
16
|
+
ttft_seconds: float
|
|
17
|
+
generation_seconds: float
|
|
18
|
+
tokens_generated: int
|
|
19
|
+
tokens_per_second: float
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Runtime(ABC):
|
|
23
|
+
def __init__(self, base_url: str):
|
|
24
|
+
self.base_url = base_url.rstrip("/")
|
|
25
|
+
|
|
26
|
+
@abstractmethod
|
|
27
|
+
def list_models(self) -> list[str]: ...
|
|
28
|
+
|
|
29
|
+
@abstractmethod
|
|
30
|
+
def run_prompt(self, prompt: str, model: str, *, temperature: float | None = None, thinking: bool = True, preserve_thinking: bool | None = None, history: list | None = None) -> LLMResult: ...
|
|
31
|
+
|
|
32
|
+
def _openai_stream(self, prompt: str, model: str, *, temperature: float | None = None, thinking: bool = True, preserve_thinking: bool | None = None, history: list | None = None, extra_messages: list | None = None) -> LLMResult:
|
|
33
|
+
messages = (history or []) + [{"role": "user", "content": prompt}]
|
|
34
|
+
if extra_messages:
|
|
35
|
+
messages += extra_messages
|
|
36
|
+
payload: dict = {
|
|
37
|
+
"model": model,
|
|
38
|
+
"messages": messages,
|
|
39
|
+
"stream": True,
|
|
40
|
+
}
|
|
41
|
+
chat_template_kwargs: dict = {}
|
|
42
|
+
if not thinking:
|
|
43
|
+
chat_template_kwargs["enable_thinking"] = False
|
|
44
|
+
payload["reasoning_effort"] = "none"
|
|
45
|
+
if preserve_thinking:
|
|
46
|
+
chat_template_kwargs["preserve_thinking"] = True
|
|
47
|
+
if chat_template_kwargs:
|
|
48
|
+
payload["chat_template_kwargs"] = chat_template_kwargs
|
|
49
|
+
if temperature is not None:
|
|
50
|
+
payload["temperature"] = temperature
|
|
51
|
+
|
|
52
|
+
t_start = time.time()
|
|
53
|
+
t_first_token: float | None = None
|
|
54
|
+
token_count = 0
|
|
55
|
+
response_parts: list[str] = []
|
|
56
|
+
reasoning_parts: list[str] = []
|
|
57
|
+
|
|
58
|
+
with httpx.stream("POST", f"{self.base_url}/v1/chat/completions", json=payload, timeout=None) as resp:
|
|
59
|
+
resp.raise_for_status()
|
|
60
|
+
for raw_line in resp.iter_lines():
|
|
61
|
+
line = raw_line.strip()
|
|
62
|
+
if not line.startswith("data: "):
|
|
63
|
+
continue
|
|
64
|
+
data = line[len("data: "):]
|
|
65
|
+
if data == "[DONE]":
|
|
66
|
+
break
|
|
67
|
+
try:
|
|
68
|
+
chunk = json.loads(data)
|
|
69
|
+
except json.JSONDecodeError:
|
|
70
|
+
continue
|
|
71
|
+
delta = chunk.get("choices", [{}])[0].get("delta", {})
|
|
72
|
+
reasoning = delta.get("reasoning_content") or delta.get("reasoning") or ""
|
|
73
|
+
content = delta.get("content") or ""
|
|
74
|
+
if reasoning:
|
|
75
|
+
if t_first_token is None:
|
|
76
|
+
t_first_token = time.time()
|
|
77
|
+
token_count += 1
|
|
78
|
+
reasoning_parts.append(reasoning)
|
|
79
|
+
if content:
|
|
80
|
+
if t_first_token is None:
|
|
81
|
+
t_first_token = time.time()
|
|
82
|
+
token_count += 1
|
|
83
|
+
response_parts.append(content)
|
|
84
|
+
|
|
85
|
+
t_end = time.time()
|
|
86
|
+
ttft = (t_first_token - t_start) if t_first_token else 0.0
|
|
87
|
+
gen_time = (t_end - t_first_token) if t_first_token else 0.0
|
|
88
|
+
tps = (token_count / gen_time) if gen_time > 0 else 0.0
|
|
89
|
+
|
|
90
|
+
return LLMResult(
|
|
91
|
+
response="".join(response_parts),
|
|
92
|
+
reasoning="".join(reasoning_parts),
|
|
93
|
+
ttft_seconds=ttft,
|
|
94
|
+
generation_seconds=gen_time,
|
|
95
|
+
tokens_generated=token_count,
|
|
96
|
+
tokens_per_second=tps,
|
|
97
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright 2026 Protorikis
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
from rikis.runtimes.base import Runtime, LLMResult
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LlamaCppRuntime(Runtime):
|
|
9
|
+
def list_models(self) -> list[str]:
|
|
10
|
+
resp = httpx.get(f"{self.base_url}/v1/models", timeout=10)
|
|
11
|
+
resp.raise_for_status()
|
|
12
|
+
return [m["id"] for m in resp.json().get("data", [])]
|
|
13
|
+
|
|
14
|
+
def run_prompt(self, prompt: str, model: str, *, temperature: float | None = None, thinking: bool = True, preserve_thinking: bool | None = None, history: list | None = None) -> LLMResult:
|
|
15
|
+
return self._openai_stream(prompt, model, temperature=temperature, thinking=thinking, preserve_thinking=preserve_thinking, history=history)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2026 Protorikis
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
from rikis.runtimes.base import Runtime, LLMResult
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LMStudioRuntime(Runtime):
|
|
9
|
+
def list_models(self) -> list[str]:
|
|
10
|
+
resp = httpx.get(f"{self.base_url}/v1/models", timeout=10)
|
|
11
|
+
resp.raise_for_status()
|
|
12
|
+
return [m["id"] for m in resp.json().get("data", [])]
|
|
13
|
+
|
|
14
|
+
def run_prompt(self, prompt: str, model: str, *, temperature: float | None = None, thinking: bool = True, preserve_thinking: bool | None = None, history: list | None = None) -> LLMResult:
|
|
15
|
+
extra_messages = [{"role": "assistant", "content": "<think>\n</think>"}] if not thinking else None
|
|
16
|
+
return self._openai_stream(prompt, model, temperature=temperature, thinking=thinking, preserve_thinking=preserve_thinking, history=history, extra_messages=extra_messages)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright 2026 Protorikis
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
from rikis.runtimes.base import Runtime, LLMResult
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OllamaRuntime(Runtime):
|
|
9
|
+
def list_models(self) -> list[str]:
|
|
10
|
+
resp = httpx.get(f"{self.base_url}/api/tags", timeout=10)
|
|
11
|
+
resp.raise_for_status()
|
|
12
|
+
return [m["name"] for m in resp.json().get("models", [])]
|
|
13
|
+
|
|
14
|
+
def run_prompt(self, prompt: str, model: str, *, temperature: float | None = None, thinking: bool = True, preserve_thinking: bool | None = None, history: list | None = None) -> LLMResult:
|
|
15
|
+
return self._openai_stream(prompt, model, temperature=temperature, thinking=thinking, preserve_thinking=preserve_thinking, history=history)
|