yaleh commited on
Commit
b7f160b
·
1 Parent(s): 675dd1e

Implemented test_simple_workflow_execution() with mockup llm.

Browse files
Files changed (1) hide show
  1. tests/meta_prompt_graph_test.py +25 -2
tests/meta_prompt_graph_test.py CHANGED
@@ -1,8 +1,9 @@
1
  import unittest
2
  import pprint
3
  import logging
4
- from unittest.mock import MagicMock
5
- from unittest.mock import patch
 
6
 
7
  from langchain_openai import ChatOpenAI
8
 
@@ -161,5 +162,27 @@ class TestMetaPromptGraph(unittest.TestCase):
161
  "The result should have the attribute 'content'"
162
  print(result.content)
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  if __name__ == '__main__':
165
  unittest.main()
 
1
  import unittest
2
  import pprint
3
  import logging
4
+ from unittest.mock import MagicMock, patch, Mock
5
+ from langchain_core.runnables.utils import Output
6
+ from langchain_core.language_models import BaseLanguageModel
7
 
8
  from langchain_openai import ChatOpenAI
9
 
 
162
  "The result should have the attribute 'content'"
163
  print(result.content)
164
 
165
+ def test_simple_workflow_execution(self):
166
+ # Create a mock LLM that returns predefined responses based on the input messages
167
+ llm = Mock(spec=BaseLanguageModel)
168
+ responses = [
169
+ Mock(type="content", content="Explain how to reverse a list in Python."), # NODE_PROMPT_INITIAL_DEVELOPER
170
+ Mock(type="content", content="Here's one way: `my_list[::-1]`"), # NODE_PROMPT_EXECUTOR
171
+ Mock(type="content", content="Accept: Yes"), # NODE_OUTPUT_HISTORY_ANALYZER
172
+ ]
173
+ llm.invoke = lambda _: responses.pop(0)
174
+
175
+ meta_prompt_graph = MetaPromptGraph(llms=llm)
176
+ input_state = AgentState(
177
+ user_message="How do I reverse a list in Python?",
178
+ expected_output="The output should use the `reverse()` method.",
179
+ acceptance_criteria="The output should be correct and efficient."
180
+ )
181
+
182
+ output_state = meta_prompt_graph(input_state)
183
+
184
+ self.assertIsNotNone(output_state['best_system_message'])
185
+ self.assertIsNotNone(output_state['best_output'])
186
+
187
  if __name__ == '__main__':
188
  unittest.main()