Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ repos:
args:
- --license-filepath
- LICENSE.md

- repo: local
hooks:
- id: pyright
name: pyright
entry: poetry run pyright
language: system
types: [python]
pass_filenames: false
# Deactivating this for now.
# - repo: https://github.com/pycqa/pylint
# rev: v2.17.0
Expand Down
2 changes: 1 addition & 1 deletion nemoguardrails/actions/llm/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def init(self):
self._init_flows_index(),
)

def _extract_user_message_example(self, flow: Flow):
def _extract_user_message_example(self, flow: Flow) -> None:
"""Heuristic to extract user message examples from a flow."""
elements = [
item
Expand Down
27 changes: 19 additions & 8 deletions nemoguardrails/actions_server/actions_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import logging
from typing import Dict, Optional

from fastapi import FastAPI
from fastapi import Depends, FastAPI
from pydantic import BaseModel, Field

from nemoguardrails.actions.action_dispatcher import ActionDispatcher
Expand All @@ -34,7 +34,12 @@


# Create action dispatcher object to communicate with actions
app.action_dispatcher = ActionDispatcher(load_all_actions=True)
_action_dispatcher = ActionDispatcher(load_all_actions=True)


def get_action_dispatcher() -> ActionDispatcher:
"""Dependency to provide the action dispatcher instance."""
return _action_dispatcher


class RequestBody(BaseModel):
Expand All @@ -58,30 +63,36 @@ class ResponseBody(BaseModel):
summary="Execute action",
response_model=ResponseBody,
)
async def run_action(body: RequestBody):
async def run_action(
body: RequestBody,
action_dispatcher: ActionDispatcher = Depends(get_action_dispatcher),
):
"""Execute the specified action and return the result.

Args:
body (RequestBody): The request body containing action_name and action_parameters.
action_dispatcher (ActionDispatcher): The action dispatcher dependency.

Returns:
dict: The response containing the execution status and result.
"""

log.info(f"Request body: {body}")
result, status = await app.action_dispatcher.execute_action(
log.info("Request body: %s", body)
result, status = await action_dispatcher.execute_action(
body.action_name, body.action_parameters
)
resp = {"status": status, "result": result}
log.info(f"Response: {resp}")
log.info("Response: %s", resp)
return resp


@app.get(
"/v1/actions/list",
summary="List available actions",
)
async def get_actions_list():
async def get_actions_list(
action_dispatcher: ActionDispatcher = Depends(get_action_dispatcher),
):
"""Returns the list of available actions."""

return app.action_dispatcher.get_registered_actions()
return action_dispatcher.get_registered_actions()
22 changes: 21 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,13 @@ pytest-profiling = "^1.7.0"
yara-python = "^4.5.1"
opentelemetry-api = "^1.34.1"
opentelemetry-sdk = "^1.34.1"
pyright = "^1.1.405"


# Directories in which to run Pyright type-checking
[tool.pyright]
include = []

[tool.poetry.group.docs]
optional = true

Expand Down
Loading