-
Notifications
You must be signed in to change notification settings - Fork 839
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
UnicodeEncodeError: 'ascii' codec can't encode character '\u201d' in position 7: ordinal not in range(128) #159
Comments
Can you add some context to your issue? |
sure. I am trying to use I have included more details of errors here. Please let me know if there is anything else I can add.
|
I found the reason I figured it out. The reason was when I export the API key through terminal, I used double quotation mark and this caused the error. So I removed the double quotation mark and it worked. |
The following script is generated by AI Agent to help reproduce the issue: # aisuite/reproduce.py
import os
from unittest.mock import patch, MagicMock
from aisuite.providers.huggingface_provider import HuggingfaceProvider, LLMError
def test_unicode_handling():
try:
# Set the environment variable for the token
os.environ["HF_TOKEN"] = "test-token"
# Initialize the provider
provider = HuggingfaceProvider()
# Create a message with a Unicode character
user_greeting = "Hello, how are you doing today? \u201d Unicode test: \u2603 \u2764 \u20AC"
message_history = [{"role": "user", "content": user_greeting}]
selected_model = "model-name"
# Mock the httpx.post request to avoid actual network call
mock_response = MagicMock()
mock_response.json.return_value = {
"choices": [{"message": {"content": "response-text"}}]
}
with patch("httpx.post", return_value=mock_response):
# Force the encoding process to catch UnicodeEncodeError
for message in message_history:
message["content"].encode('ascii')
response = provider.chat_completions_create(model=selected_model, messages=message_history)
# Check if the response is handled correctly
assert response.choices[0].message.content is not None
assert False, "Expected UnicodeEncodeError but did not get it."
except UnicodeEncodeError as e:
raise AssertionError(e)
except Exception as e:
raise AssertionError(f"An unexpected error occurred: {e}")
if __name__ == "__main__":
test_unicode_handling() How to run: python3 aisuite/reproduce.py Expected Result:
Thank you for your valuable contribution to this project and we appreciate your feedback! Please respond with an emoji if you find this script helpful. Feel free to comment below if any improvements are needed. Best regards from an AI Agent! |
I am keep getting the error on the title.
I am using python 3.13
using mac arm 64 anaconda.
The text was updated successfully, but these errors were encountered: