File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails
runtime/src/main/java/io/quarkiverse/langchain4j/guardrails Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change 1- package io .quarkiverse .langchain4j .guardrails ;
1+ package io .quarkiverse .langchain4j .test . guardrails ;
22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
44
55import java .util .List ;
66
77import jakarta .inject .Inject ;
88
9+ import org .jboss .shrinkwrap .api .ShrinkWrap ;
10+ import org .jboss .shrinkwrap .api .spec .JavaArchive ;
911import org .junit .jupiter .api .Test ;
12+ import org .junit .jupiter .api .extension .RegisterExtension ;
1013
1114import com .fasterxml .jackson .core .type .TypeReference ;
1215
13- import io .quarkus .test .junit .QuarkusTest ;
16+ import io .quarkiverse .langchain4j .guardrails .JsonGuardrailsUtils ;
17+ import io .quarkus .test .QuarkusUnitTest ;
1418
15- @ QuarkusTest
1619class JsonGuardrailsUtilsTest {
1720
21+ @ RegisterExtension
22+ static final QuarkusUnitTest unitTest = new QuarkusUnitTest ()
23+ .setArchiveProducer (() -> ShrinkWrap .create (JavaArchive .class ));
24+
1825 @ Inject
1926 JsonGuardrailsUtils jsonGuardrailsUtils ;
2027
Original file line number Diff line number Diff line change 88import com .fasterxml .jackson .databind .ObjectMapper ;
99
1010@ ApplicationScoped
11- class JsonGuardrailsUtils {
11+ public class JsonGuardrailsUtils {
1212
1313 @ Inject
1414 ObjectMapper objectMapper ;
1515
1616 private JsonGuardrailsUtils () {
1717 }
1818
19- String trimNonJson (String llmResponse ) {
19+ public String trimNonJson (String llmResponse ) {
2020 int jsonMapStart = llmResponse .indexOf ('{' );
2121 int jsonListStart = llmResponse .indexOf ('[' );
2222 if (jsonMapStart < 0 && jsonListStart < 0 ) {
@@ -29,15 +29,15 @@ String trimNonJson(String llmResponse) {
2929 return jsonEnd >= 0 && jsonStart < jsonEnd ? llmResponse .substring (jsonStart , jsonEnd + 1 ) : null ;
3030 }
3131
32- <T > T deserialize (String json , Class <T > expectedOutputClass ) {
32+ public <T > T deserialize (String json , Class <T > expectedOutputClass ) {
3333 try {
3434 return objectMapper .readValue (json , expectedOutputClass );
3535 } catch (JsonProcessingException e ) {
3636 return null ;
3737 }
3838 }
3939
40- <T > T deserialize (String json , TypeReference <T > expectedOutputType ) {
40+ public <T > T deserialize (String json , TypeReference <T > expectedOutputType ) {
4141 try {
4242 return objectMapper .readValue (json , expectedOutputType );
4343 } catch (JsonProcessingException e ) {
You can’t perform that action at this time.
0 commit comments