Support shinychat history for composed Chatlas clients such as Python Commons

Đang mở
#347 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

@jat255 đang làm issue này rồi.

Từ ngày 14/9/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

py

For Python only, when using commons with page_chat, the conversation history feature doesn't work; it's always blank.

Python Commons deliberately composes a chatlas.Chat rather than subclassing it. It exposes Chatlas-compatible behavior:

  • stream_async(...)
  • get_turns() -> list[chatlas.Turn]
  • set_turns(Sequence[chatlas.Turn])

This allows shinychat to stream from a Commons agent directly.

However, shinychat recognizes Chatlas turn history using a nominal check equivalent to:

isinstance(client, chatlas.Chat)

Other clients follow the generic ClientWithTurns path, which expects JSON-round-trippable turns. Commons therefore falls into the generic path even though its history uses chatlas.Turn semantics.

The result is that direct streaming works, but shinychat's conversation history and New Chat support require an application-level adapter that converts:

chatlas.Turn <-> JSON dictionaries

For example, the desired integration is roughly:

agent = Commons(...)
chat = shinychat.Chat("chat", client=agent)
ui = shinychat.page_chat("chat", history=True)

without needing a wrapper solely for history serialization.

History restoration also needs to call Commons.queue_restore_reminder(), similar to the hook installed by R's commons_server().

Possible directions

Some possible fixes:

  • Have shinychat or chatlas define an explicit protocol or capability for clients whose history uses chatlas.Turn.
  • Give clients explicit JSON history serialization/deserialization methods.
  • Standardize one history representation across shinychat clients.
  • Add a Python integration helper analogous to R's commons_server().
Ngôn ngữ chính
Python
Star
69
Fork
5
Merge trung bình
5 ngày 16 giờ
Pull request đã merge (30 ngày)
38

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của posit-dev/commons

Tất cả issue của posit-dev/commons

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.