elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.67k stars 8.23k forks source link

[Security solution] Fix gemini streaming #201299

Closed stephmilovic closed 2 days ago

stephmilovic commented 3 days ago

Summary

Fixes streaming for Gemini in Security Assistant.

Content can appear in the finishReason block. I'm not sure when this started happening. Updates our streaming logic to support content being in the finishReason block.

Example of finishReason block with content:

`data: {"candidates": [{"content": {"role": "model","parts": [{"text": " are 170 critical and 20 high open alerts."}]},"finishReason": "STOP","safetyRatings": [{"category": "HARM_CATEGORY_HATE_SPEECH","probability": "NEGLIGIBLE","probabilityScore": 0.060086742,"severity": "HARM_SEVERITY_NEGLIGIBLE","severityScore": 0.17106095},{"category": "HARM_CATEGORY_DANGEROUS_CONTENT","probability": "NEGLIGIBLE","probabilityScore": 0.16776322,"severity": "HARM_SEVERITY_LOW","severityScore": 0.37113687},{"category": "HARM_CATEGORY_HARASSMENT","probability": "NEGLIGIBLE","probabilityScore": 0.124212936,"severity": "HARM_SEVERITY_NEGLIGIBLE","severityScore": 0.17441037},{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT","probability": "NEGLIGIBLE","probabilityScore": 0.05419875,"severity": "HARM_SEVERITY_NEGLIGIBLE","severityScore": 0.03461887}]}],"usageMetadata": {"promptTokenCount": 1062,"candidatesTokenCount": 15,"totalTokenCount": 1077},"modelVersion": "gemini-1.5-pro-002"}`

To test

  1. Have alerts
  2. Have a Gemini connector (gemini-1.5-pro-002)
  3. Have streaming on in the assistant with the Gemini connector selected
  4. Ask the assistant: "How many open alerts do I have?"

Previously

A response begin to streams and then the response gets cut off.

Screenshot 2024-11-21 at 4 18 06 PM

Now

The response streams in full as expected.

Screenshot 2024-11-21 at 4 25 13 PM
elasticmachine commented 3 days ago

Pinging @elastic/security-solution (Team: SecuritySolution)

stephmilovic commented 3 days ago

@elasticmachine merge upstream

elasticmachine commented 3 days ago

:yellow_heart: Build succeeded, but was flaky

Failed CI Steps

Test Failures

Metrics [docs]

✅ unchanged

kibanamachine commented 2 days ago

Starting backport for target branches: 8.15, 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/11972946849

kibanamachine commented 2 days ago

💔 Some backports could not be created

Status Branch Result
8.15 Backport failed because of merge conflicts
8.16
8.17
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 201299

Questions ?

Please refer to the Backport tool documentation