OpenAI ChatGPT Integration

OpenAI

ChatGPT API Integration

Enhance your Jspreadsheet Pro by integrating the ChatGPT API directly into your spreadsheet data grids. This extension enables automated content generation, effective response handling, and in-depth data analysis. It requires the Jspreadsheet Server extension for full functionality, allowing you to run queries from the front end while connecting to the API from your backend to deliver real-time data to users.

Endless possibilities

Generate Marketing Copy

You have a list of products and their attributes, and you need to quickly generate marketing copy for each one.

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)

Documentation

Methods

Method Description
=PROMPT(...ARGUMENTS) This function is used to create dynamic prompts by combining different values or text fragments. It allows you to interact with AI models using customized prompts.

Installation

This extension requires Jspreadsheet Server & an 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

The OpenAI extension requires the Jspreadsheet Server so one user can perform a secure requests to ChatGPT API via Jspreadsheet Server, which will broadcast the same answer to all connect users. Using the cache saving the result to the cell, this way a request happen only when strictly necessary.

Server Installation

You load the OpenAI and pass as an extension to Jspreadsheet server as below.

const server = require('@jspreadsheet/server');
const openai = require('@jspreadsheet/openai');

// Connect to the Open AI API
openai({ apiKey: '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' });

// 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 },
});

Front End configuration

You can connect to your server an open your spreadsheet.

import jspreadsheet from 'jspreadsheet';
import formula from '@jspreadsheet/formula-pro';
import client from '@jspreadsheet/client';
import openai from '@jspreadsheet/openai';

// Load the extensions
jspreadsheet.setExtensions({ formula, client, openai });

// Connect
let remote = client.connect({
    url: 'https://yourdomain.com',
    path: 'socket.io/'
});

// Connect to a spreadsheet
jspreadsheet(HTMLElement, {
    guid: '53aa4c90-791d-4a65-84a6-1ac25d6b1118'
});

More Examples

Translating Column to French

This example demonstrates the utilization of PROMPT to translate an entire column.

jspreadsheet(HTMLElement, {
    worksheets: [
        {
            data: [
                ['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 Words Semantics

This example demonstrates the utilization of OPENAI.PROMPT to effectively combine word semantics.

jspreadsheet(HTMLElement, {
    worksheets: [
        {
            data: [
                ['Flower', 'Bee', `=PROMPT(A1," and ",B1," combined result in this word:")`],
            ]
        }
    ]
})