Author: Ksenia Baidina
Originally published in the direction of artificial intelligence.
There are many articles on how students use chatgpt to perform their tasks – and what the professors should do with it. Personally, I think that professors should encourage this (if you can't beat them, join them), but this is not the subject of this article.
I want to notice that professors can also use chatgpt to manage their own “homework” more efficient management. Creating and assessing tasks can be tedious, monotonous – and sometimes even annoying. In this article, I will share how I use the API CHATPPT interface to automate the generation of homework and assess students' applications.
Why the API interface, not just a regular chat?
You can do all this with a chat interface, but there is a problem: scalability. It works well if you create one task or evaluate several answers. But when you have many students and many tasks, everything manually becomes too time consuming and inefficient.
Configure API CHATGPT
Let's start by configuring access to the API ChatgPT interface. If you have already done this, you can skip this part.
To use the API interface, you need the API key and billing configuration, because the API is not free. Here's how to start:
- Create OpenAI account
- Go to the “API keys” section and click “Create a new secret key.” You will use this key later to authenticate your demands.

- Go to Reckoning Section and add funds to your account. Adding USD 10-20 is enough to start.

Now you are ready to use the API interface.
Generate
In this section I will show how I generate homework using chatgpt.
But first a quick review of my approach. I teach data analysis, and my typical task includes a set of data with a set of wide, open questions to answer. This format encourages critical thinking and gives students a place for creativity.
To generate every task, I use:
- Lecture materials in PDF presentation format
- Data set, usually in CSV or Excel format
Based on this input data, I use chatgpt to create a task. Now let me go through the code.
First, import all necessary libraries and insert the API key from the previous section.
import openai
import PyPDF2
import nbformatimport pandas as pd
openai.api_key = "YOUR_API_KEY_HERE"
Since the assignment is based on slides and PDF data in CSV format, the next step is to load these files and are separated by the text. API CHATGPT works with entering the text, so before sending them you must convert all materials to ordinary text.
The following code reads PDF presentations. Remember that he does not intercept charts or images. It was not a problem for me, but depending on the content you work with, it may be a limitation.
def extract_text_from_pdf(pdf_path):
text = ""
try:
with open(pdf_path, "rb") as file:
reader = PyPDF2.PdfReader(file)
for page in reader.pages:
text += page.extract_text()
except Exception as e:
print(f"Error reading PDF: {e}")
return text
If you have many presentations for one task, you can combine them into one text block.
combined_text = ""pdf_paths = ("Presentation1.pdf", "Presentation2.pdf")
for pdf_path in pdf_paths:
pdf_text = extract_text_from_pdf(pdf_path)
if pdf_text:
combined_text += pdf_text + "n"
And prepare your data to send to chatgpt.
data_path = 'data.csv'
csv_data = pd.read_csv(data_path)
csv_data_summary = csv_data.head(10).to_string()
Then create a function that sends a request to the API ChatGPT interface.
def generate_homework(pdf_text, csv_data_summary, prompt):
full_prompt = (
f"{prompt}nn"
f"Presentation Content: {pdf_text(:10000)}nn"
f"Data:n{csv_data_summary}nn"
)try:
response = openai.chat.completions.create(
model='o3-mini', # "gpt-4o-mini"
messages=({"role": "user",
"content": full_prompt}),
temperature = 0.25
)
return response.choices(0).message.content
except Exception as e:
print(f"Error communicating with ChatGPT API: {e}")
return None
Here's how it works, step by step:
- The function adopts lecture materials, data set sample and prompting (more details about the poem in the next part).
- Then it connects the input data in
full_prompt
. - As a failure, I cut the presentation content of up to 10,000 characters to avoid crossing the input boundaries.
- Finally, the function sends a poem to API CHATGPT. You can use different models – I use GPT-4O mini For this example.
Now for the most interesting and most important part – hints. The quality of the output depends largely on how you formulate your instructions, so it's definitely worth spending time to improve the hints.
Below I will share the monitor I use. If you have ideas to improve this, you can share them in the comments!
In my monitor and:
- Ask ChatgPT to create open questions and encourage you to tell stories because I want to give students more space for creativity
- Enter an example question as a reference
- Clearly instruct it to focus on lecture materials to avoid generating insignificant questions
prompt = """
I am a university professor teaching a course on data analytics and statistics using Python.I have a dataset with e-commerce transaction data. The dataset includes the following fields:
UserId, TransactionId, TransactionTime, ItemCode, ItemDescription, NumberOfItemPurchased, CostPerItem, Country.
I will upload a PDF containing the lecture materials.
Based on the concepts and materials covered in the lecture, please generate five assignment questions
for students working with this dataset.
The questions should:
- Be moderately open-ended (not too specific), to encourage critical thinking and analytical reasoning.
- Be clearly worded and suitable for university-level students.
- Encourage storytelling through data, not just coding.
- Align with topics from the lecture (e.g., data cleaning, descriptive statistics, visualizations,
group analysis, temporal trends).
Example (for reference):
“What can you tell about the distribution and descriptive statistics of the variables from the dataset?”
"""
Finally, she is ready to collect everything.
result = generate_homework(combined_text, csv_data_summary, prompt)
Here is an example of the output obtained:
Here are five assignment questions designed to encourage critical thinking
and analytical reasoning while working with the e-commerce transaction dataset:1. **Descriptive Statistics and Customer Insights**:
"Using descriptive statistics, analyze the purchasing behavior of users in the dataset.
What insights can you draw about the average number of items purchased and the average cost per item?
Discuss how these metrics might vary across different countries and what implications this could have for marketing strategies."
2. **Temporal Trends Analysis**:
"Examine the transaction data over time. Identify any temporal trends in purchasing behavior,
such as seasonal spikes or declines in sales. How might these trends inform
inventory management and promotional strategies for the e-commerce platform?"
3. **Data Cleaning and Quality Assessment**:
"Reflect on the importance of data cleaning in your analysis.
Identify potential issues in the dataset (e.g., missing values, outliers) and propose
methods to address these issues. How might these data quality concerns impact your findings and the overall analysis?"
4. **Correlation and Customer Segmentation**:
"Investigate the relationship between the number of items purchased and the total cost of transactions.
What correlation do you observe, and what does it suggest about customer behavior?
Based on your findings, propose a segmentation strategy for targeting different customer groups."
5. **Visualization and Storytelling**:
"Create visualizations that effectively communicate key insights from the dataset.
Choose at least two different types of visualizations (e.g., histograms, bar charts, line graphs) to represent your findings.
How do these visualizations help tell the story of customer purchasing behavior, and what actionable insights can be derived from them?"
In my case, the results look pretty good. I usually make some corrections and remove too detailed instructions to give students more freedom in approaching the task.
Assessment tasks
In this section I will explain how I assess homework using chatgpt.
Only a summary: students receive a set of data and a set of questions, and they send their answers in Python notebooks, including comments explaining their reasoning.
Let's review the code step by step again.
First of all, Python notebooks must be converted to ordinary text – as before with PDF.
def extract_notebook_content(notebook_path):
try:
with open(notebook_path, "r", encoding="utf-8") as file:
notebook = nbformat.read(file, as_version=4)content = ()
for cell in notebook.cells:
if cell.cell_type == "code":
content.append("### Code and comments:n" + cell.source.strip())
elif cell.cell_type == "markdown":
content.append("### Comments:n" + cell.source.strip())
return "nn".join(content)
except Exception as e:
print(f"Error reading notebook {notebook_path}: {e}")
return None
The next step is to prepare students' applications for chatgpt – but this part turned out to be more difficult than expected.
At the beginning I tried to individually assess the work of each student, but Chatgpt gave almost everyone similar grades and tried to distinguish between strong reports from the weaker ones.
To solve this, I started to group reports in a bucket of about five. I manually divided students into buckets to make sure that work in each bucket was easy to compare. This is a simple trick that actually worked.
Another challenge is to make sure that chatgpt clearly understands what the work of every student begins. If this is not clearly defined, it may omit or overlook some students. All used names are fictitious, just in case.
names = ("Clara", "Malik", "Sofia", "Evan", "Leila")notebook_contents = {}
for name in names:
notebook_contents(name) = extract_notebook_content(name+".ipynb")
Once again, there is a function of sending a request to API CHATGPT – it is very similar to described earlier.
def generate_feedback(task_description, csv_data_summary, notebook_content, prompt):
full_prompt = (
f"Task Description: {task_description}nn"
f"Data:n{csv_data_summary}nn"
f"Student Notebook Content (Truncated):n{notebook_content}nn"
f"{prompt}nn"
) try:
response = openai.chat.completions.create(
model="gpt-4o-mini",
messages=({"role": "user", "content": full_prompt}),
temperature = 0.25
)
return response.choices(0).message.content
except Exception as e:
print(f"Error communicating with ChatGPT API: {e}")
return None
This request includes:
- Description of the task (generated earlier, with several small corrections)
- Data set sample (the same as in the previous section)
- The content of the students' notebook, converted to ordinary text
Here is the description of the task I use:
task_description = """
In this assignment, you're going to do customer analysis for e-commerce store. Data:
Transactions data for an e-commerce store. You'll find the dataset attached to the assignment.
Questions:
1. Identify potential issues in the dataset (e.g., missing values, outliers) and clean the data.
2. Using descriptive statistics, analyze the purchasing behavior of users in the dataset.
What insights can you draw about the average number of items purchased and the average cost per item?
Discuss how these metrics might vary across different countries and what implications this could have.
3. Examine the transaction data over time. Identify any temporal trends in purchasing behavior,
such as seasonal spikes or declines in sales.
4. Investigate the relationship between the number of items purchased and the total cost of transactions.
What correlation do you observe, and what does it suggest about customer behavior?
Format:
Submit Python notebook with interpretation of the results.
"""
And as before, the most difficult part is to write hints.
To do this right, I had to view a few students' applications myself to define clear classification criteria and identify typical errors that should lead to point deductions. This step is necessary – you must clearly explain how the assessment should work so that ChatgPT can reflect your logic.
Here are some fast strategies that helped:
- I attach the names of students to make sure that chatgpt does not skip anyone.
- I provide detailed instructions for what students are expected (e.g. pure protruding values, correct data processing, explain the results, etc.).
- I define the specific criteria for point deductions – what criminal errors and how much.
At the beginning I noticed that the same student application can receive very different grades every time I was prompting. I have reduced this variability, facilitating the assessment criteria, and the instructions are more structured – but there are still some changes.
To deal with this, I added some additional elements to the hints:
- CHATGPT please provide his own level of trust in every class. If trust is low or medium, I check the application by hand.
- I am also asking for justification Ratings, so I can check and review everything that seems.
You can also use the last part – justification for the assessment – to see common mistakes that students make and take care of them in future lectures.
Here is the final version of the prompt I use. If you have any suggestions for its improvement, I will gladly hear them!
prompt = """
You are a university professor evaluating student assignments.
You will receive submissions from several students in the following format:
- Each student’s work starts with: "WORK OF START"
- And ends with: "WORK OF END"The students are: Clara, Malik, Sofia, Evan, Leila
Assignment requirements:
Students need to:
- Remove outliers from the dataset
- Aggregate data by customer
- Calculate and interpret mean, median, and variance for all variables
- Analyze correlation coefficients
- Provide descriptive statistics by country
Students must interpret and explain their results (e.g., significance of descriptive statistics,
meaning of correlations, behavior differences by country).
Grading criteria:
- Maximum is 10 points
- Deduct 2 points: No explanations for statistics, correlations, or behavior differences
- Deduct 1 point: Outliers not removed
- Deduct 2 points: Data not aggregated by customer
- Deduct 2 points for each unanswered question
- Deduct 4 points: no description or insights provided
- Give 1 extra point: Extra analysis (e.g., statistical tests, clustering)
Instructions:
For each student, give:
- Name
- Final grade and your level of confidence in this grade.
- 5 concise bullet points justifying the grade (max total: 500 characters)
After assigning the grade, re-check the instructions and adjust the grade if needed.
Be strict, fair, and brief.
"""
Here is an example of what the results look like.
### Student: Clara
- **Final Grade:** 6/10 (Confidence: Medium)
- **Justifications:**
- Outliers were removed appropriately.
- Data was aggregated by customer.
- Mean, median, and variance were calculated, but explanations were insufficient.
- Correlation coefficients were analyzed, but interpretations were lacking.
- Descriptive statistics were provided, but comparisons across countries were incomplete.
Final thoughts
Let's summarize everything. Here is my main toasle:
- Generating homework It turns out that it is quite simple and easy to start.
- ShadingHowever, it requires more effort if you want chatgpt to give consistent and reliable results.
Some practical tips:
- Look through a few students' applications to define clear assessment criteria – what you want to see and what deserves deduction
- Group reports for small parties and make sure that each party contains reports with clearly different levels of quality. This helps ChatgPT better assess and distinguish between them.
I still go through applications and adapt the grades if necessary, but ChatgPT really helps to improve the process.
Thanks for reading! I hope you considered it helpful. If you have any questions or comments, you can share them below – I will gladly discuss them.
Published via AI