-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Mistral moderation API
Signed-off-by: Ricken Bazolo <[email protected]>
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiModerationModelIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.springframework.ai.mistralai; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.ai.mistralai.moderation.MistralAiModerationModel; | ||
import org.springframework.ai.moderation.Moderation; | ||
import org.springframework.ai.moderation.ModerationPrompt; | ||
import org.springframework.ai.moderation.ModerationResult; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Ricken Bazolo | ||
*/ | ||
@SpringBootTest(classes = MistralAiTestConfiguration.class) | ||
@EnabledIfEnvironmentVariable(named = "MISTRAL_AI_API_KEY", matches = ".+") | ||
public class MistralAiModerationModelIT { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(MistralAiModerationModelIT.class); | ||
|
||
@Autowired | ||
private MistralAiModerationModel mistralAiModerationModel; | ||
|
||
@Test | ||
void moderationAsPositiveTest() { | ||
var instructions = """ | ||
I want to kill them.!"."""; | ||
|
||
var moderationPrompt = new ModerationPrompt(instructions); | ||
|
||
var moderationResponse = this.mistralAiModerationModel.call(moderationPrompt); | ||
|
||
assertThat(moderationResponse.getResults()).hasSize(1); | ||
|
||
var generation = moderationResponse.getResult(); | ||
Moderation moderation = generation.getOutput(); | ||
assertThat(moderation.getId()).isNotEmpty(); | ||
assertThat(moderation.getResults()).isNotNull(); | ||
assertThat(moderation.getResults().size()).isNotZero(); | ||
logger.info(moderation.getResults().toString()); | ||
|
||
assertThat(moderation.getId()).isNotNull(); | ||
assertThat(moderation.getModel()).isNotNull(); | ||
|
||
ModerationResult result = moderation.getResults().get(0); | ||
assertThat(result.isFlagged()).isTrue(); | ||
assertThat(result.getCategories().isViolence()).isTrue(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters