A streaming text delta that repeats everything streamed so far is missing from the recorded turn

Đang mở Phù hợp với người mới
#435 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

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

Từ ngày 14/9/2026.

  • #436 của @cpsievert — đang mở
  • #471 của @pcbeingused33 — đã đóng, không merge

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu với OpenAICompletionsProvider.stream_merge_chunks và stream_turn, sử dụng bản tái hiện ChatCompletionChunk được cung cấp để theo dõi cách các delta lặp lại được tích lũy và ghi lại. Thêm một regression test bao quát ["\n", "\n", "Here is the answer."] và các ví dụ khác, sau đó xác minh rằng turn được ghi lại khớp với toàn bộ văn bản được stream.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

ai-triage:done Priority: Medium

If a streamed response contains a text delta identical to everything streamed before it, that delta does not make it onto the assistant turn. The caller watches the right text go by, and the turn that gets stored, and sent back as history on the next request, is short by one delta.

The easy case is a response starting with two identical deltas, which is what a leading "\n\n" often looks like coming off a local model.

No API key needed for this, it drives the completions provider's streaming contract:

from openai.types.chat import ChatCompletionChunk
from chatlas._provider_openai_completions import OpenAICompletionsProvider

provider = OpenAICompletionsProvider(api_key="unused", model="gpt-4o-mini")

def chunk(text, last=False):
    return ChatCompletionChunk.model_validate({
        "id": "chatcmpl-1",
        "object": "chat.completion.chunk",
        "created": 1,
        "model": "gpt-4o-mini",
        "choices": [{
            "index": 0,
            "delta": {"role": "assistant", "content": text},
            "finish_reason": "stop" if last else None,
        }],
    })

deltas = ["\n", "\n", "Here is the answer."]

completion = None
for i, d in enumerate(deltas):
    completion = provider.stream_merge_chunks(completion, chunk(d, last=i == len(deltas) - 1))
turn = provider.stream_turn(completion, has_data_model=False)

print("streamed:", repr("".join(deltas)))
print("turn:    ", repr(turn.text))
streamed: '\n\nHere is the answer.'
turn:     '\nHere is the answer.'

I expected both to be '\n\nHere is the answer.'.

It is not just the first two deltas. ["ab", "c", "abc"] streams abcabc and records abc, while ["ab", "c", "ab"] comes out fine, so it seems to bite when the new delta equals the whole accumulation so far.

chatlas at 7b3aa569, openai 3.13.0, python 3.12.14. Everything built on OpenAICompletionsProvider shares that call, so ChatOllama(), ChatGroq(), ChatDeepSeek() and ChatOpenRouter() are in the same boat. I found it driving the provider rather than a live model, so I cannot say how often a real stream lands on it.

Ngôn ngữ chính
Python
Star
179
Fork
32
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
10

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/chatlas

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

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.