Package dev.gmitch215.bytebox.binding
Interface Ai
- All Superinterfaces:
org.teavm.jso.JSObject
public interface Ai
extends org.teavm.jso.JSObject
The Workers AI binding. Declared with
ai(), named AI.
Inference runs on Cloudflare's GPUs rather than in the isolate, so this always crosses the network and always blocks. There is no local emulation: a test either fakes this binding or points it at the real service.
TSObject input = TSObject.object();
input.set("prompt", TSObject.of("why is the sky blue?"));
String answer = env.ai().run("@cf/meta/llama-3.1-8b-instruct", input).get("response").asString();
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault TSObjectEmbeds text with an embedding model, which is the common case worth naming.default TSObjectRuns a model.default TSObjectRuns a model with options such asgatewayorreturnRawResponse.org.teavm.jso.core.JSPromise<TSObject> org.teavm.jso.core.JSPromise<TSObject> Methods inherited from interface org.teavm.jso.JSObject
cast
-
Method Details
-
run
Runs a model.- Parameters:
model- the model name, such as@cf/meta/llama-3.1-8b-instructinput- the model's input, whose shape depends on the model- Returns:
- the model's output
-
run
Runs a model with options such asgatewayorreturnRawResponse.- Parameters:
model- the model nameinput- the model's inputoptions- the options- Returns:
- the model's output
-
embed
Embeds text with an embedding model, which is the common case worth naming.- Parameters:
model- the embedding modeltext- the text- Returns:
- the response, whose
dataholds one vector per input
-
runModel
-
runModel
-