Megosztás a következőn keresztül:


OpenAI API-k hibáinak szimulálása

Amikor OpenAI API-kat használ az alkalmazásban, tesztelnie kell, hogyan kezeli az alkalmazás az API-hibákat. A Dev Proxy segítségével bármilyen OpenAI API-n szimulálhat hibákat a GenericRandomErrorPluginhasználatával.

Borravaló

Töltse le ezt az előre beállítást a devproxy config get openai-throttlingparancs futtatásával a parancssorban.

A Dev Proxy telepítési mappájában keresse meg a config mappát. A config mappában hozzon létre egy openai-errors.jsonnevű új fájlt. Nyissa meg a fájlt egy kódszerkesztőben.

Hozzon létre egy új objektumot a pluginshivatkozó GenericRandomErrorPlugin tömbben. Adja meg a beépülő modul OpenAI API-URL-címét, és adjon hozzá egy hivatkozást a beépülő modul konfigurációjának megtekintéséhez és hozzáadásához.

{
  "$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/*"
      ]
    }
  ]
}

Hozza létre a beépülő modul konfigurációs objektumát, hogy megadja a beépülő modulnak a hibaválaszok helyét.

{
  "$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"
  }
}

Ugyanabban a mappában hozza létre a errors-openai.json fájlt. Ez a fájl tartalmazza azokat a lehetséges hibaválaszokat, amelyeket a beépülő modul hibaválasz küldésekor lehet visszaadni.

{
  "$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
            }
          }
        }
      ]
    }
  ]
}

Indítsa el a Dev Proxyt a konfigurációs fájllal:

devproxy --config-file "~appFolder/config/openai-errors.json"

Az OpenAI API-kat hívó alkalmazás használatakor a Dev Proxy véletlenszerűen adja vissza a errors-openai.json fájlban megadott hibaválaszok egyikét.

További információ a GenericRandomErrorPluginről.