Building a “Summarize Text” Feature with the DeepSeek API

Idera Dev ToolsIdera Dev Tools
11 min read

Since their emergence, AI tools like the DeepSeek API have transformed how developers design experiences in their applications. From autocomplete suggestions to intelligent assistants, smart features are becoming essential rather than optional. Text summarization, or the ability to significantly shorten long content without taking away important information, is one such example.

For instance, let’s say that a user wants to quickly grasp the key points of an article, email, or report without reading every line. Text summarization would allow that user to do so in just a click or two.

As demand for intelligent summarization grows, so does the need for flexible tools that make integrating this functionality easy. That’s where DeepSeek API integration comes in. This API offers developers a simple, powerful, and versatile way to bring AI features into different applications.

In this article, you’ll learn how to build a custom “summarize text” feature using the DeepSeek API. You’ll also learn how to integrate it directly as a plugin within a WYSIWYG editor. Lastly, you’ll explore some tips for enhancing the UX as well as some things to consider when implementing summarization features.

Key Takeaways

  • Text summarization enhances readability and helps users digest content quickly.

  • The DeepSeek API allows developers to add natural language summarization with minimal effort and setup.

  • You can integrate DeepSeek into a WYSIWYG editor through a custom plugin.

  • Offer user flexibility in summary length and format for a better experience.

  • Protect user data by filtering and encrypting sensitive content before sending it to any AI service.

What Is the DeepSeek API?

The DeepSeek API is an AI-powered service that offers natural language processing (NLP) capabilities to developers. It’s similar to DeepSeek’s user-facing AI chatbot but for developers and application integration. It allows applications to understand, generate, and manipulate human language, making it useful for summarization, content writing, and the like.

Building large language models (LLMs) from scratch is a difficult and tedious task for most developers and organizations. Hence, platforms like DeepSeek make their APIs publicly available, and developers can interact with them through a simple API request. For instance, you can send a prompt, and the service returns a smart response (e.g., summary, paraphrase, explanation, etc.).

To better understand how DeepSeek’s API works, you should consider the following key technical parameters:

  • Input text: The raw content you want to summarize.

  • Max tokens: A limit on how many words or characters the summary will contain.

  • Temperature: Determines how “creative” or deterministic the response is. Ranging typically from 0 to 2, the higher the temperature, the better the creativity (at the cost of potential inaccuracy). Similarly, the lower the temperature (e.g., 0 or 0.25), the more precise (but more “boring”) the answer is. Generally, for coding or math tasks, you want to set this to 0.0. For more creative tasks, you should increase it to something greater than 1. If you want to learn more, browse this use case table from DeepSeek.

  • Top-p and presence_penalty: Optional values that help you fine-tune response tone or reduce repetition.

Whether you’re building a fun prototype or a full product, the DeepSeek API is a fast, scalable, and cost-effective solution. But what about the text summarization feature?

Why Add a “Summarize Text” Feature to Your App?

Summarization isn’t just a nice feature to have; it solves real problems in applications with content-heavy workflows. Users regularly encounter walls of text, such as blog posts like this, reports, support tickets, and chat logs. They usually want answers fast, so developers have responded by embedding summarization tools directly into user interfaces.

Without a “summarize text” feature, your users will have to read through every block of text in your application’s content. And that’s mostly alright, but for users who are pressed for time, it could seem like a hindrance. Furthermore, since popular platforms and apps are adopting text summarization today, modern users tend to look for this feature.

By integrating a text summarization feature, you give all users the ability to quickly digest information from your application’s content. As a developer, consider adding this feature when:

  • Your users deal with large blocks of user-generated or imported text.

  • You want to help users make faster decisions.

  • Application content tends to heavily increase over time (e.g., chat groups, forums), and users need to catch up easily.

  • You’re building tools for research, analysis, or reporting.

Normally, implementing this feature would require you to build an LLM yourself. Thankfully, you can integrate text summarization easily by using the DeepSeek API.

Implementing the “Summarize Text” Feature Using DeepSeek API

Building a text summarization feature with the DeepSeek API is simpler and faster than some would think. All you need is a DeepSeek API key, which you can get by signing up. You also need to have at least a bit of balance in your DeepSeek account.

Finally, there’s your choice of tech stack. This tutorial uses plain HTML and JavaScript, but implementing the same feature using frameworks like React is just as easy.

Step 1: Set up the DeepSeek API

