Skip to content

Commit e769d23

Browse files
committed
add option to stream holmes chat function
1 parent 3e8d9da commit e769d23

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/robusta/core/model/base_params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum, auto
33
from typing import Any, Dict, List, Optional, Union
44

5-
from pydantic import BaseModel, SecretStr, validator
5+
from pydantic import BaseModel, SecretStr, validator, Field
66

77
from robusta.integrations import openshift
88
from robusta.utils.documented_pydantic import DocumentedModel
@@ -190,6 +190,7 @@ class HolmesChatParams(HolmesParams):
190190
ask: str
191191
conversation_history: Optional[list[dict]] = None
192192
render_graph_images: bool = False
193+
stream: bool = Field(default=False)
193194

194195

195196
class HolmesIssueChatParams(HolmesChatParams):
@@ -251,7 +252,6 @@ class HolmesWorkloadHealthChatParams(HolmesParams):
251252
conversation_history: Optional[list[dict]] = None
252253

253254

254-
255255
class NamespacedResourcesParams(ActionParams):
256256
"""
257257
:var name: Resource name

src/robusta/core/playbooks/internal/ai_integration.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,24 @@ def holmes_chat(event: ExecutionBaseEvent, params: HolmesChatParams):
351351
cluster_name = event.get_context().cluster_name
352352

353353
try:
354-
holmes_req = HolmesChatRequest(ask=params.ask, conversation_history=params.conversation_history, model=params.model)
355-
result = requests.post(f"{holmes_url}/api/chat", data=holmes_req.json())
354+
holmes_req = HolmesChatRequest(ask=params.ask, conversation_history=params.conversation_history, model=params.model, stream=params.stream)
355+
url = f"{holmes_url}/api/chat"
356+
if params.stream:
357+
with requests.post(
358+
url,
359+
data=holmes_req.json(),
360+
stream=True,
361+
headers={"Connection": "keep-alive"},
362+
) as resp:
363+
resp.raise_for_status()
364+
for line in resp.iter_content(
365+
chunk_size=None, decode_unicode=True
366+
): # Avoid streaming chunks from holmes. send them as they arrive.
367+
if line:
368+
event.ws(data=line)
369+
return
370+
371+
result = requests.post(url, data=holmes_req.json())
356372
result.raise_for_status()
357373
holmes_result = HolmesChatResult(**json.loads(result.text))
358374
holmes_result.files = []

src/robusta/core/reporting/holmes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Optional, Union
22

3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, Field
44

55
from robusta.core.model.base_params import (
66
ConversationType,
@@ -38,6 +38,7 @@ class HolmesChatRequest(BaseModel):
3838
ask: str
3939
conversation_history: Optional[List[dict]] = None
4040
model: Optional[str] = None
41+
stream: bool = Field(default=False)
4142

4243

4344
class HolmesIssueChatRequest(HolmesChatRequest):

0 commit comments

Comments
 (0)