Class LlmChatBinding
Convenience wiring that turns a ChatView into an LLM-driven
chat surface in one call. Pulls the user's input out of the
view's ChatInput, appends it as a USER
message, opens a streaming chat call against the supplied
LlmClient, and pipes deltas into a freshly-appended assistant
bubble.
ChatView itself has no dependency on the AI package, so apps
that want a peer-to-peer messaging UI (a WhatsApp clone, for
example) can keep using ChatView without pulling LlmClient
onto their classpath -- it's only when you call
bind(ChatView, LlmClient, ChatRequest) that the binding is
established.
Example
LlmClient client = LlmClient.openai(SecureStorage.getInstance().get("openai_key"));
ChatRequest base = ChatRequest.builder()
.model("gpt-4o-mini")
.addMessage(ChatMessage.system("You are a terse assistant."))
.build();
ChatView view = new ChatView();
LlmChatBinding.bind(view, client, base);
// ...add view to a Form and that's it.
The base request's messages are a fixed prefix: they lead every request, ahead of the conversation held by the view. That is what makes it the place for a system prompt, and it means anything else put there -- a seed user or assistant turn -- is repeated on every turn too, so put those in the view instead.
The view's accumulated history is replayed on every turn so the
model has full conversation context. The original baseRequest
is treated as a template -- its model, tools, temperature, etc.
are preserved across turns, and its messages lead every request as
described above.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidbind(ChatView view, LlmClient client, ChatRequest baseRequest) Connects a chat view to a streaming client.
-
Method Details
-
bind
Connects a chat view to a streaming client. Each submitted user message replays the current view history while retaining the base request's model, sampling, tool, metadata, and safety settings.- Parameters:
view- chat UI to driveclient- provider client used for every turnbaseRequest- request template and optional initial messages
-