Before anything else, sign up for access to the API. Once you have an account, retrieve your API key. You can then secure the API key using environment variables on your server (but for simplicity, we’ll keep it in the front end in this tutorial).

Step 2: Build the Front-End View and Logic

Now, you’ll need an HTML file for the view and some JavaScript for the logic. Start by inserting the following code into your HTML:

<!DOCTYPE html>
<html lang=”en”>

<head>
 <meta charset="UTF-8" />
 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 <meta name="viewport" content="width=device-width, initial-scale=1.0 " />

<title>Summarize Text with this WYSIWYG Editor</title>
 <! - Load Froala Editor CSS files. →
 <link href='https://cdn.jsdelivr.net/npm/froala-editor@4.3/css/froala_editor.pkgd.min.css' rel='stylesheet' type='text/css' />
</head>

<body>
 <h1>Text Summarizer</h1>
 <div id="editor">
 Paste or type text here…
 </div>
<! - Load Froala Editor JS files. →
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/froala-editor@4.3/js/froala_editor.pkgd.min.js'></script>
<script type="text/javascript" src="index.js"></script>

</body>
</html>

This file does the following:

  • Load the CSS stylesheet and the JS file for Froala Editor, which will contain the embedded “summarize text” feature.

  • Create the container for the editor, which is the div with id “editor.”

  • Load the JS file “index.js.”

Step 3: Set up the WYSIWYG Editor

Now, you’ll need to initialize the WYSIWYG editor by adding the following code into your JS file or script:

new FroalaEditor(‘#editor’, {
 toolbarButtons: [‘bold’, ‘italic’, ‘underline’, ‘|’, ‘summarize’],
 pluginsEnabled: [‘summarize’],
 heightMin: 300
});

This creates a new FroalaEditor instance in the “#editor” element. In the options, define some basic toolbar buttons along with a new “summarize” button, whose functionality you’ll create later. Lastly, the code specifies a minimum height for the editor.

Step 4: Create the Custom “Summarize Text” Plugin

It’s time to create the custom plugin. Paste the following code in your JS to define the “summarize” plugin:

FroalaEditor.PLUGINS.summarize = function (editor) {
 return {
 summarizeText: function() {
 const selectedText = editor.selection.text();

// Some error handling

if(!selectedText || selectedText.trim().length < 30){
 alert ('Please select at least 30 characters of text to summarize.');
 return;
 }

// Load your API key
 // Be sure to replace this with your actual key (preferably, store it in a secure directory/file)
 const apiKey = 'YOUR_API_KEY';
 const endpoint = 'https://api.deepseek.com/v1/chat/completions';

// Add a bit of text to inform the user about the process
 editor.html.insert('<p><em>Summarizing content. Please wait a bit…</em></p>');

fetch(endpoint, {
 method: 'POST',
 headers: {
 'Content-Type': 'application/json',
 'Authorization': `Bearer ${apiKey}`
 },
 body: JSON.stringify({
 model: 'deepseek-chat',
 messages: [
 // Here's where your prompt should be
 {role: 'system', content: 'Summarize the following content in 5 sentences or less.'},
 {role: 'user', content: selectedText}
 ],
 // Customize the temperature and max tokens
 temperature: 0.75,
 max_tokens: 500
 })
 }).then(response => response.json())
 .then(data => {
 // Replace the editor's content with the summary
 const summary = data.choices?.[0]?.message?.content || 'No summary returned.';
 editor.html.set('');
 editor.html.insert(`<p><h2>Summary:</h2> ${summary}</p>`);
 }).catch(error => {
 console.error('DeepSeek API Error: ', error);
 editor.html.insert('<p style="color:red;">Summary failed. Please try again.</p>');
 });
 }
 };
};

This code snippet defines the “summarize” plugin and its “summarizeText” function. Here’s what it does in detail:

  • Get the selected (highlighted) text in the editor and store it in a constant.

  • Check for correctness (minimum number of characters).

  • Define the API key and the DeepSeek endpoint of your choice.

  • Add a text-based loading indicator.

  • Make the API call and define the model, prompt, and options.

  • Insert the resulting summary (if successful) into the editor.

After you define the custom plugin, you still have to link an icon for it and register it as a command. Since the code uses “summarize” for the toolbar button, the associated command should also have the “summarize” name. To wrap up the coding process, add the following to your JS:

FroalaEditor.DefineIcon(‘summarize’, { NAME: ‘book-open’, SVG_KEY: ‘insert’ });

