data: {"choices":[{"index":0,"delta":{"content":"","role":"assistant"}}]}
data: {"choices":[],"created":0,"id":"","prompt_filter_results":[{"content_filter_results":{"error":{"code":"","message":""},"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"prompt_index":0}]}
data: {"choices":[{"index":0,"content_filter_offsets":{"check_offset":479,"start_offset":479,"end_offset":482},"content_filter_results":{"error":{"code":"","message":""},"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":"","role":"assistant"}}],"created":1728829509,"id":"chatcmpl-AHtoruqQKpZydRFXYyQBmgx0VXKBN","model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d"}
data: {"choices":[{"index":0,"content_filter_offsets":{"check_offset":479,"start_offset":479,"end_offset":482},"content_filter_results":{"error":{"code":"","message":""},"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":"No"}}],"created":1728829509,"id":"chatcmpl-AHtoruqQKpZydRFXYyQBmgx0VXKBN","model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d"}
data: {"choices":[{"index":0,"content_filter_offsets":{"check_offset":479,"start_offset":479,"end_offset":482},"content_filter_results":{"error":{"code":"","message":""},"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":"."}}],"created":1728829509,"id":"chatcmpl-AHtoruqQKpZydRFXYyQBmgx0VXKBN","model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d"}
data: {"choices":[{"finish_reason":"stop","index":0,"content_filter_offsets":{"check_offset":479,"start_offset":479,"end_offset":482},"content_filter_results":{"error":{"code":"","message":""},"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":null}}],"created":1728829509,"id":"chatcmpl-AHtoruqQKpZydRFXYyQBmgx0VXKBN","usage":{"completion_tokens":2,"prompt_tokens":97,"total_tokens":99},"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d"}
data: [DONE]
data: {"choices":[{"index":0,"finish_reason":"stop","delta":{"content":null}}]}
data: [DONE]
When the response is streamed, under some conditions the agent response is attributed to copilot instead of the extension:
Note
This happens only on dotcom chat, VSCode always attributes the response to the agent
I haven't figured the root cause, but it seems related to the use of
createAckEventandcreateDoneEventin conjunction with streaming. This happens when using both built in SDK methods for prompt and using openai library against copilot endpoint.The resulting payload doesn't seem to be consistent either with streaming/non streaming (under some conditions
createDoneEventis redundant)I've included the four conditions, together with the response payloads (made them as small as possible).
I've used the following pattern:
The full source code used for the repro is included at the end of the issue (no concerns in making the code pretty :) )
Using Prompt method ✅
Payload
Using prompt method with streaming 🔴
Payload
Workaround: Don't send
createDoneEvent()Which basically removes the two last responses on the above payload (the streaming response already includeddata: [DONE])Using CAPI with no stream ✅
Payload
Using CAPI with streaming 🔴
Payload
Workaround don't send
createDoneEvent()even though the streaming response doesn't sends it explicitly, the client seems to be lenient (but probably not a good idea not to send it)Full Repro code
Dependencies
{ "@copilot-extensions/preview-sdk": "^5.0.0", "openai": "^4.67.1" }Source Code