Skip to content

Commit

Permalink
Merge pull request #2 from robusta-dev/feature/api-server-context-typing
Browse files Browse the repository at this point in the history
Stricter typing for API server requests
  • Loading branch information
Robert Szefler authored Jun 3, 2024
2 parents da0a36f + 383d393 commit 45fd7f8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
from collections.abc import Iterable
from typing import List, Optional
from uuid import uuid4
from typing import List, Union

from fastapi import FastAPI
from pydantic import BaseModel
Expand All @@ -13,12 +11,17 @@
from holmes.plugins.prompts import load_prompt


class InvestigateContext(BaseModel):
type: str
value: Union[str, dict]


class InvestigateRequest(BaseModel):
source: str # "prometheus" etc
title: str
description: str
subject: dict
context: List[dict]
context: List[InvestigateContext]
source_instance_id: str
# TODO in the future
# response_handler: ...
Expand All @@ -33,12 +36,12 @@ class InvestigateRequest(BaseModel):
app = FastAPI()


def fetch_context_data(context: List[dict]) -> dict:
def fetch_context_data(context: List[InvestigateContext]) -> dict:
for context_item in context:
if context_item.get("type") == "robusta_issue_id":
if context_item.type == "robusta_issue_id":
# Note we only accept a single robusta_issue_id. I don't think it
# makes sense to have several of them in the context structure.
return dal.get_issue_data(context_item.get("value"))
return dal.get_issue_data(context_item.value)


@app.post("/api/investigate")
Expand All @@ -50,7 +53,7 @@ def investigate_issues(request: InvestigateRequest):
model='gpt-4o'
)
context = fetch_context_data(request.context)
raw_data = request.dict()
raw_data = request.model_dump()
if context:
raw_data["extra_context"] = context
# TODO allowed_toolsets should probably be configurable?
Expand Down

0 comments on commit 45fd7f8

Please sign in to comment.