アプリで OpenAI API を使用する場合は、アプリが API エラーを処理する方法をテストする必要があります。 開発プロキシを使用すると、 GenericRandomErrorPlugin を使用して、任意の OpenAI API でエラーをシミュレートできます。
ヒント
コマンド プロンプト devproxy config get openai-throttling
で実行して、このプリセットをダウンロードします。
開発プロキシのインストール フォルダーで、 config
フォルダーを見つけます。
config
フォルダーに、openai-errors.json
という名前の新しいファイルを作成します。 コード エディターでファイルを開きます。
GenericRandomErrorPlugin
を参照するplugins
配列に新しいオブジェクトを作成します。 監視するプラグインの 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
ファイルで定義したエラー応答の 1 つをランダムに返します。
GenericRandomErrorPlugin の詳細を確認します。
Dev Proxy