@nu-art/ts-openai-backend 0.401.9 → 0.500.6

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.
@@ -1,6 +1,6 @@
1
1
  import { Module, TypedMap } from '@nu-art/ts-common';
2
2
  import { GPT_Model } from '@nu-art/ts-openai-shared/types';
3
- import { Request_ChatGPT } from '@nu-art/ts-openai-shared/api-def';
3
+ import { API_OpenAI, Request_ChatGPT } from '@nu-art/ts-openai-shared/api-def';
4
4
  type Config = {
5
5
  directives: TypedMap<{
6
6
  agent?: GPT_Model;
@@ -19,9 +19,7 @@ export declare class ModuleBE_OpenAI_Class extends Module<Config> {
19
19
  private openai;
20
20
  constructor(tag?: string);
21
21
  init(): void;
22
- test: (query: Request_ChatGPT) => Promise<{
23
- response: string;
24
- }>;
22
+ test(body: API_OpenAI['test']['Body']): Promise<API_OpenAI['test']['Response']>;
25
23
  predefinedQuery: (query: Request_PredefinedDirective) => Promise<{
26
24
  response: string;
27
25
  }>;
@@ -1,48 +1,87 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
1
35
  import { __stringify, BadImplementationException, Module, ThisShouldNotHappenException } from '@nu-art/ts-common';
36
+ import { ApiHandler } from '@nu-art/http-server';
2
37
  import { OpenAI } from 'openai';
3
- import { addRoutes, createBodyServerApi } from '@nu-art/thunderstorm-backend';
4
38
  import { ApiDef_OpenAI } from '@nu-art/ts-openai-shared/api-def';
5
- export class ModuleBE_OpenAI_Class extends Module {
6
- openai;
7
- constructor(tag) {
8
- super(tag);
9
- }
10
- init() {
11
- const apiKey = this.config.apiKey;
12
- const organization = this.config.orgId;
13
- const opts = { apiKey, organization };
14
- this.logDebug(opts);
15
- this.openai = new OpenAI(opts);
16
- addRoutes([
17
- createBodyServerApi(ApiDef_OpenAI.v1.test, this.test),
18
- ]);
19
- }
20
- test = async (query) => this.simpleQuery(query);
21
- predefinedQuery = async (query) => {
22
- const directive = this.config.directives[query.directiveKey];
23
- if (!directive)
24
- throw new BadImplementationException(`Missing instruction for directive: ${query.directiveKey}`);
25
- return this.simpleQuery({ model: directive.agent ?? query.model, message: query.message, directive: directive.directive });
26
- };
27
- simpleQuery = async (query) => {
28
- const completion = await this.openai.chat.completions.create({
29
- messages: [
30
- {
31
- role: 'system',
32
- content: query.directive
33
- },
34
- {
35
- role: 'user',
36
- content: query.message
37
- }
38
- ],
39
- model: query.model || this.config.defaultModel || 'gpt-3.5-turbo',
40
- });
41
- const content = completion.choices[0].message.content;
42
- this.logInfo(completion);
43
- if (!content)
44
- throw new ThisShouldNotHappenException(`Didn't receive a response from GPT, got: ${__stringify(completion, true)}`);
45
- return { response: content };
39
+ let ModuleBE_OpenAI_Class = (() => {
40
+ let _classSuper = Module;
41
+ let _instanceExtraInitializers = [];
42
+ let _test_decorators;
43
+ return class ModuleBE_OpenAI_Class extends _classSuper {
44
+ static {
45
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
46
+ _test_decorators = [ApiHandler(ApiDef_OpenAI.test)];
47
+ __esDecorate(this, null, _test_decorators, { kind: "method", name: "test", static: false, private: false, access: { has: obj => "test" in obj, get: obj => obj.test }, metadata: _metadata }, null, _instanceExtraInitializers);
48
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
49
+ }
50
+ openai = __runInitializers(this, _instanceExtraInitializers);
51
+ constructor(tag) {
52
+ super(tag);
53
+ }
54
+ init() {
55
+ const apiKey = this.config.apiKey;
56
+ const organization = this.config.orgId;
57
+ const opts = { apiKey, organization };
58
+ this.logDebug(opts);
59
+ this.openai = new OpenAI(opts);
60
+ }
61
+ async test(body) {
62
+ return this.simpleQuery(body);
63
+ }
64
+ predefinedQuery = async (query) => {
65
+ const directive = this.config.directives[query.directiveKey];
66
+ if (!directive)
67
+ throw new BadImplementationException(`Missing instruction for directive: ${query.directiveKey}`);
68
+ return this.simpleQuery({ model: directive.agent ?? query.model, message: query.message, directive: directive.directive });
69
+ };
70
+ simpleQuery = async (query) => {
71
+ const completion = await this.openai.chat.completions.create({
72
+ messages: [
73
+ { role: 'system', content: query.directive },
74
+ { role: 'user', content: query.message }
75
+ ],
76
+ model: query.model || this.config.defaultModel || 'gpt-3.5-turbo',
77
+ });
78
+ const content = completion.choices[0].message.content;
79
+ this.logInfo(completion);
80
+ if (!content)
81
+ throw new ThisShouldNotHappenException(`Didn't receive a response from GPT, got: ${__stringify(completion, true)}`);
82
+ return { response: content };
83
+ };
46
84
  };
47
- }
85
+ })();
86
+ export { ModuleBE_OpenAI_Class };
48
87
  export const ModuleBE_OpenAI = new ModuleBE_OpenAI_Class();
@@ -1,7 +1,7 @@
1
- import { Module } from "@nu-art/ts-common";
2
- import { OpenAI } from "openai";
3
- import { OpenAIClient_Assistant_Class } from "./clients/OpenAIClient_Assistant.js";
4
- import { OpenAIClient_Chat_Class } from "./clients/OpenAIClient_Chat.js";
1
+ import { Module } from '@nu-art/ts-common';
2
+ import { OpenAI } from 'openai';
3
+ import { OpenAIClient_Assistant_Class } from './clients/OpenAIClient_Assistant.js';
4
+ import { OpenAIClient_Chat_Class } from './clients/OpenAIClient_Chat.js';
5
5
  import { GPT_Model } from '@nu-art/ts-openai-shared/types';
6
6
  type Config = {
7
7
  apiKey: string;
@@ -1,7 +1,7 @@
1
- import { LogLevel, Module, tsValidate, tsValidateString, tsValidateValue } from "@nu-art/ts-common";
2
- import { OpenAI } from "openai";
3
- import { OpenAIClient_Assistant_Class } from "./clients/OpenAIClient_Assistant.js";
4
- import { OpenAIClient_Chat_Class } from "./clients/OpenAIClient_Chat.js";
1
+ import { Module, tsValidate, tsValidateString, tsValidateValue } from '@nu-art/ts-common';
2
+ import { OpenAI } from 'openai';
3
+ import { OpenAIClient_Assistant_Class } from './clients/OpenAIClient_Assistant.js';
4
+ import { OpenAIClient_Chat_Class } from './clients/OpenAIClient_Chat.js';
5
5
  import { GPT_Model } from '@nu-art/ts-openai-shared/types';
6
6
  class ModuleBE_OpenAIV2_Class extends Module {
7
7
  OpenAIClient;
@@ -12,7 +12,6 @@ class ModuleBE_OpenAIV2_Class extends Module {
12
12
  apiKey: tsValidateString(),
13
13
  orgId: tsValidateString(),
14
14
  openAIModel: tsValidateValue([...GPT_Model]),
15
- minLogLevel: tsValidateValue([LogLevel.Debug, LogLevel.Info, LogLevel.Warning, LogLevel.Error])
16
15
  });
17
16
  }
18
17
  init() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-openai-backend",
3
- "version": "0.401.9",
3
+ "version": "0.500.6",
4
4
  "description": "ts-openai - Express & Typescript based backend framework",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -31,11 +31,10 @@
31
31
  "build": "tsc"
32
32
  },
33
33
  "dependencies": {
34
- "@nu-art/ts-common": "0.401.9",
35
- "@nu-art/thunderstorm-backend": "0.401.9",
36
- "@nu-art/thunderstorm-shared": "0.401.9",
37
- "@nu-art/ts-agent-tools-backend": "0.401.9",
38
- "@nu-art/ts-openai-shared": "0.401.9",
34
+ "@nu-art/ts-common": "0.500.6",
35
+ "@nu-art/http-server": "0.500.6",
36
+ "@nu-art/ts-agent-tools-backend": "0.500.6",
37
+ "@nu-art/ts-openai-shared": "0.500.6",
39
38
  "openai": "^6.7.0",
40
39
  "firebase": "^11.9.0",
41
40
  "firebase-admin": "13.4.0",