You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_utils.py 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import pytest
  2. from autogen_ext.models._utils.parse_r1_content import parse_r1_content
  3. def test_parse_r1_content() -> None:
  4. content = "Hello, <think>world</think> How are you?"
  5. thought, content = parse_r1_content(content)
  6. assert thought == "world"
  7. assert content == "How are you?"
  8. with pytest.warns(
  9. UserWarning,
  10. match="Could not find <think>..</think> field in model response content. " "No thought was extracted.",
  11. ):
  12. content = "Hello, world How are you?"
  13. thought, content = parse_r1_content(content)
  14. assert thought is None
  15. assert content == "Hello, world How are you?"
  16. with pytest.warns(
  17. UserWarning,
  18. match="Could not find <think>..</think> field in model response content. " "No thought was extracted.",
  19. ):
  20. content = "Hello, <think>world How are you?"
  21. thought, content = parse_r1_content(content)
  22. assert thought is None
  23. assert content == "Hello, <think>world How are you?"
  24. with pytest.warns(
  25. UserWarning, match="Found </think> before <think> in model response content. " "No thought was extracted."
  26. ):
  27. content = "</think>Hello, <think>world</think>"
  28. thought, content = parse_r1_content(content)
  29. assert thought is None
  30. assert content == "</think>Hello, <think>world</think>"
  31. with pytest.warns(
  32. UserWarning, match="Found </think> before <think> in model response content. " "No thought was extracted."
  33. ):
  34. content = "</think>Hello, <think>world"
  35. thought, content = parse_r1_content(content)
  36. assert thought is None
  37. assert content == "</think>Hello, <think>world"