@sharpapi/sharpapi-node-summarize-text 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,240 @@
1
+ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Node.js Client")
2
+
3
+ # Text Summarization API for Node.js
4
+
5
+ ## 📝 Summarize long text into concise summaries — powered by SharpAPI AI.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@sharpapi/sharpapi-node-summarize-text.svg)](https://www.npmjs.com/package/@sharpapi/sharpapi-node-summarize-text)
8
+ [![License](https://img.shields.io/npm/l/@sharpapi/sharpapi-node-summarize-text.svg)](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
9
+
10
+ **SharpAPI Text Summarization** uses advanced AI to create concise, accurate summaries of long-form content. Perfect for articles, documents, reports, and more.
11
+
12
+ ---
13
+
14
+ ## 📋 Table of Contents
15
+
16
+ 1. [Requirements](#requirements)
17
+ 2. [Installation](#installation)
18
+ 3. [Usage](#usage)
19
+ 4. [API Documentation](#api-documentation)
20
+ 5. [Examples](#examples)
21
+ 6. [License](#license)
22
+
23
+ ---
24
+
25
+ ## Requirements
26
+
27
+ - Node.js >= 16.x
28
+ - npm or yarn
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ ### Step 1. Install the package via npm:
35
+
36
+ ```bash
37
+ npm install @sharpapi/sharpapi-node-summarize-text
38
+ ```
39
+
40
+ ### Step 2. Get your API key
41
+
42
+ Visit [SharpAPI.com](https://sharpapi.com/) to get your API key.
43
+
44
+ ---
45
+
46
+ ## Usage
47
+
48
+ ```javascript
49
+ const { SharpApiSummarizeTextService } = require('@sharpapi/sharpapi-node-summarize-text');
50
+
51
+ const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
52
+ const service = new SharpApiSummarizeTextService(apiKey);
53
+
54
+ const longText = `
55
+ Artificial intelligence (AI) has revolutionized numerous industries in recent years.
56
+ From healthcare to finance, AI-powered systems are helping organizations make better
57
+ decisions, automate complex processes, and improve customer experiences. Machine
58
+ learning algorithms can now analyze vast amounts of data in seconds, identifying
59
+ patterns that would take humans years to discover. As AI technology continues to
60
+ advance, we can expect even more transformative applications across all sectors
61
+ of the economy.
62
+ `;
63
+
64
+ async function summarizeContent() {
65
+ try {
66
+ // Submit summarization job
67
+ const statusUrl = await service.summarizeText(longText, 'English', 50);
68
+ console.log('Job submitted. Status URL:', statusUrl);
69
+
70
+ // Fetch results (polls automatically until complete)
71
+ const result = await service.fetchResults(statusUrl);
72
+ console.log('Summary:', result.getResultJson());
73
+ } catch (error) {
74
+ console.error('Error:', error.message);
75
+ }
76
+ }
77
+
78
+ summarizeContent();
79
+ ```
80
+
81
+ ---
82
+
83
+ ## API Documentation
84
+
85
+ ### Methods
86
+
87
+ #### `summarizeText(text: string, language?: string, maxLength?: number, context?: string): Promise<string>`
88
+
89
+ Summarizes the provided text into a concise version.
90
+
91
+ **Parameters:**
92
+ - `text` (string, required): The text content to summarize
93
+ - `language` (string, optional): The language of the text (default: 'English')
94
+ - `maxLength` (number, optional): Maximum length of summary in words (default: 100)
95
+ - `context` (string, optional): Additional context to guide summarization
96
+
97
+ **Returns:**
98
+ - Promise<string>: Status URL for polling the job result
99
+
100
+ **Example:**
101
+ ```javascript
102
+ const statusUrl = await service.summarizeText(
103
+ longArticle,
104
+ 'English',
105
+ 75,
106
+ 'Focus on key technological advances'
107
+ );
108
+ const result = await service.fetchResults(statusUrl);
109
+ ```
110
+
111
+ ### Response Format
112
+
113
+ The API returns the summarized text:
114
+
115
+ ```json
116
+ {
117
+ "summary": "AI has revolutionized industries by enabling data analysis and automation...",
118
+ "original_length": 423,
119
+ "summary_length": 50,
120
+ "compression_ratio": 0.12
121
+ }
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Examples
127
+
128
+ ### Basic Text Summarization
129
+
130
+ ```javascript
131
+ const { SharpApiSummarizeTextService } = require('@sharpapi/sharpapi-node-summarize-text');
132
+
133
+ const service = new SharpApiSummarizeTextService(process.env.SHARP_API_KEY);
134
+
135
+ const article = `
136
+ [Your long article content here...]
137
+ `;
138
+
139
+ service.summarizeText(article, 'English', 100)
140
+ .then(statusUrl => service.fetchResults(statusUrl))
141
+ .then(result => {
142
+ const summary = result.getResultJson();
143
+ console.log('Original length:', summary.original_length, 'words');
144
+ console.log('Summary length:', summary.summary_length, 'words');
145
+ console.log('Summary:', summary.summary);
146
+ })
147
+ .catch(error => console.error('Summarization failed:', error));
148
+ ```
149
+
150
+ ### Multi-Document Summarization
151
+
152
+ ```javascript
153
+ const service = new SharpApiSummarizeTextService(process.env.SHARP_API_KEY);
154
+
155
+ const documents = [
156
+ { title: 'AI Report 2024', content: '...' },
157
+ { title: 'Market Analysis', content: '...' },
158
+ { title: 'Tech Trends', content: '...' }
159
+ ];
160
+
161
+ const summaries = await Promise.all(
162
+ documents.map(async (doc) => {
163
+ const statusUrl = await service.summarizeText(doc.content, 'English', 50);
164
+ const result = await service.fetchResults(statusUrl);
165
+ return {
166
+ title: doc.title,
167
+ summary: result.getResultJson().summary
168
+ };
169
+ })
170
+ );
171
+
172
+ console.log('Document summaries:', summaries);
173
+ ```
174
+
175
+ ### Context-Aware Summarization
176
+
177
+ ```javascript
178
+ const service = new SharpApiSummarizeTextService(process.env.SHARP_API_KEY);
179
+
180
+ const technicalDoc = `[Long technical documentation...]`;
181
+
182
+ const statusUrl = await service.summarizeText(
183
+ technicalDoc,
184
+ 'English',
185
+ 100,
186
+ 'Focus on API endpoints and authentication methods'
187
+ );
188
+
189
+ const result = await service.fetchResults(statusUrl);
190
+ console.log('Technical summary:', result.getResultJson().summary);
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Use Cases
196
+
197
+ - **Content Curation**: Create summaries for news aggregation platforms
198
+ - **Research**: Quickly understand academic papers and research documents
199
+ - **Business Intelligence**: Summarize reports and market analyses
200
+ - **Email Management**: Generate summaries of long email threads
201
+ - **Documentation**: Create executive summaries of technical documents
202
+ - **Social Media**: Generate post previews from long-form content
203
+ - **E-learning**: Provide study summaries of educational materials
204
+
205
+ ---
206
+
207
+ ## API Endpoint
208
+
209
+ **POST** `/content/summarize`
210
+
211
+ For detailed API specifications, refer to:
212
+ - [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVa)
213
+ - [Product Page](https://sharpapi.com/en/catalog/ai/content-marketing-automation/summarize-text)
214
+
215
+ ---
216
+
217
+ ## Related Packages
218
+
219
+ - [@sharpapi/sharpapi-node-translate](https://www.npmjs.com/package/@sharpapi/sharpapi-node-translate) - Text translation
220
+ - [@sharpapi/sharpapi-node-paraphrase](https://www.npmjs.com/package/@sharpapi/sharpapi-node-paraphrase) - Text paraphrasing
221
+ - [@sharpapi/sharpapi-node-generate-keywords](https://www.npmjs.com/package/@sharpapi/sharpapi-node-generate-keywords) - Keyword extraction
222
+ - [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
223
+
224
+ ---
225
+
226
+ ## License
227
+
228
+ This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
229
+
230
+ ---
231
+
232
+ ## Support
233
+
234
+ - **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
235
+ - **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
236
+ - **Email**: contact@sharpapi.com
237
+
238
+ ---
239
+
240
+ **Powered by [SharpAPI](https://sharpapi.com/) - AI-Powered API Workflow Automation**
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@sharpapi/sharpapi-node-summarize-text",
3
+ "version": "1.0.0",
4
+ "description": "SharpAPI.com Node.js SDK for summarizing text",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "keywords": [
10
+ "sharpapi",
11
+ "ai-powered",
12
+ "ai capabilities",
13
+ "api",
14
+ "ai api",
15
+ "api integration",
16
+ "artificial intelligence",
17
+ "natural language processing",
18
+ "restful api",
19
+ "nodejs",
20
+ "software development",
21
+ "content analysis",
22
+ "text summarization",
23
+ "text processing"
24
+ ],
25
+ "author": "Dawid Makowski <contact@sharpapi.com>",
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "@sharpapi/sharpapi-node-core": "file:../sharpapi-node-core"
29
+ },
30
+ "devDependencies": {
31
+ "jest": "^29.7.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/sharpapi/sharpapi-node-summarize-text.git"
39
+ }
40
+ }
@@ -0,0 +1,30 @@
1
+ const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
2
+
3
+ /**
4
+ * Service for summarizing text using SharpAPI.com
5
+ */
6
+ class SharpApiSummarizeTextService extends SharpApiCoreService {
7
+ /**
8
+ * Generates a summarized version of the provided content.
9
+ * Perfect for generating marketing introductions of longer texts.
10
+ *
11
+ * @param {string} text
12
+ * @param {string|null} language
13
+ * @param {number|null} maxLength
14
+ * @param {string|null} voiceTone
15
+ * @param {string|null} context
16
+ * @returns {Promise<string>} - The status URL.
17
+ */
18
+ async summarizeText(text, language = null, maxLength = null, voiceTone = null, context = null) {
19
+ const data = { content: text };
20
+ if (language) data.language = language;
21
+ if (maxLength) data.max_length = maxLength;
22
+ if (voiceTone) data.voice_tone = voiceTone;
23
+ if (context) data.context = context;
24
+
25
+ const response = await this.makeRequest('POST', SharpApiJobTypeEnum.CONTENT_SUMMARIZE.url, data);
26
+ return this.parseStatusUrl(response);
27
+ }
28
+ }
29
+
30
+ module.exports = { SharpApiSummarizeTextService };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // sharpapi-node-summarize-text/src/index.js
2
+ const { SharpApiSummarizeTextService } = require('./SharpApiSummarizeTextService');
3
+
4
+ module.exports = {
5
+ SharpApiSummarizeTextService,
6
+ };