mirror of
https://github.com/jie65535/JChatGPT.git
synced 2026-09-15 02:56:10 +08:00
profile: add adaptive daily request control
This commit is contained in:
@@ -142,6 +142,31 @@ class UserProfileAnalysisServiceTest {
|
||||
assertFalse(UserProfileStore.isConversationProcessed(INPUT_HASH))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dailyControllerDoesNotCountSafetyRejectionAsAnOutage() = withProfileStore {
|
||||
val controller = ProfileDailyRequestController(
|
||||
maxConcurrentRequests = 128,
|
||||
maxAttempts = 3,
|
||||
)
|
||||
val model = FakeConversationProfileModel {
|
||||
throw ModelSafetyRejectionException(
|
||||
errorType = "invalid_request_error",
|
||||
errorCode = "cyber_policy",
|
||||
message = "blocked by policy",
|
||||
)
|
||||
}
|
||||
|
||||
assertFailsWith<ModelSafetyRejectionException> {
|
||||
analyze(batch(), model, retryMax = 2, requestController = controller)
|
||||
}
|
||||
|
||||
val stats = controller.snapshot()
|
||||
assertEquals(1, stats.totalAttempts)
|
||||
assertEquals(0, stats.countedFailures)
|
||||
assertEquals(0, stats.pauseIncidents)
|
||||
assertFalse(stats.stopped)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skipsConversationAlreadyProcessedByAnEarlierCall() = withProfileStore {
|
||||
val model = FakeConversationProfileModel { successfulResult() }
|
||||
@@ -250,12 +275,14 @@ class UserProfileAnalysisServiceTest {
|
||||
model: ConversationProfileModel,
|
||||
minAuthoredTextChars: Int = 1,
|
||||
retryMax: Int = 0,
|
||||
requestController: ProfileDailyRequestController? = null,
|
||||
): ConversationProfileAnalysisReport? = UserProfileAnalysisService.analyzeConversationBatch(
|
||||
batch = batch,
|
||||
minAuthoredTextChars = minAuthoredTextChars,
|
||||
model = model,
|
||||
retryMax = retryMax,
|
||||
summaryMaxLength = 500,
|
||||
requestController = requestController,
|
||||
)
|
||||
|
||||
private fun successfulResult() = result(
|
||||
|
||||
Reference in New Issue
Block a user