fix(misc): restrict countries not supported by OpenAI (#26725)
Restrict countries that are not supported by OpenAI APIs: https://platform.openai.com/docs/supported-countries 
This commit is contained in:
parent
0cefa29eca
commit
88efb216a2
@ -15,7 +15,6 @@ import {
|
||||
getUserQuery,
|
||||
initializeChat,
|
||||
extractErrorMessage,
|
||||
// moderateContent,
|
||||
} from '@nx/nx-dev/util-ai';
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
import OpenAI from 'openai';
|
||||
@ -36,7 +35,24 @@ export const config = {
|
||||
};
|
||||
|
||||
export default async function handler(request: NextRequest) {
|
||||
const country = request.geo.country;
|
||||
const restrictedCountries: string[] = [
|
||||
'BY', // Belarus
|
||||
'CN', // China
|
||||
'CU', // Cuba
|
||||
'IR', // Iran
|
||||
'KP', // North Korea
|
||||
'RU', // Russia
|
||||
'SY', // Syria
|
||||
'VE', // Venezuela
|
||||
];
|
||||
try {
|
||||
if (restrictedCountries.includes(country)) {
|
||||
throw new CustomError(
|
||||
'user_error',
|
||||
'Service is not available in your region.'
|
||||
);
|
||||
}
|
||||
const openai = getOpenAI(openAiKey);
|
||||
const supabaseClient: SupabaseClient<any, 'public', any> =
|
||||
getSupabaseClient(supabaseUrl, supabaseServiceKey);
|
||||
@ -46,11 +62,6 @@ export default async function handler(request: NextRequest) {
|
||||
const query: string | null = getUserQuery(messages);
|
||||
const sanitizedQuery = query.trim();
|
||||
|
||||
// Moderate the content to comply with OpenAI T&C
|
||||
// Removing the moderation for now
|
||||
// to see if it's faster
|
||||
// await moderateContent(sanitizedQuery, openai);
|
||||
|
||||
// We include the previous response,
|
||||
// to make sure the embeddings (doc sections)
|
||||
// we get back are relevant.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user