Skip to content

Commit

Permalink
Merge pull request #12 from robusta-dev/feature/api-server-detailed-a…
Browse files Browse the repository at this point in the history
…nalysis-response

Add tool call info in API responses if requested
  • Loading branch information
Robert Szefler authored Jun 14, 2024
2 parents 8bdf8eb + 7eb03ad commit 4b3dd08
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 23 additions & 7 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ class InvestigateRequest(BaseModel):
subject: dict
context: List[InvestigateContext]
source_instance_id: str
include_tool_calls: bool = False
include_tool_call_results: bool = False
prompt_template: str = "builtin://generic_investigation.jinja2"
# TODO in the future
# response_handler: ...


def init_logging():
logging_level = os.environ.get("LOG_LEVEL", "INFO")
logging_format = "%(log_color)s%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s"
Expand Down Expand Up @@ -79,14 +83,26 @@ def investigate_issues(request: InvestigateRequest):
source_instance_id=request.source_instance_id,
raw=raw_data,
)
return {
"analysis": ai.investigate(
issue,
# TODO prompt should probably be configurable?
prompt=load_prompt("builtin://generic_investigation.jinja2"),
console=console
).result
investigation = ai.investigate(
issue,
# TODO prompt should probably be configurable?
prompt=load_prompt(request.prompt),
console=console,
)
ret = {
"analysis": investigation.result
}
if request.include_tool_calls:
ret["tool_calls"] = [
{
"tool_name": tool.tool_name,
"tool_call": tool.description,
} | (
{"call_result": tool.result} if request.include_tool_call_results else {}
)
for tool in investigation.tool_calls
]
return ret


def fetch_context_data(context: List[InvestigateContext]) -> dict:
Expand Down
4 changes: 3 additions & 1 deletion test-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ curl -XPOST 127.0.0.1:8000/api/investigate -H "Content-Type: application/json" -
\"type\": \"robusta_issue_id\",
\"value\": \"5b3e2fb1-cb83-45ea-82ec-318c94718e44\"
}
]
],
\"include_tool_calls\": true,
\"include_tool_call_results\": true
}"

0 comments on commit 4b3dd08

Please sign in to comment.