다음을 통해 공유


OpenAI API에서 오류 시뮬레이션

앱에서 OpenAI API를 사용하는 경우 앱에서 API 오류를 처리하는 방법을 테스트해야 합니다. 개발자 프록시를 사용하면 GenericRandomErrorPlugin을 사용하여 OpenAI API에서 오류를 시뮬레이트할 수 있습니다.

명령 프롬프트 devproxy preset get openai-throttling에서 를 실행하여 이 사전 설정을 다운로드합니다.

개발자 프록시 설치 폴더에서 폴더를 찾습니다 presets . 폴더에서 presets 라는 openai-errors.json새 파일을 만듭니다. 코드 편집기에서 파일을 엽니다.

를 참조하는 배열에 plugins 새 개체를 만듭니다 GenericRandomErrorPlugin. 플러그 인에서 watch 플러그 인 구성에 대한 참조를 추가할 OpenAI API URL을 정의합니다.

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.14.1/rc.schema.json",
  "plugins": [    
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "openAIAPI",
      "urlsToWatch": [
        "https://api.openai.com/*"
      ]
    }
  ]
}

플러그 인 구성 개체를 만들어 플러그 인에 오류 응답의 위치를 제공합니다.

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.14.1/rc.schema.json",
  "plugins": [    
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "openAIAPI",
      "urlsToWatch": [
        "https://api.openai.com/*"
      ]
    }
  ],
  "openAIAPI": {
    "errorsFile": "errors-openai.json"
  }
}

동일한 폴더에서 파일을 만듭니다 errors-openai.json . 이 파일에는 플러그 인이 오류 응답을 보낼 때 반환될 수 있는 가능한 오류 응답이 포함되어 있습니다.

{
  "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/presets/openai-errors.json"

OpenAI API를 호출하는 앱을 사용하는 경우 개발자 프록시는 파일에 정의한 오류 응답 중 하나를 임의로 errors-openai.json 반환합니다.

GenericRandomErrorPlugin에 대해 자세히 알아봅니다.