-
Notifications
You must be signed in to change notification settings - Fork 135
fix: avoid filtered providers on moderation failure #1985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
152a8bd
e8d62de
9fe0c9b
290557d
1c140e6
54bb162
e26c302
77b91b8
d1ed69f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ interface OpenAIModerationResult { | |
|
|
||
| export interface OpenAIContentFilterCheckResult { | ||
| flagged: boolean; | ||
| unavailable: boolean; | ||
| model: string; | ||
| upstreamRequestId: string | null; | ||
| results: OpenAIModerationResult[]; | ||
|
|
@@ -339,9 +340,11 @@ function buildModerationErrorDetails(error: unknown): Record<string, string> { | |
|
|
||
| function createFailedOpenAIContentFilterResult( | ||
| upstreamRequestId: string | null = null, | ||
| unavailable = true, | ||
| ): OpenAIContentFilterCheckResult { | ||
| return { | ||
| flagged: false, | ||
| unavailable, | ||
| model: OPENAI_MODERATION_MODEL, | ||
| upstreamRequestId, | ||
| results: [], | ||
|
|
@@ -446,6 +449,7 @@ async function runOpenAIContentFilterRequest( | |
| flagged: (moderationResponse.results ?? []).some((result) => | ||
| isOpenAIModerationResultFlagged(result), | ||
| ), | ||
| unavailable: false, | ||
| model: moderationResponse.model ?? OPENAI_MODERATION_MODEL, | ||
| upstreamRequestId, | ||
| results: moderationResponse.results ?? [], | ||
|
|
@@ -476,7 +480,7 @@ export async function checkOpenAIContentFilter( | |
| results: [], | ||
| }); | ||
|
|
||
| return createFailedOpenAIContentFilterResult(); | ||
| return createFailedOpenAIContentFilterResult(null, false); | ||
| } | ||
|
Comment on lines
470
to
484
|
||
|
|
||
| const signal = requestSignal | ||
|
|
@@ -530,6 +534,7 @@ export async function checkOpenAIContentFilter( | |
|
|
||
| return { | ||
| flagged, | ||
| unavailable: moderationResults.some((result) => !result.success), | ||
| model, | ||
| upstreamRequestId, | ||
| results, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,7 @@ export function selectNextProvider( | |
| score: number; | ||
| region?: string; | ||
| excludedByContentFilter?: boolean; | ||
| excludedByModerationFailure?: boolean; | ||
| }>, | ||
| failedProviders: Set<string>, | ||
| modelProviders: Array<{ | ||
|
|
@@ -95,7 +96,7 @@ export function selectNextProvider( | |
| ): { providerId: string; modelName: string; region?: string } | null { | ||
| const sorted = [...providerScores].sort((a, b) => a.score - b.score); | ||
| for (const score of sorted) { | ||
| if (score.excludedByContentFilter) { | ||
| if (score.excludedByContentFilter || score.excludedByModerationFailure) { | ||
| continue; | ||
| } | ||
|
Comment on lines
97
to
101
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.