@openfn/language-chatgpt 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/LICENSE +674 -0
- package/LICENSE.LESSER +165 -0
- package/README.md +32 -0
- package/ast.json +574 -0
- package/configuration-schema.json +23 -0
- package/dist/index.cjs +124 -0
- package/dist/index.js +99 -0
- package/package.json +49 -0
- package/types/Adaptor.d.ts +26 -0
- package/types/index.d.ts +3 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/index.js
|
|
26
|
+
var src_exports = {};
|
|
27
|
+
__export(src_exports, {
|
|
28
|
+
createClient: () => createClient,
|
|
29
|
+
cursor: () => import_language_common2.cursor,
|
|
30
|
+
dataPath: () => import_language_common2.dataPath,
|
|
31
|
+
dataValue: () => import_language_common2.dataValue,
|
|
32
|
+
dateFns: () => import_language_common2.dateFns,
|
|
33
|
+
default: () => src_default,
|
|
34
|
+
each: () => import_language_common2.each,
|
|
35
|
+
execute: () => execute,
|
|
36
|
+
field: () => import_language_common2.field,
|
|
37
|
+
fields: () => import_language_common2.fields,
|
|
38
|
+
fn: () => import_language_common2.fn,
|
|
39
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
40
|
+
merge: () => import_language_common2.merge,
|
|
41
|
+
prompt: () => prompt,
|
|
42
|
+
setMockClient: () => setMockClient,
|
|
43
|
+
sourceValue: () => import_language_common2.sourceValue
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(src_exports);
|
|
46
|
+
|
|
47
|
+
// src/Adaptor.js
|
|
48
|
+
var Adaptor_exports = {};
|
|
49
|
+
__export(Adaptor_exports, {
|
|
50
|
+
createClient: () => createClient,
|
|
51
|
+
cursor: () => import_language_common2.cursor,
|
|
52
|
+
dataPath: () => import_language_common2.dataPath,
|
|
53
|
+
dataValue: () => import_language_common2.dataValue,
|
|
54
|
+
dateFns: () => import_language_common2.dateFns,
|
|
55
|
+
each: () => import_language_common2.each,
|
|
56
|
+
execute: () => execute,
|
|
57
|
+
field: () => import_language_common2.field,
|
|
58
|
+
fields: () => import_language_common2.fields,
|
|
59
|
+
fn: () => import_language_common2.fn,
|
|
60
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
61
|
+
merge: () => import_language_common2.merge,
|
|
62
|
+
prompt: () => prompt,
|
|
63
|
+
setMockClient: () => setMockClient,
|
|
64
|
+
sourceValue: () => import_language_common2.sourceValue
|
|
65
|
+
});
|
|
66
|
+
var import_language_common = require("@openfn/language-common");
|
|
67
|
+
var import_openai = __toESM(require("openai"), 1);
|
|
68
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
69
|
+
var client;
|
|
70
|
+
function createClient(state) {
|
|
71
|
+
const { apiKey } = state.configuration;
|
|
72
|
+
client = new import_openai.default({
|
|
73
|
+
apiKey
|
|
74
|
+
});
|
|
75
|
+
return state;
|
|
76
|
+
}
|
|
77
|
+
function setMockClient(mock) {
|
|
78
|
+
client = mock;
|
|
79
|
+
}
|
|
80
|
+
function execute(...operations) {
|
|
81
|
+
const initialState = {
|
|
82
|
+
references: [],
|
|
83
|
+
data: null
|
|
84
|
+
};
|
|
85
|
+
return (state) => {
|
|
86
|
+
return (0, import_language_common.execute)(
|
|
87
|
+
createClient,
|
|
88
|
+
...operations
|
|
89
|
+
)({
|
|
90
|
+
...initialState,
|
|
91
|
+
...state
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function prompt(message, model = "gpt-4o") {
|
|
96
|
+
return async (state) => {
|
|
97
|
+
const msg = await client.chat.completions.create({
|
|
98
|
+
model,
|
|
99
|
+
messages: [{ role: "user", content: message }]
|
|
100
|
+
});
|
|
101
|
+
return (0, import_language_common.composeNextState)(state, msg);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/index.js
|
|
106
|
+
var src_default = Adaptor_exports;
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
createClient,
|
|
110
|
+
cursor,
|
|
111
|
+
dataPath,
|
|
112
|
+
dataValue,
|
|
113
|
+
dateFns,
|
|
114
|
+
each,
|
|
115
|
+
execute,
|
|
116
|
+
field,
|
|
117
|
+
fields,
|
|
118
|
+
fn,
|
|
119
|
+
lastReferenceValue,
|
|
120
|
+
merge,
|
|
121
|
+
prompt,
|
|
122
|
+
setMockClient,
|
|
123
|
+
sourceValue
|
|
124
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/Adaptor.js
|
|
8
|
+
var Adaptor_exports = {};
|
|
9
|
+
__export(Adaptor_exports, {
|
|
10
|
+
createClient: () => createClient,
|
|
11
|
+
cursor: () => cursor,
|
|
12
|
+
dataPath: () => dataPath,
|
|
13
|
+
dataValue: () => dataValue,
|
|
14
|
+
dateFns: () => dateFns,
|
|
15
|
+
each: () => each,
|
|
16
|
+
execute: () => execute,
|
|
17
|
+
field: () => field,
|
|
18
|
+
fields: () => fields,
|
|
19
|
+
fn: () => fn,
|
|
20
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
21
|
+
merge: () => merge,
|
|
22
|
+
prompt: () => prompt,
|
|
23
|
+
setMockClient: () => setMockClient,
|
|
24
|
+
sourceValue: () => sourceValue
|
|
25
|
+
});
|
|
26
|
+
import {
|
|
27
|
+
composeNextState,
|
|
28
|
+
execute as commonExecute
|
|
29
|
+
} from "@openfn/language-common";
|
|
30
|
+
import OpenAI from "openai";
|
|
31
|
+
import {
|
|
32
|
+
dataPath,
|
|
33
|
+
dataValue,
|
|
34
|
+
dateFns,
|
|
35
|
+
cursor,
|
|
36
|
+
each,
|
|
37
|
+
field,
|
|
38
|
+
fields,
|
|
39
|
+
fn,
|
|
40
|
+
lastReferenceValue,
|
|
41
|
+
merge,
|
|
42
|
+
sourceValue
|
|
43
|
+
} from "@openfn/language-common";
|
|
44
|
+
var client;
|
|
45
|
+
function createClient(state) {
|
|
46
|
+
const { apiKey } = state.configuration;
|
|
47
|
+
client = new OpenAI({
|
|
48
|
+
apiKey
|
|
49
|
+
});
|
|
50
|
+
return state;
|
|
51
|
+
}
|
|
52
|
+
function setMockClient(mock) {
|
|
53
|
+
client = mock;
|
|
54
|
+
}
|
|
55
|
+
function execute(...operations) {
|
|
56
|
+
const initialState = {
|
|
57
|
+
references: [],
|
|
58
|
+
data: null
|
|
59
|
+
};
|
|
60
|
+
return (state) => {
|
|
61
|
+
return commonExecute(
|
|
62
|
+
createClient,
|
|
63
|
+
...operations
|
|
64
|
+
)({
|
|
65
|
+
...initialState,
|
|
66
|
+
...state
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function prompt(message, model = "gpt-4o") {
|
|
71
|
+
return async (state) => {
|
|
72
|
+
const msg = await client.chat.completions.create({
|
|
73
|
+
model,
|
|
74
|
+
messages: [{ role: "user", content: message }]
|
|
75
|
+
});
|
|
76
|
+
return composeNextState(state, msg);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/index.js
|
|
81
|
+
var src_default = Adaptor_exports;
|
|
82
|
+
export {
|
|
83
|
+
createClient,
|
|
84
|
+
cursor,
|
|
85
|
+
dataPath,
|
|
86
|
+
dataValue,
|
|
87
|
+
dateFns,
|
|
88
|
+
src_default as default,
|
|
89
|
+
each,
|
|
90
|
+
execute,
|
|
91
|
+
field,
|
|
92
|
+
fields,
|
|
93
|
+
fn,
|
|
94
|
+
lastReferenceValue,
|
|
95
|
+
merge,
|
|
96
|
+
prompt,
|
|
97
|
+
setMockClient,
|
|
98
|
+
sourceValue
|
|
99
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfn/language-chatgpt",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OpenFn chatgpt adaptor",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./types/index.d.ts",
|
|
10
|
+
"require": "./dist/index.cjs"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"author": "Open Function Group",
|
|
15
|
+
"license": "LGPLv3",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/",
|
|
18
|
+
"types/",
|
|
19
|
+
"ast.json",
|
|
20
|
+
"configuration-schema.json"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"openai": "^4.86.2",
|
|
24
|
+
"@openfn/language-common": "2.3.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"assertion-error": "2.0.0",
|
|
28
|
+
"chai": "4.3.6",
|
|
29
|
+
"deep-eql": "4.1.1",
|
|
30
|
+
"esno": "^0.16.3",
|
|
31
|
+
"mocha": "^10.7.3",
|
|
32
|
+
"rimraf": "3.0.2",
|
|
33
|
+
"undici": "^5.22.1"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/openfn/adaptors.git"
|
|
38
|
+
},
|
|
39
|
+
"types": "types/index.d.ts",
|
|
40
|
+
"main": "dist/index.cjs",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "pnpm clean && build-adaptor chatgpt",
|
|
43
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
44
|
+
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
|
|
45
|
+
"clean": "rimraf dist types docs",
|
|
46
|
+
"pack": "pnpm pack --pack-destination ../../dist",
|
|
47
|
+
"lint": "eslint src"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates and OpenAI client
|
|
3
|
+
* @param state
|
|
4
|
+
* @returns {state}
|
|
5
|
+
*/
|
|
6
|
+
export function createClient(state: any): any;
|
|
7
|
+
export function setMockClient(mock: any): void;
|
|
8
|
+
/**
|
|
9
|
+
* Executes a series of operations.
|
|
10
|
+
* It ensures the client is created first and assigned to the 'client' variable
|
|
11
|
+
* @private
|
|
12
|
+
* @param operations
|
|
13
|
+
* @returns {operation}
|
|
14
|
+
*/
|
|
15
|
+
export function execute(...operations: any[]): operation;
|
|
16
|
+
/**
|
|
17
|
+
* Prompt the GPT chat interface to respond
|
|
18
|
+
* @example
|
|
19
|
+
* prompt('Write a haiku about surfing.' model='gpt-4o');
|
|
20
|
+
* @public
|
|
21
|
+
* @param {string} message - The prompt
|
|
22
|
+
* @param {string} model - The model (defaults to 'gpt-4o)
|
|
23
|
+
* @returns {operation}
|
|
24
|
+
*/
|
|
25
|
+
export function prompt(message: string, model?: string): operation;
|
|
26
|
+
export { dataPath, dataValue, dateFns, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|
package/types/index.d.ts
ADDED