Calcium-Ion / new-api

AI模型接口管理与分发系统,支持将多种大模型转为OpenAI格式调用、支持Midjourney Proxy、Suno、Rerank,兼容易支付协议,仅供个人或者企业内部管理与分发渠道使用,请勿用于商业用途,本项目基于One API二次开发。
https://nekoapi.com
Apache License 2.0
3.44k stars 813 forks source link

Gemini流式返回能否去除中间字段的"finish_reason":"stop" #378

Closed utopeadia closed 3 months ago

utopeadia commented 3 months ago

相似问题:隔壁oneapi的讨论:https://github.com/songquanpeng/one-api/issues/1408 gemini的流式返回包含大量"finish_reason":"stop",软件适配过程直接使用oneapi兼容接入可能会把finish_reason作为判断依据之一,希望能够将除了data: [DONE]最近的"finish_reason":"stop"之外的中间输出此字段删除。

data: {
    "id": "chatcmpl-00b12909dea748258b3bf38c9d2e7340",
    "object": "chat.completion.chunk",
    "created": 1721379147,
    "model": "gemini",
    "system_fingerprint": null,
    "choices": [
        {
            "delta": {
                "content": "你好"
            },
            "logprobs": null,
            "finish_reason": "stop",
            "index": 0
        }
    ],
    "usage": null
}
data: {
    "id": "chatcmpl-00b12909dea748258b3bf38c9d2e7340",
    "object": "chat.completion.chunk",
    "created": 1721379147,
    "model": "gemini",
    "system_fingerprint": null,
    "choices": [
        {
            "delta": {
                "content": "!很高兴认识你。请问有什么关于计算机科学或人工智能方面的问题需要"
            },
            "logprobs": null,
            "finish_reason": "stop",
            "index": 0
        }
    ],
    "usage": null
}
data: {
    "id": "chatcmpl-00b12909dea748258b3bf38c9d2e7340",
    "object": "chat.completion.chunk",
    "created": 1721379147,
    "model": "gemini",
    "system_fingerprint": null,
    "choices": [
        {
            "delta": {
                "content": "我解答吗?我会尽力提供准确、详细和深入的答案。"
            },
            "logprobs": null,
            "finish_reason": "stop",
            "index": 0
        }
    ],
    "usage": null
}
data: {
    "id": "chatcmpl-00b12909dea748258b3bf38c9d2e7340",
    "object": "chat.completion.chunk",
    "created": 1721379147,
    "model": "gemini",
    "system_fingerprint": null,
    "choices": [
        {
            "delta": {
                "content": " 😊 \n"
            },
            "logprobs": null,
            "finish_reason": "stop",
            "index": 0
        }
    ],
    "usage": null
}
data: {
    "id": "chatcmpl-00b12909dea748258b3bf38c9d2e7340",
    "object": "chat.completion.chunk",
    "created": 1721379147,
    "model": "gemini-1.5-pro-latest",
    "system_fingerprint": null,
    "choices": [],
    "usage": {
        "prompt_tokens": 43,
        "completion_tokens": 34,
        "total_tokens": 77
    }
}
data: [DONE]
Calcium-Ion commented 3 months ago

这两天被gemini气到没脾气了

utopeadia commented 3 months ago

这两天被gemini气到没脾气了

gemini整的一手好活