How to pass a Excel sheet as part of a prompt to OpenAI LLM?

Smita Chakraborty, PhD 0 Reputation points
2023-05-11T09:31:49.4866667+00:00

I have a set of texts ("descriptions") for various news items in a csv/xlsx file which I want to pass to Azure OpenAI LLM to categorize. Is there a way to pass this file in the prompt? For now, I send 1-2 descriptions in the prompt as text, not as a list of arguments.

My code is this:

 response = openai.Completion.create(

   engine="text-davinci-003",

   prompt="<command here> \n\n <description 1:...\n\n description 2:...>",

   temperature =0.1)

display(response)
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,119 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 13,070 Reputation points
    2023-05-13T14:27:28.9833333+00:00

    First Read the Excel sheet (you can use a library in Python to read the contents of the Excel sheet into a DataFrame. Assuming you have the sheet data in a variable called df, you can extract the descriptions column using descriptions = df['column_name'], where 'column_name' is the name of the column containing the descriptions.

    Convert the descriptions into a format suitable for including in the prompt. You can create a string that concatenates all the descriptions, separating them with appropriate delimiters (e.g., newlines or commas) to distinguish between different descriptions.

    descriptions_text = '\n\n'.join(descriptions)
    
    1. Construct the prompt
    prompt = f"<command here> \n\n{descriptions_text}"
    
    1. Pass the prompt to OpenAI API
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=prompt,
        temperature=0.1
    )
    
    
    0 comments No comments