11import os
22import pytest
33from string import Template
4- from together import Together
54from aimon .reprompting_api .config import RepromptingConfig
65from aimon .reprompting_api .runner import run_reprompting_pipeline
76
8- TOGETHER_API_KEY = os .environ .get ("TOGETHER_API_KEY" )
97AIMON_API_KEY = os .environ .get ("AIMON_API_KEY" )
108
11- client = Together (api_key = TOGETHER_API_KEY )
12-
139# --- Fixtures ---
1410
1511@pytest .fixture
1612def my_llm ():
1713 """Mock LLM function for integration tests. Prints prompts and responses."""
1814 def _my_llm (recommended_prompt_template : Template , system_prompt , context , user_query ) -> str :
19- filled_prompt = recommended_prompt_template .substitute (
15+ filled_prompt = recommended_prompt_template .safe_substitute (
2016 system_prompt = system_prompt or "" ,
2117 context = context or "" ,
2218 user_query = user_query or ""
2319 )
24- print ("\n ==== LLM PROMPT SENT ====" , flush = True )
25- print (filled_prompt , flush = True )
26- response = client .chat .completions .create (
27- model = "mistralai/Mistral-7B-Instruct-v0.2" ,
28- messages = [{"role" : "user" , "content" : filled_prompt }],
29- max_tokens = 256 ,
30- temperature = 0
31- )
32- print ("\n ==== LLM RAW RESPONSE ====" , flush = True )
33- print (response .choices [0 ].message .content , flush = True )
34- return response .choices [0 ].message .content
20+ return filled_prompt
3521 return _my_llm
3622
3723@pytest .fixture
@@ -104,7 +90,6 @@ def print_result(test_name, result):
10490
10591# --- Tests ---
10692
107- @pytest .mark .integration
10893def test_low_latency_limit (my_llm , config_low_latency ):
10994 """Test stopping behavior when latency limit is very low (100ms)."""
11095 result = run_reprompting_pipeline (
@@ -117,7 +102,6 @@ def test_low_latency_limit(my_llm, config_low_latency):
117102 print_result ("Low Latency Limit Test (100ms)" , result )
118103 assert "best_response" in result
119104
120- @pytest .mark .integration
121105def test_latency_limit (my_llm , config_high_latency ):
122106 """Test behavior with a high latency limit and contradictory instructions."""
123107 result = run_reprompting_pipeline (
@@ -130,7 +114,6 @@ def test_latency_limit(my_llm, config_high_latency):
130114 print_result ("High Latency Limit Test (5000ms)" , result )
131115 assert "best_response" in result
132116
133- @pytest .mark .integration
134117def test_iteration_limit (my_llm , config_iteration_limit ):
135118 """Test behavior when max_iterations is 1."""
136119 result = run_reprompting_pipeline (
@@ -144,7 +127,6 @@ def test_iteration_limit(my_llm, config_iteration_limit):
144127 print_result ("Iteration Limit Test (no re-prompting, only 1 iteration allowed)" , result )
145128 assert "best_response" in result
146129
147- @pytest .mark .integration
148130def test_empty_context_and_instructions (my_llm , base_config ):
149131 """Ensure pipeline works with no context, instructions, or system prompt."""
150132 result = run_reprompting_pipeline (
@@ -157,7 +139,6 @@ def test_empty_context_and_instructions(my_llm, base_config):
157139 print_result ("Empty Context & Instructions Test" , result )
158140 assert "best_response" in result
159141
160- @pytest .mark .integration
161142def test_no_telemetry (my_llm , config_without_telemetry ):
162143 """Confirm telemetry and summary are excluded when disabled in config."""
163144 result = run_reprompting_pipeline (
@@ -171,7 +152,6 @@ def test_no_telemetry(my_llm, config_without_telemetry):
171152 assert "telemetry" not in result
172153 assert "summary" not in result
173154
174- @pytest .mark .integration
175155def test_no_system_prompt (my_llm , base_config ):
176156 """Test behavior when system prompt is excluded."""
177157 result = run_reprompting_pipeline (
0 commit comments