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

Smita Chakraborty, PhD 0 Reputation points

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(


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

   temperature =0.1)

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
342 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 5,635 Reputation points

    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(
    0 comments No comments