Spaces:
Running
Running
Added function test_iterated_workflow_execution().
Browse files
tests/meta_prompt_graph_test.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
import unittest
|
2 |
import pprint
|
3 |
import logging
|
4 |
-
from unittest.mock import MagicMock,
|
5 |
-
from langchain_core.runnables.utils import Output
|
6 |
from langchain_core.language_models import BaseLanguageModel
|
7 |
-
|
8 |
from langchain_openai import ChatOpenAI
|
9 |
|
10 |
# Assuming the necessary imports are made for the classes and functions used in meta_prompt_graph.py
|
@@ -168,7 +166,7 @@ class TestMetaPromptGraph(unittest.TestCase):
|
|
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"), #
|
172 |
]
|
173 |
llm.invoke = lambda _: responses.pop(0)
|
174 |
|
@@ -184,5 +182,36 @@ class TestMetaPromptGraph(unittest.TestCase):
|
|
184 |
self.assertIsNotNone(output_state['best_system_message'])
|
185 |
self.assertIsNotNone(output_state['best_output'])
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
if __name__ == '__main__':
|
188 |
unittest.main()
|
|
|
1 |
import unittest
|
2 |
import pprint
|
3 |
import logging
|
4 |
+
from unittest.mock import MagicMock, Mock
|
|
|
5 |
from langchain_core.language_models import BaseLanguageModel
|
|
|
6 |
from langchain_openai import ChatOpenAI
|
7 |
|
8 |
# Assuming the necessary imports are made for the classes and functions used in meta_prompt_graph.py
|
|
|
166 |
responses = [
|
167 |
Mock(type="content", content="Explain how to reverse a list in Python."), # NODE_PROMPT_INITIAL_DEVELOPER
|
168 |
Mock(type="content", content="Here's one way: `my_list[::-1]`"), # NODE_PROMPT_EXECUTOR
|
169 |
+
Mock(type="content", content="Accept: Yes"), # NODE_PPROMPT_ANALYZER
|
170 |
]
|
171 |
llm.invoke = lambda _: responses.pop(0)
|
172 |
|
|
|
182 |
self.assertIsNotNone(output_state['best_system_message'])
|
183 |
self.assertIsNotNone(output_state['best_output'])
|
184 |
|
185 |
+
pprint.pp(output_state["best_output"])
|
186 |
+
|
187 |
+
def test_iterated_workflow_execution(self):
|
188 |
+
# Create a mock LLM that returns predefined responses based on the input messages
|
189 |
+
llm = Mock(spec=BaseLanguageModel)
|
190 |
+
responses = [
|
191 |
+
Mock(type="content", content="Explain how to reverse a list in Python."), # NODE_PROMPT_INITIAL_DEVELOPER
|
192 |
+
Mock(type="content", content="Here's one way: `my_list[::-1]`"), # NODE_PROMPT_EXECUTOR
|
193 |
+
Mock(type="content", content="Accept: No"), # NODE_PPROMPT_ANALYZER
|
194 |
+
Mock(type="content", content="Try using the `reverse()` method instead."), # NODE_PROMPT_SUGGESTER
|
195 |
+
Mock(type="content", content="Explain how to reverse a list in Python. Output in a Markdown List."), # NODE_PROMPT_DEVELOPER
|
196 |
+
Mock(type="content", content="Here's one way: `my_list.reverse()`"), # NODE_PROMPT_EXECUTOR
|
197 |
+
Mock(type="content", content="# Preferred Output ID: B"), # NODE_OUTPUT_HISTORY_ANALYZER
|
198 |
+
Mock(type="content", content="Accept: Yes"), # NODE_PPROMPT_ANALYZER
|
199 |
+
]
|
200 |
+
llm.invoke = lambda _: responses.pop(0)
|
201 |
+
|
202 |
+
meta_prompt_graph = MetaPromptGraph(llms=llm)
|
203 |
+
input_state = AgentState(
|
204 |
+
user_message="How do I reverse a list in Python?",
|
205 |
+
expected_output="The output should use the `reverse()` method.",
|
206 |
+
acceptance_criteria="The output should be correct and efficient."
|
207 |
+
)
|
208 |
+
|
209 |
+
output_state = meta_prompt_graph(input_state)
|
210 |
+
|
211 |
+
self.assertIsNotNone(output_state['best_system_message'])
|
212 |
+
self.assertIsNotNone(output_state['best_output'])
|
213 |
+
|
214 |
+
pprint.pp(output_state["best_output"])
|
215 |
+
|
216 |
if __name__ == '__main__':
|
217 |
unittest.main()
|