DeepSeek-R1/tests/test_utils.py
Jason Kneen 449333db91 Add function calling and structured outputs support
Fixes #9

Add support for function calling and structured outputs.

* **README.md**
  - Add a section about function calling and structured outputs.
  - Include examples of using function calling and structured outputs.
  - Mention the future plans for these features.

* **src/model.py**
  - Add support for structured data formats like JSON and XML.
  - Implement function calling capabilities.
  - Include integration with external tools and APIs.

* **src/utils.py**
  - Add utility functions for parsing and generating structured data formats.
  - Include helper functions for function calling.

* **tests/test_model.py**
  - Add unit tests for structured data format support.
  - Include tests for function calling capabilities.
  - Add tests for API integration.

* **tests/test_utils.py**
  - Add unit tests for utility functions related to structured data formats.
  - Include tests for helper functions for function calling.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/deepseek-ai/DeepSeek-R1/issues/9?shareId=XXXX-XXXX-XXXX-XXXX).
2025-01-22 16:11:46 +00:00

47 lines
1.6 KiB
Python

import unittest
from src.utils import parse_json, parse_xml, generate_json, generate_xml, call_function
from src.model import Model
class TestUtils(unittest.TestCase):
def setUp(self):
self.model = Model()
def test_parse_json(self):
response = '{"name": "John", "age": 30}'
result = parse_json(response)
self.assertIsInstance(result, dict)
self.assertEqual(result["name"], "John")
self.assertEqual(result["age"], 30)
def test_parse_xml(self):
response = "<person><name>John</name><age>30</age></person>"
result = parse_xml(response)
self.assertIsInstance(result, ET.Element)
self.assertEqual(result.find("name").text, "John")
self.assertEqual(result.find("age").text, "30")
def test_generate_json(self):
data = {"name": "John", "age": 30}
result = generate_json(data)
self.assertIsInstance(result, str)
self.assertIn('"name": "John"', result)
self.assertIn('"age": 30', result)
def test_generate_xml(self):
data = {"name": "John", "age": 30}
result = generate_xml(data)
self.assertIsInstance(result, str)
self.assertIn("<name>John</name>", result)
self.assertIn("<age>30</age>", result)
def test_call_function(self):
function_name = "add"
args = {"a": 5, "b": 3}
result = call_function(self.model, function_name, args)
self.assertIsInstance(result, str) # Assuming the result is a string
self.assertIn("result", result) # Assuming the result contains the word "result"
if __name__ == "__main__":
unittest.main()