mirror of
https://github.com/hanzoai/java-sdk.git
synced 2026-10-30 15:07:36 +00:00
The 09-06 regeneration renamed AgentsApi and ToolsApi to AgentApi and ToolApi and the examples kept the old names, so examples-build failed on main. hanzoai/ci gates a client-lane move on that same test, so every release dispatch since has stopped before regenerating and the jar stayed at 8.5.156, a client with no postDecisions. The client is regenerated from the document api.hanzo.ai serves (hanzo-inc/cloud 151878a3c, sha256 00564264), which now namespaces its schemas (AgentAgentView, ProvisioningProvisionRequest, ToolToolList) and types chat completions, so the examples are rewritten against it: agent, store and tools use the new names and paths, and chat sends a prompt and prints the reply instead of a status. .spec-lock is left to the lane, whose next move records the ref it was handed. hanzo.yml now names where the version lives, scripts/version, so the cut rewrites build.gradle to the release number and the push to main publishes it through release.yml; without it the cut tagged a build.gradle Central already served and nothing published. The README names the 8.5 line (8.5.+, [8.5,8.6)) rather than a patch, because each release cuts a patch into build.gradle alone, and scripts/readme checks the line instead of a number that goes stale. Co-authored-by: Hanzo Dev <[email protected]>
60 lines
2.3 KiB
Java
60 lines
2.3 KiB
Java
package ai.hanzo.cloud.examples;
|
|
|
|
import ai.hanzo.Hanzo;
|
|
import ai.hanzo.cloud.ApiException;
|
|
import ai.hanzo.cloud.api.AiApi;
|
|
import ai.hanzo.cloud.model.OpenaiChatCompletionChoice;
|
|
import ai.hanzo.cloud.model.OpenaiChatCompletionMessage;
|
|
import ai.hanzo.cloud.model.OpenaiChatCompletionRequest;
|
|
import ai.hanzo.cloud.model.OpenaiChatCompletionResponse;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* chat — one completion.
|
|
*
|
|
* <p>Operation: {@code post_chat_completions} — POST /v1/chat/completions,
|
|
* the gateway's own inference route.
|
|
*
|
|
* <p>Non-streaming on purpose: streaming is SSE, a different transport that a
|
|
* generated client hands back as an opaque body, so demonstrating it here would
|
|
* teach the wrong shape.
|
|
*
|
|
* <p>The document types the route — {@code OpenaiChatCompletionRequest} in,
|
|
* {@code OpenaiChatCompletionResponse} out — so the prompt goes in as a value
|
|
* and the reply is {@code choices[0].message.content}.
|
|
*
|
|
* <pre>
|
|
* HANZO_API_KEY=hk-... ./gradlew :examples:chat
|
|
* </pre>
|
|
*/
|
|
public final class Chat {
|
|
|
|
/** A model the gateway serves. {@code HANZO_MODEL} overrides it. */
|
|
private static final String DEFAULT_MODEL = "zen5";
|
|
|
|
public static void main(String[] args) {
|
|
AiApi ai = new AiApi(Hanzo.client());
|
|
String model = System.getenv("HANZO_MODEL");
|
|
if (model == null || model.trim().isEmpty()) {
|
|
model = DEFAULT_MODEL;
|
|
}
|
|
try {
|
|
OpenaiChatCompletionResponse reply = ai.postChatCompletions(new OpenaiChatCompletionRequest()
|
|
.model(model)
|
|
.messages(List.of(new OpenaiChatCompletionMessage()
|
|
.role("user")
|
|
.content("Say hello in one short sentence."))));
|
|
List<OpenaiChatCompletionChoice> choices = reply.getChoices();
|
|
String content = choices == null || choices.isEmpty() || choices.get(0).getMessage() == null
|
|
? ""
|
|
: choices.get(0).getMessage().getContent();
|
|
System.out.printf("model %s%n", reply.getModel());
|
|
System.out.printf("reply %s%n", content);
|
|
} catch (ApiException e) {
|
|
System.err.printf("chat failed: HTTP %d %s%n", e.getCode(), e.getResponseBody());
|
|
System.exit(1);
|
|
}
|
|
}
|
|
}
|