Skip to content

Commit

Permalink
Merge pull request #1094 from guardrails-ai/fix/streaming-index-and-l…
Browse files Browse the repository at this point in the history
…og-issue

Fix/streaming index and log issue
  • Loading branch information
dtam authored Sep 30, 2024
2 parents 53db435 + 7cb50a9 commit 58f5f40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion guardrails/classes/history/iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def completion_tokens_consumed(self) -> Optional[int]:
def raw_output(self) -> Optional[str]:
"""The exact output from the LLM."""
response = self.outputs.llm_response_info
if response is not None:
if response is not None and response.output:
return response.output
elif self.outputs.raw_output is not None:
return self.outputs.raw_output
Expand Down
2 changes: 1 addition & 1 deletion guardrails/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def merge(
advance = True
composed_text.append(source_text)
tempdiff = DIFFER.diff_main(target_text, source_text)
_, invariant = tempdiff[1]
_, invariant = tempdiff[1] if len(tempdiff) > 1 else tempdiff[0]
# _, (_, invariant) = DIFFER.diff_main(source_text, target_text)
prev_source_text = source[1]
source = next(diff1, None) # type: ignore
Expand Down
31 changes: 17 additions & 14 deletions tests/unit_tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,23 @@
],
"""<PERSON> is funny and lives in <LOCATION>""",
),
# broken!
# (
# """JOHN lives IN SAN francisco""",
# [
# """<PERSON> lives in <LOCATION>""",
# """john lives in san francisco""",
# ],
# """<PERSON> lives in <LOCATION>""",
# )
# (broken) test behavior with a word close to PERSON
# ("""Perry is FUNNY and LIVES in NEW york""",
# ["""<PERSON> is FUNNY and lives in <LOCATION>""",
# """perry is funny and lives in new york"""],
# """<PERSON> is funny and lives in <LOCATION>"""),
(
"""JOHN lives IN SAN francisco""",
[
"""<PERSON> lives in <LOCATION>""",
"""john lives in san francisco""",
],
"""<PERSON> lives in <LOCATION>""",
),
# (broken) test behavior with a word close to PERSON - seems to work!?
(
"""Parson is FUNNY and LIVES in NEW york""",
[
"""<PERSON> is FUNNY and lives in <LOCATION>""",
"""parson is funny and lives in new york""",
],
"""<PERSON> is funny and lives in <LOCATION>""",
),
],
)
def test_merge(original, new_values, expected):
Expand Down

0 comments on commit 58f5f40

Please sign in to comment.