Reputation: 21
Python 3.9.12: This very simple code indented to upload a jsonl file to openAI for fine-tuning :gpt-3.5-turbo-1106 is resulting is the following error.
contents of the jsonl file being uploaded:
{"messages": [{"role": "system", "content": "Friendly Home Assistant"}, {"role": "user", "content": "Lights are too bring and hurting my eyes."}, {"role": "assistant", "content": "I'll reduce the luminosity by 25% now."}]}
{"messages": [{"role": "system", "content": "Friendly Home Assistant"}, {"role": "user", "content": "Music is not loud enough."}, {"role": "assistant", "content": "Ill increase the volume by 25% now."}]}
code in upload.py:
from openai import OpenAI
client = openai.OpenAI()
training_data_path = "fine_tuneGPT_test.jsonl"
response = client.files.create(
file=open("training_data_path","rb"),
purpose="fine-tune"
)
print(response)
and the error:
(openai-env) (base) PS C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2> python upload.py
Traceback (most recent call last):
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\upload.py", line 15, in <module>
response = client.files.create(
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\openai\resources\files.py", line 95, in create
return self._post(
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\openai\_base_client.py", line 1086, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\openai\_base_client.py", line 846, in request
return self._request(
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\openai\_base_client.py", line 866, in _request
request = self._build_request(options)
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\openai\_base_client.py", line 446, in _build_request
headers = self._build_headers(options)
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\openai\_base_client.py", line 407, in _build_headers
headers = httpx.Headers(headers_dict)
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\httpx\_models.py", line 70, in __init__
self._list = [
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\httpx\_models.py", line 74, in <listcomp>
normalize_header_value(v, encoding),
File "C:\Users\mendw\Dropbox\Projects\finetune_gpt\test_2\openai-env\lib\site-packages\httpx\_utils.py", line 53, in normalize_header_value
return value.encode(encoding or "ascii")
**UnicodeEncodeError: 'ascii' codec can't encode character '\u201c' in position 7: ordinal not in range(128)**
I have search for an answer on this and cannot find a resolution. I tried setting encoding manually to utf-8 since Im exceeding ascii limits.
Upvotes: 0
Views: 344
Reputation: 575
It is probably because incorrect quote characters when setting env variables. Try giving " or ' instead of slanted quotes (which happens if you cut and paste from other apps like notes)
export OPENAI_API_KEY="sk-.... "
Upvotes: 0