Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Bir bakışta
Hedef: OpenAI API'sinde hata işlemeyi test etme
Süre: 10 dakika
Eklentiler:GenericRandomErrorPlugin
Önkoşullar:Geliştirme Ara Sunucusunu Ayarlama
Uygulamanızda OpenAI API'lerini kullandığınızda uygulamanızın API hatalarını nasıl işlediğini test etmelisiniz. Dev Proxy, GenericRandomErrorPluginkullanarak herhangi bir OpenAI API'sinde hataların benzetimini yapmanızı sağlar.
Bahşiş
devproxy config get openai-throttlingkomut isteminde komutunu çalıştırarak bu ön ayarı indirin.
Dev Proxy yükleme klasöründe config klasörünü bulun.
config klasöründe openai-errors.jsonadlı yeni bir dosya oluşturun. Dosyayı bir kod düzenleyicisinde açın.
plugins'i referans eden GenericRandomErrorPlugin dizisinde yeni bir nesne oluşturun. OpenAI API URL'sini eklentinin izlemesi için tanımlayın ve eklenti yapılandırmasına bir referans ekleyin.
Dosya:openai-errors.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/rc.schema.json",
"plugins": [
{
"name": "GenericRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "openAIAPI",
"urlsToWatch": [
"https://api.openai.com/*"
]
}
]
}
Eklentiye hata yanıtlarının konumunu sağlamak için eklenti yapılandırma nesnesini oluşturun.
Dosya:openai-errors.json (tam yapılandırma)
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.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"
}
}
Aynı klasörde errors-openai.json dosyasını oluşturun. Bu dosya, eklenti bir hata yanıtı gönderdiğinde döndürülebilecek olası hata yanıtlarını içerir.
Dosya:errors-openai.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/genericrandomerrorplugin.errorsfile.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
}
}
}
]
}
]
}
Geliştirme Proxy'sini yapılandırma dosyasıyla başlatın:
devproxy --config-file "~appFolder/config/openai-errors.json"
Uygulamanızı OpenAI API'lerini çağırarak kullandığınızda Dev Proxy, errors-openai.json dosyasında tanımladığınız hata yanıtlarından birini rastgele döndürür.
GenericRandomErrorPlugin hakkında daha fazla bilgi edinin.