Error uploading file via API

Hi,

I have below script that I am trying to upload to OpenAPI.

import os
import openai
openai.organization = "org-ZAcv7DYs6oi8K6IxNtf0ql2a"
openai.api_key = "MYKEY"

response = openai.File.create(
 file=open('C:/Users/Ray/OneDrive/Desktop/OpenAi/pd_training.jsonl'),
 purpose='answers'
)

print(response)

file content as followed:

{"text": Google was founded in 1998 by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University in California. Together they own about 14 percent of its shares and control 56 percent of the stockholder voting power through supervoting stock. They incorporated Google as a privately held company on September 4, 1998. An initial public offering (IPO) took place on August 19, 2004, and Google moved to its headquarters in Mountain View, California, nicknamed the Googleplex. In August 2015, Google announced plans to reorganize its various interests as a conglomerate called Alphabet Inc. Google is Alphabet's leading subsidiary and will continue to be the umbrella company for Alphabet's Internet interests. Sundar Pichai was appointed CEO of Google, replacing Larry Page who became the CEO of Alphabet.", "metadata": "Google"}
{"text": "Amazon is an American multinational technology company based in Seattle, Washington, which focuses on e-commerce, cloud computing, digital streaming, and artificial intelligence. It is one of the Big Five companies in the U.S. information technology industry, along with Google, Apple, Microsoft, and Facebook. The company has been referred to as 'one of the most influential economic and cultural forces in the world', as well as the world's most valuable brand.Jeff Bezos founded Amazon from his garage in Bellevue, Washington on July 5, 1994. It started as an online marketplace for books but expanded to sell electronics, software, video games, apparel, furniture, food, toys, and jewelry. In 2015, Amazon surpassed Walmart as the most valuable retailer in the United States by market capitalization.", "metadata": "Amazon"}

When I execute the code, I am getting follow error in the console:

PS C:\Users\Ray\OneDrive\Desktop\OpenAi> & C:/Users/Ray/AppData/Local/Microsoft/WindowsApps/python3.9.exe c:/Users/Ray/OneDrive/Desktop/OpenAi/Test.py
Upload progress: 100%|██████████████████████████████████████████████████████| 3.67k/3.67k [00:00<00:00, 14.6kit/s]
Traceback (most recent call last):
  File "c:\Users\Ray\OneDrive\Desktop\OpenAi\Test.py", line 13, in <module>
    response = openai.File.create(
  File "C:\Users\Ray\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\openai\api_resources\file.py", line 29, in create
    response, _, api_key = requestor.request(
  File "C:\Users\Ray\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\openai\api_requestor.py", line 129, in request
    resp = self.interpret_response(rbody, rcode, rheaders, stream=stream)
  File "C:\Users\Ray\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\openai\api_requestor.py", line 348, in interpret_response
    return self.interpret_response_line(rbody, rcode, rheaders, stream)
  File "C:\Users\Ray\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\openai\api_requestor.py", line 367, in interpret_response_line
    raise self.handle_error_response(
openai.error.InvalidRequestError: Expected a JSONL file.
PS C:\Users\Ray\OneDrive\Desktop\OpenAi>

Am I doing anything wrong here?

1 Like

Hi,

Thanks for your response. :slight_smile:

After I added missing quote, I still see the issue. So I removed that line from .jsonl file and tried it again. I still see the issue with following content in jsonl file.

{"text": "Amazon is an American multinational technology company based in Seattle, Washington, which focuses on e-commerce, cloud computing, digital streaming, and artificial intelligence. It is one of the Big Five companies in the U.S. information technology industry, along with Google, Apple, Microsoft, and Facebook. The company has been referred to as 'one of the most influential economic and cultural forces in the world', as well as the world's most valuable brand.Jeff Bezos founded Amazon from his garage in Bellevue, Washington on July 5, 1994. It started as an online marketplace for books but expanded to sell electronics, software, video games, apparel, furniture, food, toys, and jewelry. In 2015, Amazon surpassed Walmart as the most valuable retailer in the United States by market capitalization.", "metadata": "Amazon"}

I removed the first line and above content became the first time. No blank line above or at the bottom.

1 Like