X Tutup
Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Simple Chat Example

This application is a minimal example of how to use the genui package to create a simple, conversational chat application.

Purpose

The main goal of this example is to demonstrate the fundamental concepts of genui in a straightforward chat context. It shows how to:

  1. Initialize and use the SurfaceController, the core engine for the package.
  2. Provide a simple system prompt to guide the AI's behavior.
  3. Send user messages to the AI and receive responses.
  4. Handle the creation of new UI "surfaces" generated by the AI.
  5. Render these dynamic UI surfaces within a standard chat message list.
  6. Manage a conversation history that interleaves user text messages with AI-generated UI responses.

Unlike more complex examples, this app does not define a custom widget catalog. Instead, it relies on the default coreCatalog provided by genui, meaning the AI can only respond with basic widgets like Text, Column, ElevatedButton, etc.

How it Works

The application's logic is contained almost entirely within lib/chat_session.dart.

  1. Initialization: A SurfaceController is created to manage the state of UI surfaces.
  2. User Input: The user types a message into a TextField and hits send.
  3. Sending the Message:
    • The user's text is immediately added to the local message list.
    • The request is sent to the AiClient.
  4. AI Response:
    • The AiClient streams A2uiMessages back.
    • These messages are piped into the SurfaceController.
  5. UI Rendering:
    • The UI listens to SurfaceController.surfaceUpdates or A2uiTransportAdapter streams.
    • When a surface is added, a Surface widget is rendered, dynamically building the UI based on the UiDefinition managed by SurfaceController.

Getting Started

Follow the instructions in the run_app_with_gemini_key.md.

X Tutup