The ChatGPT application, based on a GPT-x large language model, is dramatically changing the way million of people do things. I had recently put together a short demo of programmatically analyzing a PDF file using the ChatGPT API with Python. I figured that the same program would work for a .txt file, but that was not the case.
So I set out to put together a demo that analyzes a .txt file. I eventually succeeded but there are lots of details that I still don’t completely understand.
While I was searching for examples on the Internet, I noticed that because AI development is so fast, the majority of examples I found were completely out of date and most didn’t even run.
Well, many hours later, I finally had a short demo up and running. But what was really interesting, and what took me so long, was the massive amounts of misleading out-of-date information I found on the Internet. ChatGPT, and applications based on Gemini (Google), Llama (Meta), Claude (Anthropic) and other LLMs, are changing with astonishing speed, which leads to the vast majority of information on the Internet being completely out of date.
Anyway, I have an existing OpenAI account and a couple of existing keys for use in programs that call the API. I created a text file document using the first couple of pages of the Wikipedia entry on the planet Venus. (I copy-pasted the text into Notepad and then saved it as venus.txt).
I wrote my demo using the Python language version of the OpenAI API. I slightly prefer working with Python rather than the JavaScript API when I’m experimenting. I prepped the program by issuing a “pip install openai” command.
Here’s an output of one run of my demo:
C:\Python\ChatGPT\QueryTextFile: python text_files_chatgpt.py Begin ChatGPT text file demo Reading file ./venus.txt The question is: What is an interesting fact about Venus? The answer is: An interesting fact about Venus is that **a day on Venus is longer than its year**. Venus takes about **243 Earth days to complete one rotation on its axis** (a Venusian day), but only **224.7 Earth days to orbit the Sun** (a Venusian year). This means that, on Venus, the sun rises and sets much less frequently than it does on Earth! Done C:\Python\ChatGPT\QueryTextFile:
The demo uses client.responses.create() which has replaced the older client.chat.completions.create() method. The key code fragment is:
. . .
input = [
{ "role": "developer",
"content": "You analyze a text file." },
{ "role": "user",
"content": file_content },
{ "role": "user",
"content": question },
],
. . .
So, essentially, the contents of the text file are sent as a message, then the query is sent as another message. This feels a bit sketchy but it seems to work.
I wanted to make sure that the query-PDF-file program was correctly pulling information from the PDF file, rather than using the GPT built-in knowledge of Venus that it learned during training (GPT uses the text of Wikipedia for training). I modified the source PDF file to include the fake sentence, “A little-known fact is that the surface of Venus is pink, not green.” And then a paragraph later I added a fake sentence, “Because Venus soil is pink, Venus is sometimes called the cotton candy planet.” When I reran the query program, the response was:
The answer is: An interesting fact about Venus is . . . . Another fun and less-known fact mentioned in your text: **the surface of Venus is pink, not green**. This is sometimes why Venus is called the "cotton candy planet."
So, indeed, the program was pulling from the source PDF document. Very nice.
The main takeaway is that AI via ChatGPT, Claude, and the others, is developing with blistering speed, which means that the Internet is littered with out-of-date and irrelevant examples (maybe even this one by the time you’re reading it.)

Pinball technology developed very quickly in the 1930s.
Left: This is the “Signal” machine from Bally, produced in 1934. There are no bumpers, no flippers, and no automatic scoring. The curious white things are gate switches. Balls are captured in the lane next to the gate switches. If a ball lands in the Signal hole at the top, each ball is in a switch gate lane advances one position to a higher score. The game was powered by a 6-volt battery (the 110v electrical cord in the image was a modification of the original machine).
Right: This is the “Time” machine from PAMCO (Pacific Amusement Company), produced in 1935. If a ball lands in the tube at the top of the machine, it falls into the hand of a clock and the hand rotates which will drop the ball into the first available hole. Different holes scored different points and gave extra balls to shoot.
Demo program:
# text_files_chatgpt.py
# query a text file
from openai import OpenAI
print("\nBegin ChatGPT text file demo ")
key = "sk-proj-_AX7bGTXUwg-qojh2T5Z2CVXrox" + \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + \
"_TbyJ6Pu3Ex8FqgDOFFjKPpbZ3HsmyLwIcOsIldlZd7npEA"
client = OpenAI(api_key=key)
fp = "./venus.txt" # text file
print("\nReading file " + fp)
with open(fp, "r", encoding="utf-8") as f:
file_content = f.read()
question = "What is an interesting fact about Venus?"
print("\nThe question is: ")
print(question)
response = client.responses.create(
model = "gpt-4.1",
input = [
{ "role": "developer",
"content": "You analyze the content of a text file." },
{ "role": "user",
"content": file_content },
{ "role": "user",
"content": question },
],
temperature = 0.2, # not creative
top_p = 1.0, # default max explore
max_output_tokens = 100,
)
print("\nThe answer is: ")
print(response.output_text)
print("\nDone ")

.NET Test Automation Recipes
Software Testing
SciPy Programming Succinctly
Keras Succinctly
R Programming
2026 Visual Studio Live
2025 Summer MLADS Conference
2026 DevIntersection Conference
2025 Machine Learning Week
2025 Ai4 Conference
2026 G2E Conference
2026 iSC West Conference
You must be logged in to post a comment.