Skip to content

Commit 369d7d4

Browse files
committed
final touches based on greptile reviews
1 parent fe74e22 commit 369d7d4

4 files changed

Lines changed: 15 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ scratch.py
6969

7070
.env
7171

72-
# Ignoring congfiguration files generated by chainlit
72+
# Ignoring configuration files generated by chainlit
7373
.chainlit/*

nemoguardrails/cli/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ def server(
153153
try:
154154
import uvicorn
155155
from fastapi import FastAPI
156+
157+
from nemoguardrails.server import api
156158
except ImportError:
157159
typer.secho(
158160
"Server dependencies are missing. Install them with: pip install nemoguardrails[server]",
159161
fg=typer.colors.RED,
160162
)
161163
raise typer.Exit(1)
162164

163-
from nemoguardrails.server import api
164-
165165
if config:
166166
# We make sure there is no trailing separator, as that might break things in
167167
# single config mode.

nemoguardrails/server/api.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ async def get_rails_configs():
208208
if os.path.isdir(os.path.join(app.rails_config_path, f))
209209
and f[0] != "."
210210
and f[0] != "_"
211-
# We filter out all the configs for which there is no `config.yml` file.
212-
and (
213-
os.path.exists(os.path.join(app.rails_config_path, f, "config.yml"))
214-
or os.path.exists(os.path.join(app.rails_config_path, f, "config.yaml"))
215-
)
211+
and _has_config_file(os.path.join(app.rails_config_path, f))
216212
]
217213

218214
return [{"id": config_id} for config_id in config_ids]
@@ -258,6 +254,16 @@ async def list_models(request: Request):
258254
llm_rails_events_history_cache: dict[str, dict] = {}
259255

260256

257+
def _has_config_file(path: str) -> bool:
258+
"""Check if a directory (or its 'config' subdirectory) contains a config.yml/yaml."""
259+
for candidate in [path, os.path.join(path, "config")]:
260+
if os.path.exists(os.path.join(candidate, "config.yml")) or os.path.exists(
261+
os.path.join(candidate, "config.yaml")
262+
):
263+
return True
264+
return False
265+
266+
261267
def _generate_cache_key(config_ids: List[str], model_name: Optional[str] = None) -> str:
262268
"""Generates a cache key for the given config ids and model name."""
263269
key = "-".join(config_ids)

nemoguardrails/server/app.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import chainlit as cl
2323

2424
from nemoguardrails.exceptions import StreamingNotSupportedError
25-
from nemoguardrails.server.api import _get_rails, app, challenges
25+
from nemoguardrails.server.api import _get_rails, _has_config_file, app, challenges
2626

2727
log = logging.getLogger(__name__)
2828

@@ -43,16 +43,6 @@ async def set_starters(user: Optional[cl.User] = None) -> List[cl.Starter]:
4343
]
4444

4545

46-
def _has_config_file(path: str) -> bool:
47-
"""Check if a directory (or its 'config' subdirectory) contains a config.yml/yaml."""
48-
for candidate in [path, os.path.join(path, "config")]:
49-
if os.path.exists(os.path.join(candidate, "config.yml")) or os.path.exists(
50-
os.path.join(candidate, "config.yaml")
51-
):
52-
return True
53-
return False
54-
55-
5646
def _discover_configs() -> List[str]:
5747
"""Return the list of available guardrails configuration IDs."""
5848
if app.single_config_mode and app.single_config_id:

0 commit comments

Comments
 (0)