@edpear/sdk 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,239 @@
1
+ # EdPear SDK
2
+
3
+ JavaScript/TypeScript SDK for EdPear - AI-powered educational components.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @edpear/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```javascript
14
+ const { EdPearClient } = require('@edpear/sdk');
15
+
16
+ const client = new EdPearClient({
17
+ apiKey: process.env.EDPEAR_API_KEY
18
+ });
19
+
20
+ // Analyze an image
21
+ const result = await client.analyzeImage({
22
+ image: base64Image,
23
+ prompt: "Analyze this textbook page and explain the main concepts"
24
+ });
25
+
26
+ console.log(result.result);
27
+ ```
28
+
29
+ ## API Reference
30
+
31
+ ### EdPearClient
32
+
33
+ #### Constructor
34
+
35
+ ```javascript
36
+ const client = new EdPearClient({
37
+ apiKey: string, // Required: Your EdPear API key
38
+ baseURL?: string // Optional: API base URL (default: https://api.edpear.com)
39
+ });
40
+ ```
41
+
42
+ #### Methods
43
+
44
+ ##### analyzeImage(request)
45
+
46
+ Analyze an image using EdPear's Vision AI.
47
+
48
+ **Parameters:**
49
+ - `request.image` (string): Base64 encoded image
50
+ - `request.prompt` (string): Analysis prompt
51
+ - `request.maxTokens` (number, optional): Maximum tokens in response (default: 1000)
52
+ - `request.temperature` (number, optional): Response creativity (0-1, default: 0.7)
53
+
54
+ **Returns:** Promise<VisionResponse>
55
+
56
+ **Example:**
57
+ ```javascript
58
+ const result = await client.analyzeImage({
59
+ image: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...',
60
+ prompt: 'Create a study guide from this textbook page',
61
+ maxTokens: 1200,
62
+ temperature: 0.7
63
+ });
64
+
65
+ console.log(result.result);
66
+ console.log(`Credits used: ${result.creditsUsed}`);
67
+ ```
68
+
69
+ ##### getStatus()
70
+
71
+ Get account status and remaining credits.
72
+
73
+ **Returns:** Promise<{credits: number, user: any}>
74
+
75
+ **Example:**
76
+ ```javascript
77
+ const status = await client.getStatus();
78
+ console.log(`Credits remaining: ${status.credits}`);
79
+ ```
80
+
81
+ ## Types
82
+
83
+ ### VisionRequest
84
+
85
+ ```typescript
86
+ interface VisionRequest {
87
+ image: string; // Base64 encoded image
88
+ prompt: string; // Analysis prompt
89
+ maxTokens?: number; // Maximum tokens (optional)
90
+ temperature?: number; // Response creativity 0-1 (optional)
91
+ }
92
+ ```
93
+
94
+ ### VisionResponse
95
+
96
+ ```typescript
97
+ interface VisionResponse {
98
+ success: boolean; // Request success status
99
+ result: string; // Analysis result
100
+ creditsUsed: number; // Credits consumed
101
+ remainingCredits: number; // Credits remaining
102
+ processingTime: number; // Processing time in ms
103
+ }
104
+ ```
105
+
106
+ ## Examples
107
+
108
+ ### Basic Image Analysis
109
+
110
+ ```javascript
111
+ const fs = require('fs');
112
+ const { EdPearClient } = require('@edpear/sdk');
113
+
114
+ const client = new EdPearClient({
115
+ apiKey: process.env.EDPEAR_API_KEY
116
+ });
117
+
118
+ async function analyzeTextbook() {
119
+ // Read image file
120
+ const imageBuffer = fs.readFileSync('./textbook-page.jpg');
121
+ const base64Image = imageBuffer.toString('base64');
122
+
123
+ // Analyze image
124
+ const result = await client.analyzeImage({
125
+ image: base64Image,
126
+ prompt: "Analyze this textbook page and create a study guide with key concepts, formulas, and practice questions."
127
+ });
128
+
129
+ console.log('Study Guide:');
130
+ console.log(result.result);
131
+ console.log(`\nCredits used: ${result.creditsUsed}`);
132
+ }
133
+ ```
134
+
135
+ ### Batch Processing
136
+
137
+ ```javascript
138
+ async function analyzeMultiplePages(imagePaths, subject) {
139
+ const results = [];
140
+
141
+ for (const imagePath of imagePaths) {
142
+ const imageBuffer = fs.readFileSync(imagePath);
143
+ const base64Image = imageBuffer.toString('base64');
144
+
145
+ const result = await client.analyzeImage({
146
+ image: base64Image,
147
+ prompt: `Analyze this ${subject} page and extract key concepts, formulas, and examples.`
148
+ });
149
+
150
+ results.push(result);
151
+
152
+ // Add delay to avoid rate limiting
153
+ await new Promise(resolve => setTimeout(resolve, 1000));
154
+ }
155
+
156
+ return results;
157
+ }
158
+ ```
159
+
160
+ ### Error Handling
161
+
162
+ ```javascript
163
+ async function safeAnalyze(image, prompt) {
164
+ try {
165
+ const result = await client.analyzeImage({ image, prompt });
166
+ return result;
167
+ } catch (error) {
168
+ if (error.message.includes('Invalid API key')) {
169
+ console.error('Please check your API key');
170
+ } else if (error.message.includes('Insufficient credits')) {
171
+ console.error('Please add more credits to your account');
172
+ } else {
173
+ console.error('Analysis failed:', error.message);
174
+ }
175
+ throw error;
176
+ }
177
+ }
178
+ ```
179
+
180
+ ## Use Cases
181
+
182
+ ### Educational Content Analysis
183
+
184
+ - **Textbook Pages**: Extract key concepts, formulas, and examples
185
+ - **Handwritten Notes**: Convert to structured, searchable content
186
+ - **Diagrams**: Analyze and explain complex diagrams
187
+ - **Charts**: Extract data and insights from educational charts
188
+
189
+ ### Study Material Generation
190
+
191
+ - **Study Guides**: Create comprehensive study materials
192
+ - **Quiz Generation**: Generate questions from content
193
+ - **Summaries**: Create concise summaries of long content
194
+ - **Flashcards**: Generate flashcards from educational material
195
+
196
+ ### Learning Assessment
197
+
198
+ - **Content Understanding**: Assess student understanding of material
199
+ - **Progress Tracking**: Track learning progress over time
200
+ - **Personalized Learning**: Adapt content to individual needs
201
+
202
+ ## Best Practices
203
+
204
+ ### Image Preparation
205
+
206
+ - Use high-quality images (minimum 300x300 pixels)
207
+ - Ensure good contrast and readability
208
+ - Avoid heavily compressed images
209
+ - Use standard formats (JPEG, PNG)
210
+
211
+ ### Prompt Engineering
212
+
213
+ - Be specific about what you want analyzed
214
+ - Include context about the subject matter
215
+ - Ask for structured output when needed
216
+ - Use clear, educational language
217
+
218
+ ### Rate Limiting
219
+
220
+ - Add delays between requests (1-2 seconds)
221
+ - Monitor your credit usage
222
+ - Use batch processing for multiple images
223
+ - Implement retry logic for failed requests
224
+
225
+ ## Error Codes
226
+
227
+ | Error | Description | Solution |
228
+ |-------|-------------|----------|
229
+ | 401 | Invalid API key | Check your API key |
230
+ | 402 | Insufficient credits | Add credits to your account |
231
+ | 400 | Bad request | Check your request parameters |
232
+ | 429 | Rate limited | Reduce request frequency |
233
+ | 500 | Server error | Try again later |
234
+
235
+ ## Support
236
+
237
+ - Documentation: [https://docs.edpear.com](https://docs.edpear.com)
238
+ - Support: [support@edpear.com](mailto:support@edpear.com)
239
+ - GitHub Issues: [https://github.com/edpear/sdk/issues](https://github.com/edpear/sdk/issues)
@@ -0,0 +1,39 @@
1
+ export interface VisionRequest {
2
+ image: string;
3
+ prompt: string;
4
+ maxTokens?: number;
5
+ temperature?: number;
6
+ }
7
+ export interface VisionResponse {
8
+ success: boolean;
9
+ result: string;
10
+ creditsUsed: number;
11
+ remainingCredits: number;
12
+ processingTime: number;
13
+ }
14
+ export interface EdPearConfig {
15
+ apiKey: string;
16
+ baseURL?: string;
17
+ }
18
+ export declare class EdPearClient {
19
+ private apiKey;
20
+ private baseURL;
21
+ constructor(config: EdPearConfig);
22
+ /**
23
+ * Analyze an image using EdPear's Vision AI
24
+ * @param request - The vision request containing image and prompt
25
+ * @returns Promise<VisionResponse>
26
+ */
27
+ analyzeImage(request: VisionRequest): Promise<VisionResponse>;
28
+ /**
29
+ * Get account status and remaining credits
30
+ * @returns Promise<{credits: number, user: any}>
31
+ */
32
+ getStatus(): Promise<{
33
+ credits: number;
34
+ user: any;
35
+ }>;
36
+ }
37
+ export declare function createEdPearClient(apiKey: string, baseURL?: string): EdPearClient;
38
+ export default EdPearClient;
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,YAAY;IAKhC;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IA2BnE;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,CAAC;CAa3D;AAGD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,CAEjF;AAGD,eAAe,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EdPearClient = void 0;
7
+ exports.createEdPearClient = createEdPearClient;
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class EdPearClient {
10
+ constructor(config) {
11
+ this.apiKey = config.apiKey;
12
+ this.baseURL = config.baseURL || 'https://api.edpear.com';
13
+ }
14
+ /**
15
+ * Analyze an image using EdPear's Vision AI
16
+ * @param request - The vision request containing image and prompt
17
+ * @returns Promise<VisionResponse>
18
+ */
19
+ async analyzeImage(request) {
20
+ try {
21
+ const response = await axios_1.default.post(`${this.baseURL}/api/vision`, request, {
22
+ headers: {
23
+ 'Content-Type': 'application/json',
24
+ 'x-api-key': this.apiKey,
25
+ },
26
+ });
27
+ return response.data;
28
+ }
29
+ catch (error) {
30
+ if (error.response?.status === 401) {
31
+ throw new Error('Invalid API key. Please check your EdPear API key.');
32
+ }
33
+ else if (error.response?.status === 402) {
34
+ throw new Error('Insufficient credits. Please add more credits to your account.');
35
+ }
36
+ else if (error.response?.status === 400) {
37
+ throw new Error(`Bad request: ${error.response.data.error}`);
38
+ }
39
+ else {
40
+ throw new Error(`API request failed: ${error.message}`);
41
+ }
42
+ }
43
+ }
44
+ /**
45
+ * Get account status and remaining credits
46
+ * @returns Promise<{credits: number, user: any}>
47
+ */
48
+ async getStatus() {
49
+ try {
50
+ const response = await axios_1.default.get(`${this.baseURL}/api/user/status`, {
51
+ headers: {
52
+ 'x-api-key': this.apiKey,
53
+ },
54
+ });
55
+ return response.data;
56
+ }
57
+ catch (error) {
58
+ throw new Error(`Failed to get account status: ${error.message}`);
59
+ }
60
+ }
61
+ }
62
+ exports.EdPearClient = EdPearClient;
63
+ // Convenience function for quick setup
64
+ function createEdPearClient(apiKey, baseURL) {
65
+ return new EdPearClient({ apiKey, baseURL });
66
+ }
67
+ // Default export
68
+ exports.default = EdPearClient;
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAmFA,gDAEC;AArFD,kDAA6C;AAsB7C,MAAa,YAAY;IAIvB,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,wBAAwB,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,OAAsB;QACvC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAkC,MAAM,eAAK,CAAC,IAAI,CAC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ED,uCAAuC;AACvC,SAAgB,kBAAkB,CAAC,MAAc,EAAE,OAAgB;IACjE,OAAO,IAAI,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED,iBAAiB;AACjB,kBAAe,YAAY,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@edpear/sdk",
3
+ "version": "1.0.0",
4
+ "description": "EdPear SDK - AI-powered educational components for JavaScript/TypeScript",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "dev": "tsc --watch",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "keywords": [
13
+ "edpear",
14
+ "ai",
15
+ "education",
16
+ "vision",
17
+ "sdk"
18
+ ],
19
+ "author": "EdPear",
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/edpear/edpearofficial.git",
24
+ "directory": "edpear-sdk"
25
+ },
26
+ "homepage": "https://edpear.com",
27
+ "bugs": {
28
+ "url": "https://github.com/edpear/edpearofficial/issues"
29
+ },
30
+ "dependencies": {
31
+ "axios": "^1.6.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20.0.0",
35
+ "typescript": "^5.0.0"
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ]
40
+ }