DeepSeek-R1/tests/test_model.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

39 lines
1.6 KiB
Python

import unittest
from src.model import Model
class TestModel(unittest.TestCase):
def setUp(self):
self.model = Model()
def test_generate_structured_output_json(self):
prompt = "Extract the following data as JSON: {\"name\": \"John\", \"age\": 30}"
result = self.model.generate_structured_output(prompt, format="json")
self.assertIsInstance(result, dict)
self.assertEqual(result["name"], "John")
self.assertEqual(result["age"], 30)
def test_generate_structured_output_xml(self):
prompt = "Extract the following data as XML: <person><name>John</name><age>30</age></person>"
result = self.model.generate_structured_output(prompt, format="xml")
self.assertIsInstance(result, ET.Element)
self.assertEqual(result.find("name").text, "John")
self.assertEqual(result.find("age").text, "30")
def test_call_function(self):
function_name = "add"
args = {"a": 5, "b": 3}
result = self.model.call_function(function_name, args)
self.assertIsInstance(result, str) # Assuming the result is a string
self.assertIn("result", result) # Assuming the result contains the word "result"
def test_integrate_with_api(self):
api_endpoint = "https://api.example.com/endpoint"
data = {"key": "value"}
result = self.model.integrate_with_api(api_endpoint, data)
self.assertIsInstance(result, dict)
self.assertIn("response", result) # Assuming the API response contains the key "response"
if __name__ == "__main__":
unittest.main()