groq / groq-python

The official Python Library for the Groq API
Apache License 2.0
353 stars 23 forks source link

UnicodeEncodeError: 'ascii' codec can't encode character '\u200b' in position 117: ordinal not in range(128) #7

Closed MediGenie closed 6 months ago

MediGenie commented 6 months ago

Hello! I got early access to the api and I just ran the example code, but there seems to be an error with ASCII? Would you please check?

Traceback (most recent call last): File "/home/ubuntu/sample.py", line 9, in <module> chat_completion = client.chat.completions.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/resources/chat/completions.py", line 175, in create return self._post( ^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/_base_client.py", line 1186, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/_base_client.py", line 888, in request return self._request( ^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/_base_client.py", line 909, in _request request = self._build_request(options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/_base_client.py", line 451, in _build_request headers = self._build_headers(options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/_base_client.py", line 412, in _build_headers headers = httpx.Headers(headers_dict) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/httpx/_models.py", line 70, in __init__ self._list = [ ^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/httpx/_models.py", line 74, in <listcomp> normalize_header_value(v, encoding), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/httpx/_utils.py", line 53, in normalize_header_value return value.encode(encoding or "ascii") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'ascii' codec can't encode character '\u200b' in position 117: ordinal not in range(128)

MediGenie commented 6 months ago

So i just did a quick HTTPX library fix and now it seems to be working, but I encounter another error. I was just provided API Auth Token, hence i dont know what userID means. here

Traceback (most recent call last): File "/home/ubuntu/sample.py", line 9, in <module> chat_completion = client.chat.completions.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/resources/chat/completions.py", line 175, in create return self._post( ^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/_base_client.py", line 1186, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/_base_client.py", line 888, in request return self._request( ^^^^^^^^^^^^^^ File "/home/ubuntu/.pyenv/versions/3.11.4/lib/python3.11/site-packages/groq/_base_client.py", line 979, in _request raise self._make_status_error_from_response(err.response) from None groq.BadRequestError: Failed getting metadata from request: error userID missing

MediGenie commented 6 months ago

I tried with CURL and I get the same result. image

MediGenie commented 6 months ago

Just FYI i am running curl 8.6.0 image

hozen-groq commented 6 months ago

Hello! Excited that you were able to get early access, but sad that you ran into some issues. Rest assured that the team is currently looking into this. We'll provide updates soon... 🚀

MediGenie commented 6 months ago

Thanks! Looking forward to getting it fixed so i can try out the api.😇

hozen-groq commented 6 months ago

Hi! It's been a bit - hope you're doing well! 😄 I was wondering if you could please try this again and let me know your results?

mac4281 commented 6 months ago

I'm getting the same result today. Looking forward to diving in to Groq!

rattrayalex commented 6 months ago

It seems you may have a zero-width space character in your api key. Can you try removing it?

mac4281 commented 6 months ago

@rattrayalex Yep, that was it! Working great now.. Thanks!

hozen-groq commented 6 months ago

@rattrayalex Alex! You're the best! Thank you for lending a hand. So happy that these are resolved. Happy exploring, guys! 🙌