1515import org .elasticsearch .xpack .inference .services .huggingface .request .completion .HuggingFaceUnifiedChatCompletionRequest ;
1616
1717import java .io .IOException ;
18- import java .net .URISyntaxException ;
1918import java .util .List ;
2019import java .util .Map ;
2120
2726public class HuggingFaceUnifiedChatCompletionRequestTests extends ESTestCase {
2827
2928 public void testCreateRequest_WithStreaming () throws IOException {
30- var request = createRequest ("url" , "secret" , "abcd" , "model" , true );
29+ var request = createRequest ("url" , "secret" , randomAlphaOfLength ( 15 ) , "model" , true );
3130 var httpRequest = request .createHttpRequest ();
3231
3332 assertThat (httpRequest .httpRequestBase (), instanceOf (HttpPost .class ));
@@ -37,8 +36,9 @@ public void testCreateRequest_WithStreaming() throws IOException {
3736 assertThat (requestMap .get ("stream" ), is (true ));
3837 }
3938
40- public void testTruncate_DoesNotReduceInputTextSize () throws URISyntaxException , IOException {
41- var request = createRequest ("url" , "secret" , "abcd" , "model" , true );
39+ public void testTruncate_DoesNotReduceInputTextSize () throws IOException {
40+ String input = randomAlphaOfLength (5 );
41+ var request = createRequest ("url" , "secret" , input , "model" , true );
4242 var truncatedRequest = request .truncate ();
4343 assertThat (request .getURI ().toString (), is ("url" ));
4444
@@ -50,15 +50,15 @@ public void testTruncate_DoesNotReduceInputTextSize() throws URISyntaxException,
5050 assertThat (requestMap , aMapWithSize (5 ));
5151
5252 // We do not truncate for Hugging Face chat completions
53- assertThat (requestMap .get ("messages" ), is (List .of (Map .of ("role" , "user" , "content" , "abcd" ))));
53+ assertThat (requestMap .get ("messages" ), is (List .of (Map .of ("role" , "user" , "content" , input ))));
5454 assertThat (requestMap .get ("model" ), is ("model" ));
5555 assertThat (requestMap .get ("n" ), is (1 ));
5656 assertTrue ((Boolean ) requestMap .get ("stream" ));
5757 assertThat (requestMap .get ("stream_options" ), is (Map .of ("include_usage" , true )));
5858 }
5959
6060 public void testTruncationInfo_ReturnsNull () {
61- var request = createRequest ("url" , "secret" , "abcd" , "model" , true );
61+ var request = createRequest ("url" , "secret" , randomAlphaOfLength ( 5 ) , "model" , true );
6262 assertNull (request .getTruncationInfo ());
6363 }
6464
0 commit comments