Skip to content

Commit c196f64

Browse files
committed
Add patterns as list of strings. now we can use streaming logs i.e. `parlant log "Revisions" "Evaluation"
1 parent 4c69e7d commit c196f64

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

src/parlant/bin/client.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from rich.text import Text
3030
import sys
3131
import time
32-
from typing import Any, Iterator, Optional, cast
32+
from typing import Any, Iterator, Optional, Sequence, cast
3333

3434
from parlant.client import ParlantClient
3535
from parlant.client.core import ApiError
@@ -848,9 +848,7 @@ def delete_tag(ctx: click.Context, tag_id: str) -> None:
848848
client.tags.delete(tag_id=tag_id)
849849

850850
@staticmethod
851-
def stream_logs(
852-
ctx: click.Context, filters: list[str], operator: str
853-
) -> Iterator[dict[str, Any]]:
851+
def stream_logs(ctx: click.Context, filters: list[str]) -> Iterator[dict[str, Any]]:
854852
try:
855853
context = zmq.Context.instance()
856854
sub_socket = context.socket(zmq.SUB)
@@ -863,7 +861,7 @@ def stream_logs(
863861
while True:
864862
try:
865863
message = cast(dict[str, Any], sub_socket.recv_json(flags=zmq.NOBLOCK))
866-
if Actions._log_matches_filters(message, filters, operator):
864+
if Actions._log_matches_filters(message, filters):
867865
yield message
868866
except zmq.Again:
869867
time.sleep(0.01)
@@ -873,19 +871,14 @@ def stream_logs(
873871
sub_socket.close()
874872

875873
@staticmethod
876-
def _log_matches_filters(log_entry: dict[str, Any], filters: list[str], operator: str) -> bool:
874+
def _log_matches_filters(log_entry: dict[str, Any], filters: list[str]) -> bool:
877875
message = log_entry.get("message", "")
878876
matches_filters = []
879877

880878
for filter_item in filters:
881879
matches_filters.append(filter_item in message)
882880

883-
if operator == "AND":
884-
filter_match = all(matches_filters)
885-
else:
886-
filter_match = any(matches_filters)
887-
888-
return filter_match
881+
return any(matches_filters) if matches_filters else True
889882

890883

891884
def raise_for_status_with_detail(response: requests.Response) -> None:
@@ -2011,10 +2004,9 @@ def delete_tag(ctx: click.Context, tag_id: str) -> None:
20112004
def stream_logs(
20122005
ctx: click.Context,
20132006
filters: list[str],
2014-
operator: str,
20152007
) -> None:
20162008
try:
2017-
for log in Actions.stream_logs(ctx, filters, operator):
2009+
for log in Actions.stream_logs(ctx, filters):
20182010
level = log.get("level", "")
20192011
message = log.get("message", "")
20202012
correlation_id = log.get("correlation_id", "")
@@ -3120,23 +3112,14 @@ def tag_delete(ctx: click.Context, id: str) -> None:
31203112
is_flag=True,
31213113
help="Filter logs by [MessageEventGenerator]",
31223114
)
3123-
@click.option(
3124-
"--operator",
3125-
"-o",
3126-
type=click.Choice(["AND", "OR"], case_sensitive=False),
3127-
default="OR",
3128-
show_default=True,
3129-
help="Logical operator to combine filters",
3130-
)
3131-
@click.argument("pattern", required=False)
3115+
@click.argument("patterns", nargs=-1, required=False)
31323116
@click.pass_context
31333117
def log_view(
31343118
ctx: click.Context,
31353119
guideline_proposer: bool,
31363120
tool_caller: bool,
31373121
message_event_generator: bool,
3138-
operator: str,
3139-
pattern: Optional[str],
3122+
patterns: Optional[Sequence[str]],
31403123
) -> None:
31413124
filters = []
31423125
if guideline_proposer:
@@ -3145,10 +3128,10 @@ def log_view(
31453128
filters.append("[ToolCaller]")
31463129
if message_event_generator:
31473130
filters.append("[MessageEventGenerator]")
3148-
if pattern:
3149-
filters.append(pattern)
3131+
if patterns:
3132+
filters.extend(patterns)
31503133

3151-
Interface.stream_logs(ctx, filters, operator)
3134+
Interface.stream_logs(ctx, filters)
31523135

31533136
@cli.command(
31543137
"help",

src/parlant/core/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __init__(
189189
correlator: ContextualCorrelator,
190190
log_level: LogLevel = LogLevel.DEBUG,
191191
logger_id: Optional[str] = None,
192-
port: int = 8779,
192+
port: int = 8799,
193193
) -> None:
194194
super().__init__(correlator, log_level, logger_id)
195195

0 commit comments

Comments
 (0)