Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 启用流式传输后Gemini Pro模型输出的结果可能会包含重复内容 #3703

Closed
3 tasks done
Kosette opened this issue Dec 29, 2023 · 8 comments
Closed
3 tasks done

Comments

@Kosette
Copy link
Contributor

Kosette commented Dec 29, 2023

请在下方中括号内输入 x 来表示你已经知晓相关内容。

  • 我确认已经在 常见问题 中搜索了此次反馈的问题,没有找到解答;
  • 我确认已经在 Issues 列表(包括已经 Close 的)中搜索了此次反馈的问题,没有找到解答。
  • 我确认已经在 Vercel 使用教程 中搜索了此次反馈的问题,没有找到解答。

描述问题
在启用了对Gemini Pro流式传输的支持后(#3688) ,Gemini的回答有一定几率出现重复内容,比对请求的返回结果可以发现,有一部分内容丢失了,有一部分发生了重复。

请求的返回结果:

[{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "**Single Quotes (')**\n\n* Used for enclosing character values (e."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ],
  "promptFeedback": {
    "safetyRatings": [
      {
        "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HATE_SPEECH",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HARASSMENT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
        "probability": "NEGLIGIBLE"
      }
    ]
  }
}
,
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "g., 'a', '1', '$')\n* Used for defining single-line strings (e.g., 'Hello, world!')\n* Can"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ]
}
,
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": " be used inside double-quoted strings without escaping (e.g., \"He said, 'Hello, world!'\")\n\n**Double Quotes (\")**\n\n* Used for enclosing string values (e.g., \"Hello, world!\", \"123 Main Street\")\n* Used for defining multi-line strings"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ]
}
,
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": " (e.g., \"\"\"This is a multi-line string.\nIt can span multiple lines.\n\"\"\")\n* Can be used inside single-quoted strings without escaping (e.g., 'He said, \"Hello, world!\"')\n\n**Summary Table**\n\n| Feature | Single Quotes (') | Double Quotes (\") |\n|---|---|---|\n| Enclosing character values | Yes | No |\n| Defining single-line strings | Yes | Yes |\n| Defining multi-line strings | No | Yes |\n| Can be used inside other quotes without escaping | Yes | Yes |\n\n**Additional Notes**"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ]
}
,
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "\n\n* In some programming languages, such as Python, single quotes are used for defining strings that contain apostrophes ('), while double quotes are used for strings that contain double quotes (\"). This helps to avoid having to escape the quotes within the string.\n* In some programming languages, such as C++, single quotes are used for defining character constants, while double quotes are used for defining string constants.\n* In some programming languages, such as JavaScript, single quotes and double quotes are interchangeable for defining strings."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ]
}
]

截图
双子星

如何复现
使用Gemini pro询问一个可能回复较长的问题。有一定几率出现。

一些必要的信息

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: [Bug] After enabling streaming, the output results of the Gemini Pro model may contain duplicate content.

@H0llyW00dzZ
Copy link
Contributor

H0llyW00dzZ commented Dec 29, 2023

to be honest it's not perfect using json decoder for streaming
just wait google ai update support text-stream then can use fetch stream like a gpt by @Yidadaa
because right now it's not supported when using fetch stream for text stream (it's keep receive response a json)

@czjdr
Copy link

czjdr commented Dec 30, 2023

我也同样遇到这个问题,基本上每次都会重复

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I also encounter this problem, it basically repeats every time

@zhangbinhui
Copy link

不是可能,是每次都重复:
1703950873129.png

另外,我补充一个 bug,关于环境变量。

GOOGLE_URL=https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent

GOOGLE_API_KEY=AIzaSyAbrXo18...

如果这么设置,无法正常使用,报 404 错误。
必须不设置 GOOGLE_URL,只填GOOGLE_API_KEY 才能正常用。关键我看了默认 url 就是我设置的这个,我认为这也是一个 bug。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


It's not possible, it's repeated every time:
1703950873129.png

In addition, I will add a bug regarding environment variables.

GOOGLE_URL=https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent

GOOGLE_API_KEY=AIzaSyAbrXo18...

If set like this, it cannot be used normally and a 404 error will be reported.
GOOGLE_URL must not be set, only GOOGLE_API_KEY must be filled in for normal use. The key is that I looked at the default URL and it is the one I set. I think this is also a bug.

@chaoyuechen
Copy link

建议增加关闭流式的功能,这样等支持后再打开

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


It is recommended to add the function of turning off streaming so that it can be turned on again after support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants