Created
September 21, 2023 09:56
-
-
Save teramotodaiki/5cf2bd7c62a356ef3a80d5438e7b381b to your computer and use it in GitHub Desktop.
Azure OpenAI SDKをCloudflare Workerで利用するためのモンキーパッチ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Azure OpenAI SDK(@azure/openai)をCloudflare Workerで利用するとこういうエラーが出る | |
Trace: RestError: Error sending request: The 'credentials' field on 'RequestInitializerDict' is not implemented. | |
at getError (file:///private/var/folders/32/.../T/.../index.js:3407:12) | |
at FetchHttpClient.sendRequest (file:///private/var/folders/32/.../T/.../index.js:3317:13) { | |
name: RestError, | |
code: REQUEST_SEND_ERROR, | |
statusCode: undefined, | |
request: PipelineRequestImpl, | |
response: undefined | |
... | |
} | |
詳しくは下記のissueを参照 | |
https://github.com/cloudflare/workers-sdk/issues/2514 | |
これ以外は上手く動くっぽいので、モンキーパッチを当てて回避することにした | |
これでいいのかどうかは分からないので、コメント大歓迎です | |
*/ | |
// Azure OpenAI SDKをCloudflare Workerで利用するためのモンキーパッチ | |
const originalFetch = fetch; | |
self.fetch = (...args) => { | |
if (args[1]) { | |
// Cloudflare Workerでは利用できないオプションを削除 | |
if ("credentials" in args[1]) { | |
delete args[1]["credentials"]; | |
} | |
if ("cache" in args[1]) { | |
delete args[1]["cache"]; | |
} | |
} | |
return originalFetch(...args); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a monkey patch for the issue cloudflare/workers-sdk#2514