Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
28945a3
test(client): cover surplus decisions endpoint and model validation
senamakel Nov 15, 2026
28de1be
feat(client): add Surplus Intelligence provider
senamakel Nov 15, 2026
835d12c
feat(emulation): add crop and geometry helpers for image emulation
senamakel Nov 15, 2026
10f4076
feat(emulation): scaffold box emulation pipeline
senamakel Nov 15, 2026
b940d8c
feat(emulation): implement box question emulation via noul probes
senamakel Nov 15, 2026
8f5e41d
test(emulation): import ImageFormat in emulation tests
senamakel Nov 15, 2026
bf7c88e
feat(client): emulate box questions for providers without native support
senamakel Nov 15, 2026
8494276
test(client): add imports for emulated client test helpers
senamakel Nov 15, 2026
24f725f
test(client): rename test helper client to echo_client
senamakel Nov 15, 2026
ffaf76b
feat(client): implement emulated box evaluation
senamakel Nov 15, 2026
32ab6a6
style(tinyinference-decisions): reformat emulation code and tests
senamakel Nov 15, 2026
ff0b05b
test(public-api): cover surplus box emulation defaults and overrides
senamakel Nov 15, 2026
f66ded2
feat(tinyinference-decisions): add Surplus Intelligence provider and …
senamakel Nov 15, 2026
2685fc0
test(emulation): cover empty crop returning a request error
senamakel Nov 15, 2026
f4501ce
fix(emulation): reject empty crop rectangles
senamakel Nov 15, 2026
d27f387
feat(examples): add live surplus box example
senamakel Nov 15, 2026
30d781f
test(decisions): live Surplus Box emulation example
senamakel Nov 15, 2026
0121dc0
fix(emulation): match asset keys as whole tokens
senamakel Nov 15, 2026
96b9d98
refactor(emulation): reformat nested span check
senamakel Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

## Unreleased

- `tinyinference-decisions`: Surplus Intelligence provider. `ClientConfig::surplus`
posts to `https://api.surplusintelligence.ai/v1/decisions` and accepts
OpenRouter-style resolved model ids (`jev-1.14` answered as
`typesafe/jev-1.14-20261014`); `Provider::Surplus` is a new variant, so an
exhaustive `match` on `Provider` needs an arm for it.
- `tinyinference-decisions`: Box questions are emulated for providers that do
not answer them (`Provider::answers_box`, `BoxSupport`, `BoxEmulation`,
`ClientConfig::with_box_support` / `box_support`). The client cuts the image
into a grid of upscaled PNG crops, asks one Noul per crop, optionally refines
inside the box found, and returns ordinary `Answer::Box` answers with usage
summed over the sub-requests. Adds the `image` dependency (PNG and JPEG
only).
- Security: re-pin `tinystoragedrivers-*` to 2.1.3, which moves `rusqlite` to 0.41.1
and `libsqlite3-sys` to 0.39.x (SQLite 3.54). Clears RUSTSEC-2026-0459 from the
dev-dependency tree of `tinyinference-image`; no advisory ignore was added.
Expand Down
147 changes: 143 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/tinyinference-decisions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ async-trait = { workspace = true }
# Encodes attached images for the System One `assets` map.
base64 = "0.23"
httpdate = { workspace = true }
# Decodes, crops, and re-encodes images to emulate Box questions on providers
# that only answer Noul; PNG and JPEG are the formats the provider accepts.
image = { version = "0.25.10", default-features = false, features = ["jpeg", "png"] }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
68 changes: 68 additions & 0 deletions crates/tinyinference-decisions/examples/live_surplus_box.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! Live check of Box emulation on Surplus Intelligence, using a synthetic
//! image.
//!
//! Run with `SURPLUS_API_KEY` set (and optionally `SURPLUS_JEV_MODEL`,
//! default `jev-1.14`). Surplus does not accept Box questions, so the client
//! answers this one by cropping the picture and asking a Noul per cell. Each
//! run spends a few cents of the account's balance at most.

use std::collections::BTreeMap;
use std::io::Cursor;

use image::{ImageFormat as Encoding, Rgb, RgbImage};
use serde_json::json;
use tinyinference_decisions::{
Answer, BoxQuestion, Client, ClientConfig, EvaluationRequest, ImageAsset, Question,
};

/// The red square drawn on a white 640×480 picture, as pixel bounds.
const SQUARE: (u32, u32, u32, u32) = (400, 80, 520, 200);

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = std::env::var("SURPLUS_API_KEY")?;
let model = std::env::var("SURPLUS_JEV_MODEL").unwrap_or_else(|_| "jev-1.14".to_owned());
let client = Client::new(ClientConfig::surplus(key))?;

let (left, top, right, bottom) = SQUARE;
let picture = RgbImage::from_fn(640, 480, |x, y| {
if (left..right).contains(&x) && (top..bottom).contains(&y) {
Rgb([220, 20, 20])
} else {
Rgb([255, 255, 255])
}
});
let mut png = Vec::new();
picture.write_to(&mut Cursor::new(&mut png), Encoding::Png)?;

let questions = BTreeMap::from([(
"square".to_owned(),
Question::Box(BoxQuestion {
instructions: json!({ "find": "the red square in `picture`" }),
}),
)]);
let request = EvaluationRequest::new(model, json!({ "picture": "picture-image" }), questions)
.with_image("picture-image", ImageAsset::png(&png));

let result = client.evaluate(&request).await?;
println!("model: {}", result.response.model);
println!(
"expected: left {:.3} right {:.3} top {:.3} bottom {:.3}",
f64::from(left) / 640.0,
f64::from(right) / 640.0,
f64::from(top) / 480.0,
f64::from(bottom) / 480.0,
);
match result.response.answers.get("square") {
Some(Answer::Box(found)) => println!(
"box: left {:.3} right {:.3} top {:.3} bottom {:.3} (confidence {:.2})",
found.edges.left,
found.edges.right,
found.edges.top,
found.edges.bottom,
found.confidence,
),
other => println!("unexpected answer: {other:?}"),
}
Ok(())
}
1 change: 1 addition & 0 deletions crates/tinyinference-decisions/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
| --- | --- |
| `client/` | HTTP execution, bounded retry, secret handling, and measurements |
| `request/` | typed Choice, Score, and Noul request payloads and validation |
| `emulation/` | Box questions emulated with Noul questions over image crops |
| `response/` | typed answers and request-relative response validation |
| `error/` | crate-wide classified failures |
| `sage/` | Levanto Sage decision requests, results, and HTTP transport |
8 changes: 8 additions & 0 deletions crates/tinyinference-decisions/src/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ The endpoint is used exactly as given and must pass the same URL checks. There
is no default model, so callers set `EvaluationRequest::model`; the response
must echo that model id. An empty key is allowed for unauthenticated local
servers and then no `Authorization` header is sent.

`ClientConfig::surplus` targets Surplus Intelligence at
`https://api.surplusintelligence.ai/v1/decisions` and validates the response
model like OpenRouter. Surplus rejects Box questions, so its default
`BoxSupport` is `Emulated`: `emulated.rs` sends the probe requests planned by
`crate::emulation` one after another through the same retry loop and
response validation, then validates the synthesized response against the
caller's request. `with_box_support` overrides the provider default.
Loading
Loading