#Passinng csv file to Openrouter API

9 messages · Page 1 of 1 (latest)

heady stump
#

I am trying to attach a csv file to API to ask question based on data present in the csv file. I am wondering how to do that. Currently I am converting the csv file to string using csv_text = df.to_string(index=False) and then passing to chatmessage

# Convert the DataFrame into a text format that can be used in prompts
csv_text = df.to_string(index=False)  # Converts to string without row indices

# Prepare a message to pass to the model
user_message = ChatMessage(
    role="user",
    content=f"Here is the data from my CSV:\n{csv_text}\n Who nominated Best Sound in the 1972 Academy Awards? Don't give me program instead analyze the data and give me result",
)

# Use the LLM to process the message
response = llm.chat([user_message])

Is there a way to attach the csv file itself to API? Also is there a way to get the plotting done by a particular LLM?, like in chatgpt we can ask it to analyse the data and then plot.

pseudo otter
rustic gyro
#

And for plotting you can give the LLM a tool. E.g. with a python executor.

heady stump
#

Thanks for the inputs.

rustic gyro
#

Oh and if your CSV is huge you can give it an except & let the LLM query it with the python tool. Works pretty well for analysis.

heady stump
#

You mean to say split the big file into chunks using python and then pass it into the LLM for answering a question? Do you have some documentation on how to do that that I can refer?

rustic gyro
#

No like only giving the first 5 lines to the LLM with a filename accessible from the python tool.

heady stump
#

Ah, Okay. First 5 rows of dataframe so that LLM can understand the structure of the data then use that information to generate appropriate python function to answer the question?

rustic gyro
#

Exactly. :)