Pass dangerouslyAllowBrowser to clean client constructor in isWrapped#170
Open
jamie-retool wants to merge 1 commit intobraintrustdata:mainfrom
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This might be an artifact of our own unique setup where we are using JSDom for handling browser-related things in our environment.
The Problem
The isWrapped function creates a "clean" client to compare against the passed client to detect if it's already been wrapped/proxied. It does this by calling:
However, in browser environments (or environments using JSDom), the OpenAI client requires dangerouslyAllowBrowser: true or it throws an error. If a client was created with
dangerouslyAllowBrowser: true, the isWrapped check would fail because the clean client constructor throws before the comparison can happen.The Fix
Extract dangerouslyAllowBrowser from the client options (or deprecated options) and pass it through to isWrapped, so the clean client is constructed with the same browser setting as the original.
I added a test that shows a failure before the fix, and it passes after the fix.
Also, I have a reproducible block of code that shows this failing in autoevals 0.0.127 (the latest code fails in the same way).
Code you can run to see it fail in current versions: