Search code examples
pythonopenai-apigpt-3

How to use files in the Answer api of OpenAI


As finally OpenAI opened the GPT-3 related API publicly, I am playing with it to explore and discover his potential.

I am trying the Answer API, the simple example that is in the documentation: https://beta.openai.com/docs/guides/answers

I upload the .jsonl file as indicated, and I can see it succesfully uploaded with the openai.File.list() api.

When I try to use it, unfortunately, I always get the same error:

>>> openai.File.create(purpose='answers', file=open('example.jsonl') )
<File file id=file-xxx at 0x7fbc9eca5e00> JSON: {
  "bytes": 140,
  "created_at": 1637597242,
  "filename": "example.jsonl",
  "id": "file-xxx",
  "object": "file",
  "purpose": "answers",
  "status": "uploaded",
  "status_details": null
}

#Use the file in the API:
openai.Answer.create(
    search_model="ada", 
    model="curie", 
    question="which puppy is happy?", 
    file="file-xxx", 
    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_rerank=10,
    max_tokens=5,
    stop=["\n", "<|endoftext|>"]
)
<some exception, then>
openai.error.InvalidRequestError: File is still processing.  Check back later.

I have waited several hours, and I do not think this content deserve such a long wait... Do you know if it is a normal behaviour, or if I miss something?

Thanks


Solution

  • After a few hours (the day after) the file metadata status changed from uploaded to processed and the file could be used in the Answer API as stated in the documentation.

    I think this need to be better documented in the original OpenAI API reference.