FroalaEditor.RegisterCommand('summarize', {
 title: 'Summarize Text',
 icon: 'summarize',
 undo: true,
 focus: true,
 plugin: 'summarize',
 callback: function() {
 this.summarize.summarizeText();
 }
});

This snippet defines an icon for the summarization feature and then registers the command and links it with the “summarize” plugin from earlier.

Step 5: Run the Application

Once you link the plugin with the toolbar button, you’re done! Run the application using a browser, and you should see something similar to the following image.

This contains the title “Text Summarizer” and the editor instance. Notice how in the toolbar, we can see the three built-in buttons along with a new fourth one. You should then replace the initial text with something else, like this sample short story:

This example tells the story of a curious duck who ventures farther from safety, learning and growing in the process. To see if the summarizer can function correctly, select the entire story and click the “Summarize” button. Afterwards, you should see something similar to the following:

In this example, the summarizer from DeepSeek’s API was able to correctly distill the story into 5 sentences. This follows the prompt that was set, which stated to summarize the content in no more than 5 sentences. At this point, you now have a decent start to building something more with a text summary feature and a WYSIWYG editor.

Tips for Enhancing the UX

To improve user experience from “working” to “great,” consider adding the following features to your AI-powered text summarization:

  • Let users choose summary length. Provide dropdowns or buttons like “Short (1–2 lines),” “Medium,” or “Detailed.” This way, your users will get to choose the level of detail they want from the summary.

  • Add copy or download buttons. Summaries often become reusable snippets or notes. For example, users can paste summaries into an email, save them into a note-taking app, or attach them to a report. By adding a “Copy” or “Download” button, you allow users to quickly grab the text without needing to manually copy or type it.

  • Use subtle animations or loading indicators. This manages expectations while the API processes the request. Without animations or a loading indicator, your users might think that the feature doesn’t work.

  • Let users edit the summary. Since AI is never perfect and could contain mistakes, your users should have the ability to tweak the summary. For example, the output might sound too formal or overly simplified, or it might lack important details. By making the summary editable, you allow users to quickly personalize or improve the output to suit their intent better.

Best Practices and Considerations

When using DeepSeek or any LLM-based API, keep these points in mind to help ensure security, performance, and scalability:

  • Monitor token usage. LLMs charge based on token count (roughly a word or sub-word). The longer your inputs and outputs, the more expensive the request.

  • Keep prompts clean. Avoid inconsistent phrasing or irrelevant instructions to allow for more focused summaries or output. If you must, test out different instructions for one input text and pick the one that gives the most consistent or accurate answer.

  • Protect sensitive data. Never send passwords, financial details, or personally identifiable information (PII) unless necessary and encrypted or filtered out. Furthermore, keep your API keys in the back end, preferably stored in a .env file.

  • Cache common results. If multiple users summarize the same content (e.g., in chat groups), store the result locally or in a cache. Doing so would significantly improve response time and cost efficiency. By generating the summary once and storing it into the server or shared memory store, your app won’t have to call the DeepSeek API each time.

Real-World Use Cases

Summarization can fit seamlessly into a wide range of applications:

  • News aggregators can provide condensed story previews.

  • Messaging apps or communication tools can help users catch up on long threads without scrolling up too many times.

  • Documentation tools can auto-generate summaries for long articles or content.

  • Note-taking apps can turn meeting minutes into action points immediately.

  • AI writing tools can help users refine their own drafts through summaries.

Conclusion

Adding a summarization feature shouldn’t take up all your time and resources. Thanks to DeepSeek’s API, developers can implement accurate and scalable summarization features quickly and easily. This helps you change how users consume content, giving them more productivity and convenience.

Integrating the DeepSeek API into your application is fast and simple. Once you’re done with that, experiment with prompts and test different summary lengths and formats. In the end, you should go with the combination of parameters that works best for your use case.

If you want to take things further, try summarizing content from pasted URLs or summarizing conversations into topic-based chunks. You can also try adding multilingual summaries or maybe even a plagiarism or generic content detector to improve quality. Just make sure that as you explore AI-powered features, you continue to prioritize thoughtful implementation and user trust. Happy coding!

This article was originally published on the Froala blog.

0
Subscribe to my newsletter

Read articles from Idera Dev Tools directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Idera Dev Tools
Idera Dev Tools

Idera, Inc.’s portfolio of Developer Tools include high productivity tools to develop applications using powerful and scalable technology stacks.