@@ -176,58 +176,31 @@ def consistent_payload():
176
176
"seed" : 13 # fixed random seed
177
177
}
178
178
179
- # ==========================
180
- # Helper function to calculate difference rate between two texts
181
- # ==========================
182
- def calculate_diff_rate (text1 , text2 ):
183
- """
184
- Calculate the difference rate between two strings
185
- based on the normalized Levenshtein edit distance.
186
- Returns a float in [0,1], where 0 means identical.
187
- """
188
- if text1 == text2 :
189
- return 0.0
190
-
191
- len1 , len2 = len (text1 ), len (text2 )
192
- dp = [[0 ] * (len2 + 1 ) for _ in range (len1 + 1 )]
193
-
194
- for i in range (len1 + 1 ):
195
- for j in range (len2 + 1 ):
196
- if i == 0 or j == 0 :
197
- dp [i ][j ] = i + j
198
- elif text1 [i - 1 ] == text2 [j - 1 ]:
199
- dp [i ][j ] = dp [i - 1 ][j - 1 ]
200
- else :
201
- dp [i ][j ] = 1 + min (dp [i - 1 ][j ], dp [i ][j - 1 ], dp [i - 1 ][j - 1 ])
202
-
203
- edit_distance = dp [len1 ][len2 ]
204
- max_len = max (len1 , len2 )
205
- return edit_distance / max_len if max_len > 0 else 0.0
206
179
207
180
# ==========================
208
181
# Consistency test for repeated runs with fixed payload
209
182
# ==========================
210
183
def test_consistency_between_runs (api_url , headers , consistent_payload ):
211
184
"""
212
- Test that two runs with the same fixed input produce similar outputs .
185
+ Test that result is same as the base result .
213
186
"""
214
- # First request
187
+ # request
215
188
resp1 = requests .post (api_url , headers = headers , json = consistent_payload )
216
189
assert resp1 .status_code == 200
217
190
result1 = resp1 .json ()
218
191
content1 = result1 ["choices" ][0 ]["message" ]["content" ]
219
192
220
- # Second request
221
- resp2 = requests . post ( api_url , headers = headers , json = consistent_payload )
222
- assert resp2 . status_code == 200
223
- result2 = resp2 . json ( )
224
- content2 = result2 [ "choices" ][ 0 ][ "message" ][ "content" ]
225
-
226
- # Calculate difference rate
227
- diff_rate = calculate_diff_rate ( content1 , content2 )
193
+ # base result
194
+ base_path = os . getenv ( "MODEL_PATH" )
195
+ if base_path :
196
+ base_file = os . path . join ( base_path , "ernie-4_5-vl-base" )
197
+ else :
198
+ base_file = "ernie-4_5-vl-base"
199
+ with open ( base_file , "r" ) as f :
200
+ content2 = f . read ( )
228
201
229
- # Verify that the difference rate is below the threshold
230
- assert diff_rate < 0.05 , "Output difference too large ({:.4%})" . format ( diff_rate )
202
+ # Verify that result is same as the base result
203
+ assert content1 == content2
231
204
232
205
# ==========================
233
206
# OpenAI Client Chat Completion Test
@@ -322,4 +295,4 @@ def test_streaming_chat(openai_client, capsys):
322
295
for chunk in response :
323
296
if hasattr (chunk .choices [0 ], 'delta' ) and hasattr (chunk .choices [0 ].delta , 'content' ):
324
297
output .append (chunk .choices [0 ].delta .content )
325
- assert len (output ) > 2
298
+ assert len (output ) > 2
0 commit comments