mirror of
https://github.com/block/goose.git
synced 2026-04-28 03:29:36 +00:00
fix(providers): handle missing delta field in streaming chunks (#8700)
Signed-off-by: sunilkumarvalmiki <g.sunilkumarvalmiki@gmail.com> Co-authored-by: Lifei Zhou <lifei@squareup.com>
This commit is contained in:
parent
d18bb6e512
commit
03f4bfaa99
1 changed files with 19 additions and 1 deletions
|
|
@ -65,7 +65,7 @@ struct ContentPart {
|
|||
thought_signature: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||
struct Delta {
|
||||
#[serde(default)]
|
||||
content: Option<DeltaContent>,
|
||||
|
|
@ -89,6 +89,7 @@ impl Delta {
|
|||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct StreamingChoice {
|
||||
#[serde(default)]
|
||||
delta: Delta,
|
||||
index: Option<i32>,
|
||||
finish_reason: Option<String>,
|
||||
|
|
@ -2012,6 +2013,23 @@ data: [DONE]
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_azure_annotation_chunk_without_delta_does_not_fail() -> anyhow::Result<()> {
|
||||
let response_lines = r#"
|
||||
data: {"id":"chatcmpl-test","object":"chat.completion.chunk","created":1234567890,"model":"gpt-5.4","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null}],"usage":null}
|
||||
data: {"choices":[{"content_filter_offsets":{"check_offset":5,"start_offset":5,"end_offset":5},"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"finish_reason":null,"index":0}],"created":0,"id":"","model":"","object":""}
|
||||
data: {"id":"chatcmpl-test","object":"chat.completion.chunk","created":1234567891,"model":"gpt-5.4","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":10,"completion_tokens":1,"total_tokens":11}}
|
||||
data: [DONE]
|
||||
"#;
|
||||
|
||||
let result = run_streaming_test(response_lines).await?;
|
||||
|
||||
assert!(result.has_text_content, "Expected text content in response");
|
||||
assert_usage_yielded_once(&result, 10, 1, 11);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_to_message_with_nested_extra_content() -> anyhow::Result<()> {
|
||||
let response = json!({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue