ai-form-fill 0.1.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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Joel Deffner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,355 @@
1
+ # AI Form Fill
2
+
3
+ Framework-agnostic library for AI-powered form filling. Extract structured data from unstructured text and automatically fill forms using OpenAI, Ollama, Perplexity, or custom AI providers.
4
+
5
+ ## Features
6
+
7
+ - Uses LLMs to understand and extract data from natural language
8
+ - Automatically matches data to form fields
9
+ - Works with Ollama, OpenAI or Perplexity
10
+ - Framework-agnostic - works with vanilla JS, React, Vue, or any framework that allows module imports
11
+ - Two integration modes: Quick setup or full customization
12
+ - Field hints for precise AI guidance
13
+ - Configurable field targeting
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install ai-form-fill
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Quick Start (Simple Setup)
24
+
25
+ The fastest way to get started - just add HTML attributes and one line of JavaScript.
26
+
27
+ ### HTML Setup
28
+
29
+ ```html
30
+ <form id="aff-form" data-aff-provider="ollama">
31
+ <input type="text" name="name" placeholder="Name">
32
+ <input type="email" name="email" placeholder="Email">
33
+ <input type="tel" name="phone" placeholder="Phone">
34
+ </form>
35
+
36
+ <textarea id="aff-text" placeholder="Paste your text here..."></textarea>
37
+ <button id="aff-text-button">Fill Form</button>
38
+ ```
39
+
40
+ ### JavaScript (One Line!)
41
+
42
+ ```typescript
43
+ import { initializeAFFQuick } from 'ai-form-fill';
44
+
45
+ initializeAFFQuick(); // That's it!
46
+ ```
47
+
48
+ ### Required Element IDs
49
+
50
+ | Element ID | Description |
51
+ |------------|-------------|
52
+ | `aff-form` | The form element to fill |
53
+ | `aff-text` | Textarea for user input text |
54
+ | `aff-text-button` | Button to trigger form filling |
55
+
56
+ ### Provider Selection
57
+
58
+ Add `data-aff-provider` attribute to specify which AI provider to use:
59
+
60
+ ```html
61
+ <form id="aff-form" data-aff-provider="openai">
62
+ ```
63
+
64
+ Available providers (case-insensitive): `ollama`, `openai`, `perplexity`
65
+
66
+ ### Custom Form ID
67
+
68
+ You can use a custom form ID by passing it to `initializeAFFQuick()`:
69
+
70
+ ```typescript
71
+ initializeAFFQuick('my-custom-form');
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Advanced Setup (Full Customization)
77
+
78
+ For complete control over the library, use the `AIFormFill` class directly.
79
+
80
+ ### Basic Usage
81
+
82
+ ```typescript
83
+ import { AIFormFill } from 'ai-form-fill';
84
+
85
+ // Create instance with a provider
86
+ const aiForm = new AIFormFill('ollama', {
87
+ model: 'gemma3:4b',
88
+ debug: true
89
+ });
90
+
91
+ // Fill entire form from unstructured text
92
+ const form = document.getElementById('myForm') as HTMLFormElement;
93
+ const text = "My name is John Doe, email john@example.com, phone 555-1234";
94
+
95
+ await aiForm.parseAndFillForm(form, text);
96
+ ```
97
+
98
+ ### Fill a Single Field
99
+
100
+ ```typescript
101
+ const bioField = document.querySelector('#bio') as HTMLElement;
102
+ await aiForm.fillSingleField(bioField);
103
+ ```
104
+
105
+ ### Using Custom Providers
106
+
107
+ You can pass a custom `AIProvider` instance instead of a provider name:
108
+
109
+ ```typescript
110
+ import { AIFormFill, LocalOllamaProvider } from 'ai-form-fill';
111
+
112
+ const customProvider = new LocalOllamaProvider({
113
+ apiEndpoint: 'http://my-server:11434',
114
+ model: 'llama3',
115
+ timeout: 60000,
116
+ });
117
+
118
+ const aiForm = new AIFormFill(customProvider, { debug: true });
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Configuration
124
+
125
+ ### Provider Options
126
+
127
+ #### Ollama (Local - Recommended for Development)
128
+ ```typescript
129
+ const aiForm = new AIFormFill('ollama', {
130
+ model: 'gemma3:4b',
131
+ apiEndpoint: 'http://localhost:11434', // Optional
132
+ timeout: 40000, // Optional
133
+ });
134
+ ```
135
+
136
+ #### OpenAI
137
+ ```typescript
138
+ const aiForm = new AIFormFill('openai', {
139
+ model: 'gpt-5-nano',
140
+ timeout: 60000,
141
+ });
142
+ ```
143
+
144
+ #### Perplexity
145
+ ```typescript
146
+ const aiForm = new AIFormFill('perplexity', {
147
+ model: 'sonar',
148
+ timeout: 60000,
149
+ });
150
+ ```
151
+
152
+ ### Global Configuration
153
+
154
+ Change default settings for all instances:
155
+
156
+ ```typescript
157
+ import { affConfig } from 'ai-form-fill';
158
+
159
+ // Update Ollama defaults
160
+ affConfig.providers.ollama.model = 'mistral';
161
+ affConfig.providers.ollama.apiEndpoint = 'http://my-server:11434';
162
+
163
+ // Update OpenAI defaults
164
+ affConfig.providers.openai.model = 'gpt-4o';
165
+
166
+ // Enable debug mode globally
167
+ affConfig.defaults.debug = true;
168
+ ```
169
+
170
+ ### Field Targeting
171
+
172
+ By default, all detected form fields are filled. Target specific fields only:
173
+
174
+ ```typescript
175
+ const aiForm = new AIFormFill('ollama', {
176
+ targetFields: ['firstName', 'lastName', 'email'], // Only fill fields with these name attributes
177
+ });
178
+
179
+ await aiForm.parseAndFillForm(form, text);
180
+ ```
181
+
182
+ Update the field list after instantiation:
183
+
184
+ ```typescript
185
+ aiForm.setFields(['name', 'phone']); // Update targeted fields
186
+ aiForm.setFields(undefined); // Reset to fill all fields
187
+
188
+ // Get currently targeted fields
189
+ const fields = aiForm.getFields(); // Returns string[] | undefined
190
+ ```
191
+
192
+ ### Field Hints (`data-aff-hint`)
193
+
194
+ Provide additional context to help the AI understand specific fields using the `data-aff-hint` attribute:
195
+
196
+ ```html
197
+ <form id="job-application">
198
+ <!-- Basic field - AI infers from name/label -->
199
+ <input type="text" name="firstName" />
200
+
201
+ <!-- Date field with format hint -->
202
+ <input
203
+ type="date"
204
+ name="startDate"
205
+ data-aff-hint="Use the earliest date mentioned in the text"
206
+ />
207
+
208
+ <!-- Select with mapping hint -->
209
+ <select
210
+ name="department"
211
+ data-aff-hint="Map to the closest match from the available options"
212
+ >
213
+ <option value="engineering">Engineering</option>
214
+ <option value="sales">Sales</option>
215
+ <option value="marketing">Marketing</option>
216
+ </select>
217
+
218
+ <!-- Textarea with content guidance -->
219
+ <textarea
220
+ name="bio"
221
+ data-aff-hint="Extract a professional summary, max 2 sentences"
222
+ ></textarea>
223
+ </form>
224
+ ```
225
+
226
+ Hints are automatically read when filling the form:
227
+
228
+ ```typescript
229
+ const aiForm = new AIFormFill('openai', { debug: true });
230
+ const form = document.getElementById('job-application') as HTMLFormElement;
231
+
232
+ await aiForm.parseAndFillForm(form, resumeText);
233
+ ```
234
+
235
+ ---
236
+
237
+ ## Overview
238
+
239
+ ### `AIFormFill` Class
240
+
241
+ #### Constructor
242
+
243
+ ```typescript
244
+ new AIFormFill(provider: AvailableProviders | AIProvider, options?: AIFormFillConfig & ProviderConfig)
245
+ ```
246
+
247
+ | Parameter | Type | Description |
248
+ |-----------|------|-------------|
249
+ | `provider` | `'ollama' \| 'openai' \| 'perplexity' \| AIProvider` | Provider name or custom instance |
250
+ | `options.targetFields` | `string[]` | Optional list of field names to fill |
251
+ | `options.debug` | `boolean` | Enable debug logging (default: `false`) |
252
+ | `options.model` | `string` | Model name to use |
253
+ | `options.apiEndpoint` | `string` | Custom API endpoint |
254
+ | `options.timeout` | `number` | Request timeout in ms |
255
+
256
+ #### Methods
257
+
258
+ | Method | Description |
259
+ |--------|-------------|
260
+ | `parseAndFillForm(form, text)` | Parse text and fill matching form fields |
261
+ | `fillSingleField(element)` | Fill a single field with AI-generated content |
262
+ | `setProvider(provider)` | Change the AI provider |
263
+ | `getProvider()` | Get the current AI provider |
264
+ | `setFields(fields)` | Set which fields should be filled |
265
+ | `getFields()` | Get currently targeted fields |
266
+ | `getAvailableModels()` | Get list of available models from provider |
267
+ | `setSelectedModel(model)` | Set the model to use |
268
+ | `getSelectedModel()` | Get the currently selected model |
269
+ | `providerAvailable()` | Check if the provider is available |
270
+
271
+ ### `initializeAFFQuick(formId?)`
272
+
273
+ Quick initialization function for simple setups.
274
+
275
+ | Parameter | Type | Default | Description |
276
+ |-----------|------|---------|-------------|
277
+ | `formId` | `string` | `'aff-form'` | ID of the form element |
278
+
279
+ ---
280
+
281
+ ## Examples
282
+
283
+ See the `examples/` folder for working demos:
284
+
285
+ | Example | Description |
286
+ |---------|-------------|
287
+ | `basic/` | Simple form filling with minimal setup |
288
+ | `advanced/` | Full-featured demo with provider selection and debugging |
289
+
290
+ Run examples locally:
291
+
292
+ ```bash
293
+ npm run dev
294
+ ```
295
+
296
+ ---
297
+
298
+ ## Development Setup
299
+
300
+ ### Prerequisites
301
+
302
+ - **Node.js** - [Install from nodejs.org](https://nodejs.org/en)
303
+ - **pnpm** (recommended) - [Install guide on pnpm.io](https://pnpm.io/installation)
304
+ - **Ollama** - [Install from ollama.ai](https://ollama.ai)
305
+
306
+ ### Recommended: Ollama Setup (Simplest)
307
+
308
+ Run this command after installing Ollama:
309
+ ```bash
310
+ ollama pull gemma3:4b
311
+ ```
312
+
313
+ No API keys required!
314
+
315
+ ### Full Setup
316
+
317
+ 1. **Clone this Git repository**
318
+
319
+ 2. **Go to the Project root and run**
320
+ ```bash
321
+ pnpm install
322
+ ```
323
+ 3. **Optional - API Keys for OpenAI/Perplexity:**
324
+
325
+ Create a `.env` file in the project root:
326
+ ```env
327
+ VITE_OPEN_AI_KEY=your-openai-key-here
328
+ VITE_PERPLEXITY_KEY=your-perplexity-key-here
329
+ ```
330
+
331
+ 4. **Start development server:**
332
+ ```bash
333
+ pnpm run dev
334
+ ```
335
+
336
+ ### Project Structure
337
+
338
+ ```
339
+ ai-form-fill/
340
+ ├── lib/ # Core library source
341
+ │ ├── core/ # Main classes and types
342
+ │ ├── providers/ # AI provider implementations
343
+ │ └── utils/ # Utility functions
344
+ ├── examples/ # Demo applications
345
+ │ ├── basic/ # Simple form fill example
346
+ │ └── advanced/ # Full-featured demo
347
+ └── mock/ # API mock endpoints for development
348
+ ```
349
+
350
+ ## APIs
351
+
352
+ ---
353
+ APIs have to be handled with utmost care when working with JavaScipt since they are easily exposed when they are handled in the front end. since this library is a frontend one it means that sending the data to a self hosted backend first is a must. In the current version this happens through the mock abstraction but in real implementations this would require the configurations of a proper backend. this is outside the scope of this project but there is an obligation to set up guidelines as to how the libraries requiests should be relayed.
354
+
355
+ ---