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

オープン 初心者向け
#435 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@cpsievert がすでに取り組んでいます。

2026年9月14日 から。

  • #436 @cpsievert による — オープン
  • #471 @pcbeingused33 による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api

調査の方向性

提供された ChatCompletionChunk の再現を使用して、繰り返される delta がどのように蓄積および記録されるかを追跡しながら、OpenAICompletionsProvider.stream_merge_chunks と stream_turn から始めます。["\n", "\n", "Here is the answer."] とその他の例を対象とするリグレッションテストを追加し、記録された turn がストリーミングされた完全なテキストと一致することを確認します。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
179
フォーク
32
平均マージ
1日 3時間
マージ済み PR(30日)
10

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

posit-dev/chatlas のほかの issue

posit-dev/chatlas の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。