Step-by-step: DeepSeek text generation with product data from the EAN-Search.org API
5 Feb 2025
DeepSeek is the new rival to ChatGPT, so let's see how we can use it to generate texts about products and generate prompts with factual product data.
To get the product data, we will use the EAN-Search.org barcode lookup API. To access DeepSeek, you can either use the DeepSeek API directly or you can use OpenRouter AI. DeepSeek is currently a bit overloaded and using OpenRouter AI has the added benefit that you can use their free tier to experiment with DeepSeek.
The first step is to obtain API tokens (also called API keys) for OpenRouter and EAN-Search. If you want to follow our example below on your own Linux box, you can put them into the environment variables OPENROUTER_API_TOKEN and EAN_SEARCH_API_TOKEN.
The second step is to create a Python virtual environment and install the API libraries. Since DeepSeek's API is compatible with OpenAI, we will be using the OpenAI Python library:
python3 -m venv deepseek-test cd deepseek-test source ./bin/activate pip install eansearch openai export OPENROUTER_API_TOKEN="..." export EAN_SEARCH_API_TOKEN="..."
As an example, let's assume you have an inventory of smartphones in stock and want to write blog posts about them to aid sales.
You could scan the barcodes,
type them in or use the EAN-Search.org API to search for the barcodes.
The Python code to generate the blog posts is rather similar to what we used with ChatGPT:
import os
from eansearch import EANSearch
from openai import OpenAI
# quickly set up both APIs
eansearch = EANSearch(os.environ.get("EAN_SEARCH_API_TOKEN"))
deepseek = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key = os.environ.get("OPENROUTER_API_TOKEN"))
# this is the EAN barcode number you scan, here a Samsung Galaxy S24+ 512GB
ean = "6095636137125"
# let's get the product data from ean-search.org
product = eansearch.barcodeSearch(ean, 1)
# now send the prompt to DeepSeek
response = deepseek.chat.completions.create(
model = "deepseek/deepseek-r1:free",
messages = [
{
"role": "user",
"content": "You are a tech writer. Please write a 6 paragraph blog post "
+ "pointing out the highlights of the product '"
+ product["name"] + "' from the product category '"
+ product["categoryName"] + "'"
}
]
)
# now print out all your product data with the generated description
print ("Products > " + product["categoryName"])
print ("<h1>" + product["name"] + " (EAN " + ean + ")</h1>")
print (response.choices[0].message.content)
Save the example code as deepseek.py and run it with
python3 ./deepseek.py
When I run it, the results that DeepSeek generates look decent and I don't see much of a difference between DeepSeek and ChatGPT, but judge for yourself and tune the prompt to your situation.
You might also be interested in this:
Using the EAN-Search API with ChatGPT