OpenAI Extension
Integrate the ChatGPT API directly into your Jspreadsheet Server application. This extension enables automated content generation, intelligent responses, and advanced data analysis. Frontend queries securely communicate with the API through your server, delivering real-time, AI-powered insights.
Documentation
Methods
| Method | Description |
|---|---|
=PROMPT() |
Combines values and text fragments to create dynamic prompts for AI model interactions. |
Example
Generate Marketing Copy
Generate marketing copy for products using their attributes.
A1: "Product Name"
B1: "Product Description"
C1: "Marketing Copy"
A2: "Smartwatch"
B2: "Fitness tracking, sleep monitoring, 48-hour battery life"
In C2, you would enter:
=PROMPT("Write an engaging marketing copy for a product named ", A2, " with these features: ", B2)
Installation
This extension requires Jspreadsheet Server and an active OpenAI API account.
Using NPM
npm install @jspreadsheet/openai
Using a CDN
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/openai/dist/index.min.js"></script>
Configuration
Jspreadsheet Server enables secure requests to the ChatGPT API. When a user executes a formula on the frontend, the server processes it and shares the response with all connected users. With caching enabled, responses are saved to cells to reduce redundant API calls.
Installation
Load the OpenAI extension and register it with Jspreadsheet Server:
const server = require('@jspreadsheet/server');
const openai = require('@jspreadsheet/openai');
// Connect to the Open AI API
openai({ apiKey: 'your-openai-key' });
// You can get this information on your Jspreadsheet Account
const license = {
clientId: 'your-client-id',
licenseKey: 'your-license'
}
// Private server that runs on your servers (100% private)
server({
config: {
cors: {
origin: "*"
},
},
port: 3000,
error: function(e) {
// Your implementation
},
auth: async function(socket) {
// Your implementation
},
load: async function(guid) {
// Your implementation
},
create: async function(guid, config) {
// Your implementation
},
destroy: async function(guid) {
// Your implementation
},
change: async function(guid, changes) {
// Your implementation
},
license: license,
extensions: { openai },
});
Examples
Translating Column to French
Use the PROMPT function to translate entire columns automatically.
[
['Hello', '=PROMPT("Translate ",A1," to French")'],
['Bye', '=PROMPT("Translate ",A2," to French")'],
['Thanks', '=PROMPT("Translate ",A3," to French")'],
['Sorry', '=PROMPT("Translate ",A4," to French")'],
]
Combining Word Semantics
Use PROMPT to generate creative semantic combinations.
['Flower', 'Bee', `=PROMPT(A1," and ",B1," combined result in this word:")`]