How to Upload a document for answers as file?

I was trying to upload using “openai.File.create” but once I create a file I get an error of
“Something went wrong while processing. Please contact support@openai.com with the file ID”

Inside my JsonL file:
{“text”:“Some text in here”}
This is for answers which have no examples.

I tried for a file with
{“text”:“Some text in here”, “Answer”:“Answers here”}
This worked without any problem.

I just wanna do

openai.Answer.create(
  search_model="ada", 
  model="curie",
  question="which puppy is happy?", 
  documents=["Puppy A is happy.", "Puppy B is sad."],
  examples_context="In 2017, U.S. life expectancy was 78.6 years.", 
  examples=[["What is human life expectancy in the United States?","78 years."]],
  max_tokens=5,
  stop=["\n", "<|endoftext|>"],
)

without providing the documents which are a list but use the fileID instead.
Sorry for asking a stupid question…

Hey,
This is the function I use that works well:

try:
    with open("key", mode="r") as f: #the key is in a plain text file called key(without extension)
        openai.api_key = f.read()
except FileNotFoundError:
    print("Create a plain text file called 'key'(no extension) for the key")
    exit()
except:
    print("sorry, an error occured!")
    exit()

def upload_file(file_2_upload, purpose="answers"):
    if os.path.exists(file_2_upload):
        response = openai.File.create(file=open(file_2_upload), purpose=purpose)
        print(
            f"{response.id=} -> {response.filename} {response.status} for {response.purpose}."
        )
    else:
        print(f"{file_2_upload=} not found")

Sample jsonl

{"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."}
{"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."}

Hope that helps.

1 Like

Sorry for the Edit.

I tried your jsonl file and seems like that works.
But my jsonl file does not.

{"text": "Standing screen display size:‎14 Inches"}
{"text": "Screen Resolution:‎2560 x 1440 pixels"}
{"text": "Max Screen Resolution:‎2560 x 1440"}
{"text": "Processor:‎3.3 GHz amd_ryzen_9_5900x"}
{"text": "RAM:‎16 GB DDR4"}
{"text": "Hard Drive:‎SSD"}
{"text": "Chipset Brand:‎Intel"}
{"text": "Card Description:‎Dedicated"}
{"text": "Graphics Card Ram Size:‎8 GB"}
{"text": "Wireless Type:‎Bluetooth, 802.11a/b/g/n/ac"}
{"text": "Number of USB 3.0 Ports:‎4"}
{"text": "Brand:‎Razer"}
{"text": "Series:‎Razer Blade 14"}
{"text": "Item model number:‎RZ09-0370CEA3-R3U1"}
{"text": "Hardware Platform:‎PC"}
{"text": "Operating System:‎Windows 10 Home"}
{"text": "Item Weight:‎3.92 pounds"}
{"text": "Product Dimensions:‎8.66 x 12.59 x 0.66 inches"}
{"text": "Item Dimensions LxWxH:‎8.66 x 12.59 x 0.66 inches"}
{"text": "Processor Brand:‎AMD"}
{"text": "Processor Count:‎1"}
{"text": "Computer Memory Type:‎DDR4 SDRAM"}
{"text": "Flash Memory Size:‎16"}
{"text": "Batteries:‎1 Lithium ion batteries required. (included)"}
{"text": "ASIN:B094681RZP"}
{"text": "Customer Reviews:4.3 out of 5 stars    46 ratings"}
{"text": "4.3 out of 5 stars"}
{"text": "Best Sellers Rank:#1,174 in Computers & Accessories (See Top 100 in Computers & Accessories)"}
{"text": "in Traditional Laptop Computers"}
{"text": "Date First Available:June 14, 2021"}
{"text": "Warranty & Support"}
{"text": "Amazon.com Return Policy:You may return any new computer purchased from Amazon.com that is "dead on arrival," arrives in damaged condition, or is still in unopened boxes, for a full refund within 30 days of purchase. Amazon.com reserves the right to test "dead on arrival" returns and impose a customer fee equal to 15 percent of the product sales price if the customer misrepresents the condition of the product. Any returned computer that is damaged through customer misuse, is missing parts, or is in unsellable condition due to customer tampering will result in the customer being charged a higher restocking fee based on the condition of the product. Amazon.com will not accept returns of any desktop or notebook computer more than 30 days after you receive the shipment. New, used, and refurbished products purchased from Marketplace vendors are subject to the returns policy of the individual vendor."}
{"text": "Manufacturer’s warranty can be requested from customer service. Click here to make a request to customer service."}

This is my jsonl file from Amazon, what is wrong here.
And what jsonl files are valid and what makes them invalid?

Thank you for the help!!!

1 Like

Damn I need some sleep. Thank you very much found the error!!!

3 Likes

Glad to see your actual issue was resolved.

What I actually do to debug is strip out most punctuation from the input text initially, and gradually reduce the elimination list to home into the offending bits.
Just my way to divide and conquer the issues.

2 Likes

Wow.
Syntax highlighting to the rescue, I guess :smiley:

2 Likes

Currently I am trying to implement the same in NodeJs but everytime I am getting 400 error and also I have tried using your jsonl file but still it is the same issue, can you please help me what is the issue here?

Nodejs code: openai.createFile(fs.readFileSync(path.join(__dirname, ‘/sample.jsonl’)), ‘questions’)

and also if I want to upload pdf file, what I have to do?