Skip to content

Add persistent multi-turn chat and Gemma 4 image support - #51

Open
AbhinavPanwarDev wants to merge 19 commits into
drumih:mainfrom
AbhinavPanwarDev:AbhinavPanwarDev/chat-enhancements
Open

Add persistent multi-turn chat and Gemma 4 image support#51
AbhinavPanwarDev wants to merge 19 commits into
drumih:mainfrom
AbhinavPanwarDev:AbhinavPanwarDev/chat-enhancements

Conversation

@AbhinavPanwarDev

@AbhinavPanwarDev AbhinavPanwarDev commented Aug 1, 2026

Copy link
Copy Markdown

Summary

This PR evolves the Mac app from a single-prompt interface into a persistent multi-turn chat workspace and adds local image input support for Gemma 4.

Chat experience

  • Adds role-aware multi-turn conversations throughout the app and decode-service protocol.
  • Persists complete chat history across chat switching and app relaunches.
  • Adds a collapsible sidebar with newest chats first.
  • Supports creating, selecting, renaming, and deleting conversations.
  • Prevents multiple empty “New chat” pages from being created.
  • Adds compact relative timestamps without continuously displaying seconds.
  • Clears the composer immediately after a prompt is accepted.
  • Supports Enter to send and Shift+Enter for a newline.
  • Allows the latest user prompt to be edited and regenerated.
  • Keeps earlier prompts immutable to avoid branching the conversation unexpectedly.
  • Supports regenerating the latest response.
  • Presents model load and reload actions inside every chat when generation is unavailable.

Transcript and streaming

  • Renders user and assistant messages as distinct chat turns.
  • Improves Markdown rendering for headings, lists, emphasis, code blocks, and inline code.
  • Renders streamed output continuously instead of waiting for generation to finish.
  • Reduces Markdown flickering and layout instability during streaming.
  • Adds stable scroll-following and message copy actions.
  • Periodically persists an active streamed response so partial output is not lost unexpectedly.
  • Guards against long runs of invisible control tokens that produce no visible response.

Image support

  • Adds an image picker and image preview to the Mac chat composer.
  • Persists managed image attachments with their chat messages.
  • Preserves attachments when switching chats, relaunching, editing, or regenerating.
  • Adds image attachment metadata to app requests and decode-service IPC without embedding image bytes in history files or IPC frames.
  • Adds native Gemma 4 image preprocessing and vision-tower execution.
  • Adds an optional Gemma 4 vision sidecar installer and verifier.
  • Streams vision weights from disk one layer at a time instead of loading the complete vision checkpoint.
  • Adds 2D positional embeddings, RMS normalization, noncausal vision attention, gated GELU MLP processing, spatial pooling, standardization, and projection into the language-model embedding space.
  • Adds bounded vision feature caching.
  • Adds FP16 activation safeguards for the BF16-trained vision tower.
  • Suppresses image/control tokens during text generation and stops pathological invisible-token loops.
Screenshot 2026-08-03 at 8 08 11 PM Screenshot 2026-08-03 at 8 08 38 PM Screenshot 2026-08-03 at 10 44 46 PM

Issues addressed

Closes #12 — Multi-turn chat

Closes #65 — Clear the composer after a prompt is submitted

Closes #9 — Visual Tower support

Partially addresses #61 — Support multimodal input. This PR implements image input in the Mac app and decode-service path. Audio input and multimodal requests through the OpenAI-compatible server are not included.

The TurboFieldfare core target built successfully.

Focused tests were added or extended for:

  • Multi-turn request construction.
  • Chat persistence and chat selection.
  • Prompt editing and regeneration.
  • Composer clearing.
  • Decode-service protocol compatibility.
  • Image attachment persistence and validation.
  • Gemma 4 image preprocessing.
  • Vision Metal kernels.
  • Multimodal prefill behavior.
  • Streaming response buffering.
  • Invisible control-token handling.
  • Vision sidecar planning, installation, and verification.

A complete reference-quality comparison of image output against the upstream Gemma 4 implementation has not yet been performed.

Memory and performance

The optional vision payload is stored in a separate sidecar of approximately 1.09 GiB. The complete sidecar is not loaded into memory.

Vision encoding uses bounded memory:

  • Vision tensors are read directly into reusable Metal buffers.
  • Only one vision layer’s weights are streamed at a time.
  • Vision activation and matrix-conversion buffers are reused during an image request.
  • Image preprocessing is limited by input file size, decoded pixel count, and a maximum of 280 visual tokens.
  • The complete checkpoint, shard, or vision sidecar is never materialized in Swift heap memory.
  • Temporary vision encoding buffers are released after the request.
  • Only the projected image features required by language-model prefill remain available to the request.
  • Managed image files are referenced by metadata instead of being copied into chat-history JSON or decode IPC frames.

The chat changes intentionally retain conversation text so saved chats can be restored. Active streaming uses a bounded temporary response buffer that is reset between runs.

No controlled before/after performance or peak-memory measurements were collected. Vision encoding adds temporary Metal memory and preprocessing latency only when an image is submitted.

Remaining limitations

  • Audio input is not implemented.

  • The OpenAI-compatible server does not yet accept image or audio content.

  • Only the latest user prompt can be edited.

  • Editing an image prompt regenerates the latest answer; it does not create alternate conversation branches.

  • Image inference requires the optional vision sidecar to be installed.

  • Image output quality still needs comparison against the upstream Gemma 4 processor and vision implementation.

  • Peak memory and vision preprocessing latency still need measurement on supported Apple Silicon hardware.

  • Full package-test execution requires a Swift/Xcode environment containing the necessary testing and SwiftUI preview plugins.

  • The change does not load a complete checkpoint, shard, or large model tensor into Swift heap memory.

  • Logs and artifacts contain no credentials, private paths, or model weights.

Validation

The following checks were used:

git diff --check

/Library/Developer/CommandLineTools/usr/bin/swiftc \
  -frontend \
  -parse \
  Sources/TurboFieldfare/Kernels/Vision/Gemma4VisionKernels.swift \
  Sources/TurboFieldfare/Runtime/Vision/Gemma4VisionEncoder.swift
  
  CLANG_MODULE_CACHE_PATH=/tmp/turbo-fieldfare-clang-cache \
swift build --disable-sandbox \
  --target TurboFieldfare \
  -Xswiftc -Xfrontend \
  -Xswiftc -interface-compiler-version \
  -Xswiftc -Xfrontend \
  -Xswiftc 6.3.2
  
  
  

@AbhinavPanwarDev AbhinavPanwarDev changed the title Added persistent multi-turn chat workspace to Mac app Add persistent multi-turn chat workspace to Mac app Aug 2, 2026
@AbhinavPanwarDev
AbhinavPanwarDev force-pushed the AbhinavPanwarDev/chat-enhancements branch from 891cd64 to 069aedc Compare August 3, 2026 14:06
@AbhinavPanwarDev AbhinavPanwarDev changed the title Add persistent multi-turn chat workspace to Mac app Add persistent multi-turn chat and Gemma 4 image support Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Clear the composer after a prompt is submitted [Feature]: Multi-turn chat [Feature]: Visual Tower support

1 participant