@@ -74,22 +74,19 @@ def test_get_utterances_by_id_duplicate_texts_different_labels():
7474@pytest .mark .asyncio
7575async def test_create_intent_description_basic ():
7676 client = AsyncMock ()
77- mock_create = client .chat . completions . create
78- mock_create .return_value = AsyncMock ( choices = [ Mock ( message = Mock ( content = "Generated description" ))])
77+ mock_create = client .get_chat_completion_async
78+ mock_create .return_value = "Generated description"
7979
8080 utterances = ["Hi" , "Hello" ]
81- regex_patterns = ["^hello$" , "^hi$" ]
8281 prompt = PromptDescription (
83- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
82+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
8483 )
8584
8685 description = await create_intent_description (
8786 client = client ,
8887 intent_name = "Greeting" ,
8988 utterances = utterances ,
90- regex_patterns = regex_patterns ,
9189 prompt = prompt ,
92- model_name = "gpt4o-mini" ,
9390 )
9491
9592 assert description == "Generated description"
@@ -99,22 +96,19 @@ async def test_create_intent_description_basic():
9996@pytest .mark .asyncio
10097async def test_create_intent_description_empty_intent_name ():
10198 client = AsyncMock ()
102- mock_create = client .chat . completions . create
103- mock_create .return_value = AsyncMock ( choices = [ Mock ( message = Mock ( content = "Generated description" ))])
99+ mock_create = client .get_chat_completion_async
100+ mock_create .return_value = "Generated description"
104101
105102 utterances = ["Hi" , "Hello" ]
106- regex_patterns = ["^hello$" , "^hi$" ]
107103 prompt = PromptDescription (
108- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
104+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
109105 )
110106
111107 description = await create_intent_description (
112108 client = client ,
113109 intent_name = None ,
114110 utterances = utterances ,
115- regex_patterns = regex_patterns ,
116111 prompt = prompt ,
117- model_name = "gpt4o-mini" ,
118112 )
119113
120114 assert description == "Generated description"
@@ -124,22 +118,19 @@ async def test_create_intent_description_empty_intent_name():
124118@pytest .mark .asyncio
125119async def test_create_intent_description_empty_utterances_patterns ():
126120 client = AsyncMock ()
127- mock_create = client .chat . completions . create
128- mock_create .return_value = AsyncMock ( choices = [ Mock ( message = Mock ( content = "Generated description" ))])
121+ mock_create = client .get_chat_completion_async
122+ mock_create .return_value = "Generated description"
129123
130124 utterances = []
131- regex_patterns = []
132125 prompt = PromptDescription (
133- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
126+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
134127 )
135128
136129 description = await create_intent_description (
137130 client = client ,
138131 intent_name = "Greeting" ,
139132 utterances = utterances ,
140- regex_patterns = regex_patterns ,
141133 prompt = prompt ,
142- model_name = "gpt4o-mini" ,
143134 )
144135
145136 assert description == "Generated description"
@@ -149,51 +140,46 @@ async def test_create_intent_description_empty_utterances_patterns():
149140@pytest .mark .asyncio
150141async def test_create_intent_description_large_utterances_patterns ():
151142 client = AsyncMock ()
152- mock_create = client .chat . completions . create
153- mock_create .return_value = AsyncMock ( choices = [ Mock ( message = Mock ( content = "Generated description" ))])
143+ mock_create = client .get_chat_completion_async
144+ mock_create .return_value = "Generated description"
154145
155146 utterances = ["Hi" , "Hello" , "Hey" , "Greetings" , "Salutations" , "Good day" , "Hiya" ]
156- regex_patterns = ["^hello$" , "^hi$" , "^hey$" , "^greetings$" ]
157147 prompt = PromptDescription (
158- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
148+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
159149 )
160150
161151 with patch ("random.sample" , side_effect = lambda x , k : x [:k ]) as mock_sample :
162152 description = await create_intent_description (
163153 client = client ,
164154 intent_name = "Greeting" ,
165155 utterances = utterances ,
166- regex_patterns = regex_patterns ,
167156 prompt = prompt ,
168- model_name = "gpt4o-mini" ,
169157 )
170158
171159 assert description == "Generated description"
172160 mock_create .assert_called_once ()
173161 mock_sample .assert_any_call (utterances , 5 )
174- mock_sample .assert_any_call (regex_patterns , 3 )
175162
176163
177164@pytest .mark .asyncio
178165async def test_generate_intent_descriptions_basic ():
179166 client = AsyncMock ()
180- mock_create = client .chat . completions . create
181- mock_create .return_value = AsyncMock ( choices = [ Mock ( message = Mock ( content = "Generated description" ))])
167+ mock_create = client .get_chat_completion_async
168+ mock_create .return_value = "Generated description"
182169
183170 intent_utterances = {1 : ["Hello" , "Hi" ], 2 : ["Goodbye" , "See you" ]}
184171 intents = [
185172 Intent (id = 1 , name = "Greeting" , description = None , regex_full_match = [], regex_partial_match = []),
186173 Intent (id = 2 , name = "Farewell" , description = None , regex_full_match = [], regex_partial_match = []),
187174 ]
188175 prompt = PromptDescription (
189- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
176+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
190177 )
191178 updated_intents = await generate_intent_descriptions (
192179 client = client ,
193180 intent_utterances = intent_utterances ,
194181 intents = intents ,
195182 prompt = prompt ,
196- model_name = "gpt4o-mini" ,
197183 )
198184
199185 assert all (intent .description == "Generated description" for intent in updated_intents )
@@ -203,8 +189,8 @@ async def test_generate_intent_descriptions_basic():
203189@pytest .mark .asyncio
204190async def test_generate_intent_descriptions_skip_existing_descriptions ():
205191 client = AsyncMock ()
206- mock_create = client .chat . completions . create
207- mock_create .return_value = AsyncMock ( choices = [ Mock ( message = Mock ( content = "Generated description" ))])
192+ mock_create = client .get_chat_completion_async
193+ mock_create .return_value = "Generated description"
208194
209195 intent_utterances = {1 : ["Hello" , "Hi" ], 2 : ["Goodbye" , "See you" ]}
210196 intents = [
@@ -218,14 +204,13 @@ async def test_generate_intent_descriptions_skip_existing_descriptions():
218204 Intent (id = 2 , name = "Farewell" , description = None , regex_full_match = [], regex_partial_match = []),
219205 ]
220206 prompt = PromptDescription (
221- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
207+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
222208 )
223209 updated_intents = await generate_intent_descriptions (
224210 client = client ,
225211 intent_utterances = intent_utterances ,
226212 intents = intents ,
227213 prompt = prompt ,
228- model_name = "gpt4o-mini" ,
229214 )
230215
231216 assert updated_intents [0 ].description == "Existing description"
@@ -236,35 +221,36 @@ async def test_generate_intent_descriptions_skip_existing_descriptions():
236221@pytest .mark .asyncio
237222async def test_generate_intent_descriptions_empty_utterances_patterns ():
238223 client = AsyncMock ()
239- mock_create = client .chat . completions . create
240- mock_create .return_value = AsyncMock ( choices = [ Mock ( message = Mock ( content = "Generated description" ))])
224+ mock_create = client .get_chat_completion_async
225+ mock_create .return_value = "Generated description"
241226
242227 intent_utterances = {} # No utterances for any intent
243228 intents = [
244229 Intent (id = 1 , name = "Greeting" , description = None , regex_full_match = [], regex_partial_match = []),
245230 ]
246231 prompt = PromptDescription (
247- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
232+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
248233 )
249234 updated_intents = await generate_intent_descriptions (
250235 client = client ,
251236 intent_utterances = intent_utterances ,
252237 intents = intents ,
253238 prompt = prompt ,
254- model_name = "gpt4o-mini" ,
255239 )
256240
257241 # Assertions
258242 assert updated_intents [0 ].description == "Generated description"
259243 mock_create .assert_called_once_with (
260244 messages = [
245+ {
246+ "role" : "system" ,
247+ "content" : prompt .system_text ,
248+ },
261249 {
262250 "role" : "user" ,
263- "content" : prompt .text .format (intent_name = "Greeting" , user_utterances = "" , regex_patterns = "" ),
251+ "content" : prompt .user_text .format (intent_name = "Greeting" , user_utterances = "" ),
264252 },
265253 ],
266- model = "gpt4o-mini" ,
267- temperature = 0.2 ,
268254 )
269255
270256
@@ -292,13 +278,12 @@ def test_enhance_dataset_with_descriptions_basic():
292278 },
293279 )
294280 prompt = PromptDescription (
295- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
281+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
296282 )
297283 enhanced_dataset = generate_descriptions (
298284 dataset = dataset ,
299285 client = client ,
300286 prompt = prompt ,
301- model_name = "gpt4o-mini" ,
302287 )
303288 expected_intent_utterances = defaultdict (list , {0 : ["Hello" ], 1 : ["Goodbye" ]})
304289
@@ -312,7 +297,6 @@ def test_enhance_dataset_with_descriptions_basic():
312297 Intent (id = 1 , name = "Farewell" , description = None , regex_full_match = [], regex_partial_match = []),
313298 ],
314299 prompt ,
315- "gpt4o-mini" ,
316300 )
317301
318302
@@ -340,13 +324,12 @@ def test_enhance_dataset_with_existing_descriptions():
340324 },
341325 )
342326 prompt = PromptDescription (
343- text = "Describe intent {intent_name} with examples: {user_utterances} and patterns: {regex_patterns }" ,
327+ user_text = "Describe intent {intent_name} with examples: {user_utterances}" ,
344328 )
345329 enhanced_dataset = generate_descriptions (
346330 dataset = dataset ,
347331 client = client ,
348332 prompt = prompt ,
349- model_name = "gpt4o-mini" ,
350333 )
351334 expected_intent_utterances = defaultdict (list , {0 : ["Hello" ], 1 : ["Goodbye" ]})
352335
@@ -366,5 +349,4 @@ def test_enhance_dataset_with_existing_descriptions():
366349 Intent (id = 1 , name = "Farewell" , description = None , regex_full_match = [], regex_partial_match = []),
367350 ],
368351 prompt ,
369- "gpt4o-mini" ,
370352 )
0 commit comments