@digipair/skill-openai 0.89.0 → 0.91.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/.swcrc ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "jsc": {
3
+ "target": "es2017",
4
+ "parser": {
5
+ "syntax": "typescript",
6
+ "decorators": true,
7
+ "dynamicImport": true
8
+ },
9
+ "transform": {
10
+ "decoratorMetadata": true,
11
+ "legacyDecorator": true
12
+ },
13
+ "keepClassNames": true,
14
+ "externalHelpers": true,
15
+ "loose": true
16
+ },
17
+ "module": {
18
+ "type": "es6"
19
+ },
20
+ "sourceMaps": true,
21
+ "exclude": [
22
+ "jest.config.ts",
23
+ ".*\\.spec.tsx?$",
24
+ ".*\\.test.tsx?$",
25
+ "./src/jest-setup.ts$",
26
+ "./**/jest-setup.ts$"
27
+ ]
28
+ }
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # mylib
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build mylib` to build the library.
@@ -0,0 +1,22 @@
1
+ import baseConfig from '../../eslint.config.mjs';
2
+
3
+ export default [
4
+ ...baseConfig,
5
+ {
6
+ files: ['**/*.json'],
7
+ rules: {
8
+ '@nx/dependency-checks': [
9
+ 'error',
10
+ {
11
+ ignoredFiles: [
12
+ '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
+ '{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
14
+ ],
15
+ },
16
+ ],
17
+ },
18
+ languageOptions: {
19
+ parser: await import('jsonc-eslint-parser'),
20
+ },
21
+ },
22
+ ];
package/package.json CHANGED
@@ -1,12 +1,28 @@
1
1
  {
2
2
  "name": "@digipair/skill-openai",
3
- "version": "0.89.0",
3
+ "version": "0.91.0-0",
4
+ "type": "module",
5
+ "main": "dist/libs/skill-openai/index.cjs.js",
6
+ "module": "dist/libs/skill-openai/index.esm.js",
7
+ "types": "dist/libs/skill-openai/index.esm.d.ts",
8
+ "exports": {
9
+ "./package.json": "./libs/skill-openai/package.json",
10
+ ".": {
11
+ "development": "./dist/libs/skill-openai/src/index.ts",
12
+ "types": "./dist/libs/skill-openai/index.esm.d.ts",
13
+ "import": "./dist/libs/skill-openai/index.esm.js",
14
+ "default": "./dist/libs/skill-openai/index.cjs.js"
15
+ }
16
+ },
4
17
  "keywords": [
5
18
  "digipair",
6
- "service",
7
- "util"
19
+ "util",
20
+ "service"
8
21
  ],
9
- "dependencies": {},
10
- "main": "./index.cjs.js",
11
- "module": "./index.esm.js"
12
- }
22
+ "nx": {
23
+ "name": "skill-openai"
24
+ },
25
+ "dependencies": {
26
+ "@digipair/engine": "0.91.0-0"
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+ const { withNx } = require('@nx/rollup/with-nx');
2
+
3
+ module.exports = withNx(
4
+ {
5
+ main: 'libs/skill-openai/src/index.ts',
6
+ outputPath: 'dist/libs/skill-openai',
7
+ tsConfig: 'libs/skill-openai/tsconfig.lib.json',
8
+ compiler: 'swc',
9
+ format: ['esm', "cjs"],
10
+ assets: [
11
+ {
12
+ input: 'libs/skill-openai/',
13
+ glob: 'package.json',
14
+ output: '.'
15
+ },
16
+ {
17
+ input: 'libs/skill-openai/src/',
18
+ glob: '*.json',
19
+ output: '.'
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
25
+ // e.g.
26
+ // output: { sourcemap: true },
27
+ }
28
+ );
@@ -0,0 +1,7 @@
1
+ import { skillOpenai } from './skill-openai';
2
+
3
+ describe('skillOpenai', () => {
4
+ it('should work', () => {
5
+ expect(skillOpenai()).toEqual('skill-openai');
6
+ });
7
+ });
@@ -0,0 +1,109 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import {
3
+ AzureChatOpenAI,
4
+ AzureOpenAIEmbeddings,
5
+ ChatOpenAI,
6
+ OpenAIEmbeddings,
7
+ } from '@langchain/openai';
8
+ import { PinsSettings } from '@digipair/engine';
9
+
10
+ class OpenAIService {
11
+ async model(params: any, _pinsSettingsList: PinsSettings[], context: any) {
12
+ const {
13
+ modelName = 'gpt-4o-mini',
14
+ temperature = 0,
15
+ baseURL = context.privates.OPENAI_SERVER ?? process.env['OPENAI_SERVER'],
16
+ openAIApiKey = context.privates.OPENAI_API_KEY ?? process.env['OPENAI_API_KEY'],
17
+ configuration = {},
18
+ } = params;
19
+ const model = new ChatOpenAI({
20
+ modelName,
21
+ temperature,
22
+ openAIApiKey,
23
+ configuration: { baseURL },
24
+ ...configuration,
25
+ });
26
+
27
+ return model;
28
+ }
29
+
30
+ async modelAzure(params: any, _pinsSettingsList: PinsSettings[], context: any) {
31
+ const {
32
+ deploymentName,
33
+ temperature = 0,
34
+ openAIApiInstanceName = context.privates.AZURE_OPENAI_API_INSTANCE_NAME ??
35
+ process.env['AZURE_OPENAI_API_INSTANCE_NAME'],
36
+ openAIApiKey = context.privates.AZURE_OPENAI_API_KEY ?? process.env['AZURE_OPENAI_API_KEY'],
37
+ openAIApiVersion = context.privates.AZURE_OPENAI_API_VERSION ??
38
+ process.env['AZURE_OPENAI_API_VERSION'],
39
+ configuration = {},
40
+ } = params;
41
+ const model = new AzureChatOpenAI({
42
+ deploymentName,
43
+ temperature,
44
+ openAIApiKey,
45
+ openAIApiVersion,
46
+ azureOpenAIApiInstanceName: openAIApiInstanceName,
47
+ ...configuration,
48
+ });
49
+
50
+ return model;
51
+ }
52
+
53
+ async embeddings(params: any, _pinsSettingsList: PinsSettings[], context: any) {
54
+ const {
55
+ modelName = 'text-embedding-3-small',
56
+ baseURL = context.privates.OPENAI_SERVER ?? process.env['OPENAI_SERVER'],
57
+ openAIApiKey = context.privates.OPENAI_API_KEY ?? process.env['OPENAI_API_KEY'],
58
+ dimensions,
59
+ configuration = {},
60
+ } = params;
61
+ const config = {
62
+ configuration: { baseURL },
63
+ modelName,
64
+ openAIApiKey,
65
+ ...configuration,
66
+ };
67
+
68
+ const modelInstance = new OpenAIEmbeddings(!!dimensions ? { ...config, dimensions } : config);
69
+
70
+ return modelInstance;
71
+ }
72
+
73
+ async embeddingsAzure(params: any, _pinsSettingsList: PinsSettings[], context: any) {
74
+ const {
75
+ deploymentName,
76
+ dimensions,
77
+ openAIApiKey = context.privates.AZURE_OPENAI_API_KEY ?? process.env['AZURE_OPENAI_API_KEY'],
78
+ openAIApiInstanceName = context.privates.AZURE_OPENAI_API_INSTANCE_NAME ??
79
+ process.env['AZURE_OPENAI_API_INSTANCE_NAME'],
80
+ openAIApiVersion = context.privates.AZURE_OPENAI_API_VERSION ??
81
+ process.env['AZURE_OPENAI_API_VERSION'],
82
+ configuration = {},
83
+ } = params;
84
+ const config = {
85
+ deploymentName,
86
+ apiKey: openAIApiKey,
87
+ azureOpenAIApiInstanceName: openAIApiInstanceName,
88
+ openAIApiVersion,
89
+ ...configuration,
90
+ };
91
+ const modelInstance = new AzureOpenAIEmbeddings(
92
+ !!dimensions ? { ...config, dimensions } : config,
93
+ );
94
+
95
+ return modelInstance;
96
+ }
97
+ }
98
+
99
+ export const model = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
100
+ new OpenAIService().model(params, pinsSettingsList, context);
101
+
102
+ export const modelAzure = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
103
+ new OpenAIService().modelAzure(params, pinsSettingsList, context);
104
+
105
+ export const embeddings = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
106
+ new OpenAIService().embeddings(params, pinsSettingsList, context);
107
+
108
+ export const embeddingsAzure = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
109
+ new OpenAIService().embeddingsAzure(params, pinsSettingsList, context);
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "../engine"
8
+ },
9
+ {
10
+ "path": "./tsconfig.lib.json"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
7
+ "emitDeclarationOnly": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "node",
10
+ "forceConsistentCasingInFileNames": true,
11
+ "types": ["node"]
12
+ },
13
+ "include": ["src/**/*.ts"],
14
+ "references": [
15
+ {
16
+ "path": "../engine/tsconfig.lib.json"
17
+ }
18
+ ]
19
+ }
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";