Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Response Resolver($.choices[0].delta.content)对SSE响应的最后一个消息处理不当导致日志里面一直在异常报错 #424

Copy link
Copy link
@minshiwu

Description

@minshiwu
Issue body actions

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
可以看到sse响应的最后一个消息里面没有content字段。这也是符合openai api规范的。

{
    "id": "chatcmpl-2c954dc0-0ba5-4015-8117-4fe22ff7cf04",
    "created": 1750421392,
    "model": "qwen2.5-72b",
    "object": "chat.completion.chunk",
    "choices": [{
            "finish_reason": "stop",
            "index": 0,
            "delta": {}
        }
    ]
}

Screenshots
日志里面的报错信息如下
2025-06-20 20:15:29,994 [ 499854] WARN - #cc.unitmesh.devti.llm2.LLMProvider2 - sse stream: {"id":"chatcmpl-d408e5e0-9294-40ce-af08-50915b45227d","created":1750421729,"model":"qwen2.5-72b","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" here","tool_calls":[]}}]}
2025-06-20 20:15:30,037 [ 499897] WARN - #cc.unitmesh.devti.llm2.LLMProvider2 - sse stream: {"id":"chatcmpl-d408e5e0-9294-40ce-af08-50915b45227d","created":1750421729,"model":"qwen2.5-72b","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" to","tool_calls":[]}}]}
2025-06-20 20:15:30,053 [ 499913] WARN - #cc.unitmesh.devti.llm2.LLMProvider2 - sse stream: {"id":"chatcmpl-d408e5e0-9294-40ce-af08-50915b45227d","created":1750421729,"model":"qwen2.5-72b","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" help","tool_calls":[]}}]}
2025-06-20 20:15:30,092 [ 499952] WARN - #cc.unitmesh.devti.llm2.LLMProvider2 - sse stream: {"id":"chatcmpl-d408e5e0-9294-40ce-af08-50915b45227d","created":1750421730,"model":"qwen2.5-72b","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!","tool_calls":[]}}]}
2025-06-20 20:15:30,109 [ 499969] WARN - #cc.unitmesh.devti.llm2.LLMProvider2 - sse stream: {"id":"chatcmpl-d408e5e0-9294-40ce-af08-50915b45227d","created":1750421730,"model":"qwen2.5-72b","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"","role":"assistant","tool_calls":[]}}]}
2025-06-20 20:15:30,161 [ 500021] WARN - #cc.unitmesh.devti.llm2.LLMProvider2 - sse stream: {"id":"chatcmpl-d408e5e0-9294-40ce-af08-50915b45227d","created":1750421730,"model":"qwen2.5-72b","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}
2025-06-20 20:15:30,161 [ 500021] WARN - #cc.unitmesh.devti.llm2.LLMProvider2 - cannot parse with responseResolver: $.choices[0].delta.content, ori data: {"id":"chatcmpl-d408e5e0-9294-40ce-af08-50915b45227d","created":1750421730,"model":"qwen2.5-72b","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}
java.lang.IllegalStateException: cannot parse with responseResolver: $.choices[0].delta.content, ori data: {"id":"chatcmpl-d408e5e0-9294-40ce-af08-50915b45227d","created":1750421730,"model":"qwen2.5-72b","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}
at cc.unitmesh.devti.llm2.LLMProvider2$sseStream$eventSource$1.onEvent(LLMProvider2.kt:99)
at okhttp3.internal.sse.RealEventSource.onEvent(RealEventSource.kt:101)
at okhttp3.internal.sse.ServerSentEventReader.completeEvent(ServerSentEventReader.kt:108)
at okhttp3.internal.sse.ServerSentEventReader.processNextEvent(ServerSentEventReader.kt:52)
at okhttp3.internal.sse.RealEventSource.processResponse(RealEventSource.kt:75)
at okhttp3.internal.sse.RealEventSource.onResponse(RealEventSource.kt:46)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)

Desktop (please complete the following information):

  • OS: [e.g. Windows] win11
  • Main Version [e.g. 22]
  • IDEA Version [e.g. Intellij IDEA 2024.3] idea2024.3

Additional context
当前代码这里的处理,没有考虑sse最后一个消息finish_reason不为空的时候的特殊情况。

                val chunk: String = runCatching {
                    val result: String? = JsonPath.parse(data)?.read(responseResolver)
                    result ?: ""
                }.getOrElse {
                    logger.warn(IllegalStateException("cannot parse with responseResolver: ${responseResolver}, ori data: $data"))
                    ""
                }

                result += chunk

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.