Skip to content

Commit 58f5f40

Browse files
authored
Merge pull request #1094 from guardrails-ai/fix/streaming-index-and-log-issue
Fix/streaming index and log issue
2 parents 53db435 + 7cb50a9 commit 58f5f40

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

guardrails/classes/history/iteration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def completion_tokens_consumed(self) -> Optional[int]:
9898
def raw_output(self) -> Optional[str]:
9999
"""The exact output from the LLM."""
100100
response = self.outputs.llm_response_info
101-
if response is not None:
101+
if response is not None and response.output:
102102
return response.output
103103
elif self.outputs.raw_output is not None:
104104
return self.outputs.raw_output

guardrails/merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def merge(
8888
advance = True
8989
composed_text.append(source_text)
9090
tempdiff = DIFFER.diff_main(target_text, source_text)
91-
_, invariant = tempdiff[1]
91+
_, invariant = tempdiff[1] if len(tempdiff) > 1 else tempdiff[0]
9292
# _, (_, invariant) = DIFFER.diff_main(source_text, target_text)
9393
prev_source_text = source[1]
9494
source = next(diff1, None) # type: ignore

tests/unit_tests/test_merge.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@
3333
],
3434
"""<PERSON> is funny and lives in <LOCATION>""",
3535
),
36-
# broken!
37-
# (
38-
# """JOHN lives IN SAN francisco""",
39-
# [
40-
# """<PERSON> lives in <LOCATION>""",
41-
# """john lives in san francisco""",
42-
# ],
43-
# """<PERSON> lives in <LOCATION>""",
44-
# )
45-
# (broken) test behavior with a word close to PERSON
46-
# ("""Perry is FUNNY and LIVES in NEW york""",
47-
# ["""<PERSON> is FUNNY and lives in <LOCATION>""",
48-
# """perry is funny and lives in new york"""],
49-
# """<PERSON> is funny and lives in <LOCATION>"""),
36+
(
37+
"""JOHN lives IN SAN francisco""",
38+
[
39+
"""<PERSON> lives in <LOCATION>""",
40+
"""john lives in san francisco""",
41+
],
42+
"""<PERSON> lives in <LOCATION>""",
43+
),
44+
# (broken) test behavior with a word close to PERSON - seems to work!?
45+
(
46+
"""Parson is FUNNY and LIVES in NEW york""",
47+
[
48+
"""<PERSON> is FUNNY and lives in <LOCATION>""",
49+
"""parson is funny and lives in new york""",
50+
],
51+
"""<PERSON> is funny and lives in <LOCATION>""",
52+
),
5053
],
5154
)
5255
def test_merge(original, new_values, expected):

0 commit comments

Comments
 (0)