앱에서 OpenAI API를 사용하는 경우 앱에서 API 오류를 처리하는 방법을 테스트해야 합니다. 개발자 프록시를 사용하면 GenericRandomErrorPlugin사용하여 OpenAI API에서 오류를 시뮬레이션할 수 있습니다.
팁
명령 프롬프트 devproxy config get openai-throttling실행하여 이 사전 설정을 다운로드합니다.
개발자 프록시 설치 폴더에서 config 폴더를 찾습니다.
config 폴더에서 openai-errors.json새 파일을 만듭니다. 코드 편집기에서 파일을 엽니다.
plugins참조하는 GenericRandomErrorPlugin 배열에 새 개체를 만듭니다. 플러그 인에서 감시할 OpenAI API URL을 정의하고 플러그 인 구성에 대한 참조를 추가합니다.
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/rc.schema.json",
"plugins": [
{
"name": "GenericRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "openAIAPI",
"urlsToWatch": [
"https://api.openai.com/*"
]
}
]
}
플러그 인 구성 개체를 만들어 플러그 인에 오류 응답의 위치를 제공합니다.
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/rc.schema.json",
"plugins": [
{
"name": "GenericRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "openAIAPI",
"urlsToWatch": [
"https://api.openai.com/*"
]
}
],
"openAIAPI": {
"errorsFile": "errors-openai.json"
}
}
동일한 폴더에서 errors-openai.json 파일을 만듭니다. 이 파일에는 플러그 인이 오류 응답을 보낼 때 반환될 수 있는 가능한 오류 응답이 포함되어 있습니다.
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/genericrandomerrorplugin.schema.json",
"errors": [
{
"request": {
"url": "https://api.openai.com/*"
},
"responses": [
{
"statusCode": 429,
"headers": [
{
"name": "content-type",
"value": "application/json; charset=utf-8"
}
],
"body": {
"error": {
"message": "Rate limit reached for default-text-davinci-003 in organization org-K7hT684bLccDbBRnySOoK9f2 on tokens per min. Limit: 150000.000000 / min. Current: 160000.000000 / min. Contact support@openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://beta.openai.com/account/billing to add a payment method.",
"type": "tokens",
"param": null,
"code": null
}
}
},
{
"statusCode": 429,
"headers": [
{
"name": "content-type",
"value": "application/json; charset=utf-8"
}
],
"body": {
"error": {
"message": "Rate limit reached for default-text-davinci-003 in organization org-K7hT684bLccDbBRnySOoK9f2 on requests per min. Limit: 60.000000 / min. Current: 70.000000 / min. Contact support@openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://beta.openai.com/account/billing to add a payment method.",
"type": "requests",
"param": null,
"code": null
}
}
},
{
"statusCode": 429,
"addDynamicRetryAfter": true,
"headers": [
{
"name": "content-type",
"value": "application/json; charset=utf-8"
}
],
"body": {
"error": {
"message": "The engine is currently overloaded, please try again later.",
"type": "requests",
"param": null,
"code": null
}
}
}
]
}
]
}
구성 파일을 사용하여 개발 프록시를 시작합니다.
devproxy --config-file "~appFolder/config/openai-errors.json"
OpenAI API를 호출하는 앱을 사용하는 경우 개발자 프록시는 errors-openai.json 파일에 정의한 오류 응답 중 하나를 임의로 반환합니다.
GenericRandomErrorPlugin에 대해 자세히 알아봅니다.
Dev Proxy