-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Issue with custom transport #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @psymbio , thanks for sharing your findings. Unfortunately we can't commit to providing support to help debug issues with user code in this way. In this case, this line looks suspect to me: urllib3_response = self.pool.request('GET', str(request.url)) You don't seem to be passing the request headers along here (or the body, and the method looks incorrect as well). If you need further help from here, you may be able to ask fellow developers in the OpenAI Discord server. |
You were right, thanks! The correct way of doing it was: class URLLib3Transport(httpx.BaseTransport):
def __init__(self):
self.pool = urllib3.PoolManager()
def handle_request(self, request: httpx.Request):
payload = json.loads(request.content.decode("utf-8").replace("'",'"'))
urllib3_response = self.pool.request(request.method, str(request.url), headers=request.headers, json=payload) # Convert httpx.URL to string
content = json.loads(urllib3_response.data.decode('utf-8')) # Decode the data and load as JSON
stream = httpx.ByteStream(json.dumps(content).encode("utf-8")) # Convert back to JSON and encode
headers = [(b"content-type", b"application/json")]
return httpx.Response(200, headers=headers, stream=stream) |
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
So, I'm trying to resolve pyodide/pyodide#4292
With these fixes in place: urllib3/urllib3#3195, encode/httpx#2994, and the custom transport feature in the library the solution is more feasible.
To Reproduce
Testing environment: https://jupyter.org/try-jupyter/lab/
But I get this output:
I have provided the API key - so what am I doing wrong here?
Code snippets
No response
OS
Pyodide
Python version
Python v3.11.3
Library version
openai v1.3.7
The text was updated successfully, but these errors were encountered: