mirror of
https://github.com/jie65535/JChatGPT.git
synced 2026-09-15 02:56:10 +08:00
profile: handle rejected model responses
This commit is contained in:
@@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import net.mamoe.mirai.message.data.MessageSourceKind
|
||||
import top.jie65535.mirai.data.ChatMessageRecord
|
||||
import top.jie65535.mirai.llm.ModelSafetyRejectionException
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
@@ -122,6 +123,25 @@ class UserProfileAnalysisServiceTest {
|
||||
assertFalse(UserProfileStore.isConversationProcessed(INPUT_HASH))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun safetyRejectionDoesNotRetryOrCommit() = withProfileStore {
|
||||
val model = FakeConversationProfileModel {
|
||||
throw ModelSafetyRejectionException(
|
||||
errorType = "invalid_request_error",
|
||||
errorCode = "cyber_policy",
|
||||
message = "blocked by policy",
|
||||
)
|
||||
}
|
||||
|
||||
assertFailsWith<ModelSafetyRejectionException> {
|
||||
analyze(batch(), model, retryMax = 3)
|
||||
}
|
||||
|
||||
assertEquals(1, model.calls)
|
||||
assertNull(UserProfileStore.load(USER_A))
|
||||
assertFalse(UserProfileStore.isConversationProcessed(INPUT_HASH))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skipsConversationAlreadyProcessedByAnEarlierCall() = withProfileStore {
|
||||
val model = FakeConversationProfileModel { successfulResult() }
|
||||
|
||||
Reference in New Issue
Block a user