@fiado/api-invoker 3.0.35 → 3.0.36
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/bin/ai-engine-connector/AiEngineApi.d.ts +10 -0
- package/bin/ai-engine-connector/AiEngineApi.js +46 -0
- package/bin/ai-engine-connector/index.d.ts +2 -0
- package/bin/ai-engine-connector/index.js +18 -0
- package/bin/ai-engine-connector/interfaces/IAiEngineApi.d.ts +5 -0
- package/bin/ai-engine-connector/interfaces/IAiEngineApi.js +2 -0
- package/bin/container.config.js +4 -0
- package/bin/index.d.ts +1 -0
- package/bin/index.js +1 -0
- package/package.json +1 -1
- package/src/ai-engine-connector/AiEngineApi.ts +28 -0
- package/src/ai-engine-connector/index.ts +2 -0
- package/src/ai-engine-connector/interfaces/IAiEngineApi.ts +6 -0
- package/src/container.config.ts +5 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IHttpRequest } from "@fiado/http-client";
|
|
2
|
+
import { IAiEngineApi } from "./interfaces/IAiEngineApi";
|
|
3
|
+
import { AiAnalyzeResponse } from "@fiado/type-kit/bin/aiEngine";
|
|
4
|
+
import FiadoApiResponse from "@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse";
|
|
5
|
+
export declare class AiEngineApi implements IAiEngineApi {
|
|
6
|
+
private readonly httpRequest;
|
|
7
|
+
private readonly baseUrl;
|
|
8
|
+
constructor(httpRequest: IHttpRequest);
|
|
9
|
+
analyze(prompt: string, systemPrompt?: string, modelId?: string): Promise<FiadoApiResponse<AiAnalyzeResponse>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AiEngineApi = void 0;
|
|
19
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
20
|
+
const inversify_1 = require("inversify");
|
|
21
|
+
const logger_1 = require("@fiado/logger");
|
|
22
|
+
dotenv_1.default.config();
|
|
23
|
+
let AiEngineApi = class AiEngineApi {
|
|
24
|
+
constructor(httpRequest) {
|
|
25
|
+
this.httpRequest = httpRequest;
|
|
26
|
+
this.baseUrl = process.env.AI_ENGINE_LAMBDA_URL || "";
|
|
27
|
+
}
|
|
28
|
+
async analyze(prompt, systemPrompt, modelId) {
|
|
29
|
+
try {
|
|
30
|
+
const url = `${this.baseUrl}ai/analyze`;
|
|
31
|
+
const body = { prompt, systemPrompt, modelId };
|
|
32
|
+
logger_1.log.info(`Calling AI Engine at: ${url}`);
|
|
33
|
+
return await this.httpRequest.post(url, body, { 'operationName': 'aiAnalyze' });
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
logger_1.log.error('Error calling AI Engine from api-invoker', error);
|
|
37
|
+
throw new Error('Error calling AI Engine from api-invoker');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.AiEngineApi = AiEngineApi;
|
|
42
|
+
exports.AiEngineApi = AiEngineApi = __decorate([
|
|
43
|
+
(0, inversify_1.injectable)(),
|
|
44
|
+
__param(0, (0, inversify_1.inject)("IHttpRequest")),
|
|
45
|
+
__metadata("design:paramtypes", [Object])
|
|
46
|
+
], AiEngineApi);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./interfaces/IAiEngineApi"), exports);
|
|
18
|
+
__exportStar(require("./AiEngineApi"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AiAnalyzeResponse } from "@fiado/type-kit/bin/aiEngine";
|
|
2
|
+
import FiadoApiResponse from "@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse";
|
|
3
|
+
export interface IAiEngineApi {
|
|
4
|
+
analyze(prompt: string, systemPrompt?: string, modelId?: string): Promise<FiadoApiResponse<AiAnalyzeResponse>>;
|
|
5
|
+
}
|
package/bin/container.config.js
CHANGED
|
@@ -93,6 +93,8 @@ const TeamsNotificationPublisher_1 = __importDefault(require("./teams-connector/
|
|
|
93
93
|
// Legal document
|
|
94
94
|
const legalDocument_1 = require("./legalDocument");
|
|
95
95
|
const CountriesBusinessApi_1 = __importDefault(require("./countries-business/CountriesBusinessApi"));
|
|
96
|
+
// AI Engine connector
|
|
97
|
+
const ai_engine_connector_1 = require("./ai-engine-connector");
|
|
96
98
|
exports.apiInvokerBindings = new inversify_1.ContainerModule((bind) => {
|
|
97
99
|
// UTILS bindings
|
|
98
100
|
bind("InvokerUtils").to(InvokerUtils_1.InvokerUtils);
|
|
@@ -188,4 +190,6 @@ exports.apiInvokerBindings = new inversify_1.ContainerModule((bind) => {
|
|
|
188
190
|
bind("ILegalDocumentApi").to(legalDocument_1.LegalDocumentApi);
|
|
189
191
|
// Countries business
|
|
190
192
|
bind("ICountriesBusinessApi").to(CountriesBusinessApi_1.default);
|
|
193
|
+
// AI Engine connector
|
|
194
|
+
bind("IAiEngineApi").to(ai_engine_connector_1.AiEngineApi);
|
|
191
195
|
});
|
package/bin/index.d.ts
CHANGED
package/bin/index.js
CHANGED
|
@@ -83,3 +83,4 @@ __exportStar(require("./commission-business"), exports);
|
|
|
83
83
|
__exportStar(require("./platform-error-events"), exports);
|
|
84
84
|
__exportStar(require("./teams-connector"), exports);
|
|
85
85
|
__exportStar(require("./countries-business"), exports);
|
|
86
|
+
__exportStar(require("./ai-engine-connector"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiado/api-invoker",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.36",
|
|
4
4
|
"description": "Sirve como un puente entre diferentes funciones lambda, facilitando la comunicación entre ellas a través de invocaciones http",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"types": "bin/index.d.ts",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import { inject, injectable } from "inversify";
|
|
3
|
+
import { IHttpRequest } from "@fiado/http-client";
|
|
4
|
+
import { IAiEngineApi } from "./interfaces/IAiEngineApi";
|
|
5
|
+
import { AiAnalyzeRequest, AiAnalyzeResponse } from "@fiado/type-kit/bin/aiEngine";
|
|
6
|
+
import FiadoApiResponse from "@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse";
|
|
7
|
+
import { log } from "@fiado/logger";
|
|
8
|
+
dotenv.config();
|
|
9
|
+
|
|
10
|
+
@injectable()
|
|
11
|
+
export class AiEngineApi implements IAiEngineApi {
|
|
12
|
+
|
|
13
|
+
private readonly baseUrl = process.env.AI_ENGINE_LAMBDA_URL || "";
|
|
14
|
+
|
|
15
|
+
constructor(@inject("IHttpRequest") private readonly httpRequest: IHttpRequest) {}
|
|
16
|
+
|
|
17
|
+
public async analyze(prompt: string, systemPrompt?: string, modelId?: string): Promise<FiadoApiResponse<AiAnalyzeResponse>> {
|
|
18
|
+
try {
|
|
19
|
+
const url = `${this.baseUrl}ai/analyze`;
|
|
20
|
+
const body: AiAnalyzeRequest = { prompt, systemPrompt, modelId };
|
|
21
|
+
log.info(`Calling AI Engine at: ${url}`);
|
|
22
|
+
return await this.httpRequest.post(url, body, { 'operationName': 'aiAnalyze' });
|
|
23
|
+
} catch (error) {
|
|
24
|
+
log.error('Error calling AI Engine from api-invoker', error as Error);
|
|
25
|
+
throw new Error('Error calling AI Engine from api-invoker');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AiAnalyzeResponse } from "@fiado/type-kit/bin/aiEngine";
|
|
2
|
+
import FiadoApiResponse from "@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse";
|
|
3
|
+
|
|
4
|
+
export interface IAiEngineApi {
|
|
5
|
+
analyze(prompt: string, systemPrompt?: string, modelId?: string): Promise<FiadoApiResponse<AiAnalyzeResponse>>;
|
|
6
|
+
}
|
package/src/container.config.ts
CHANGED
|
@@ -137,6 +137,8 @@ import { ILegalDocumentApi, LegalDocumentApi } from "./legalDocument";
|
|
|
137
137
|
// Countries business
|
|
138
138
|
import { ICountriesBusinessApi } from "./countries-business";
|
|
139
139
|
import CountriesBusinessApi from "./countries-business/CountriesBusinessApi";
|
|
140
|
+
// AI Engine connector
|
|
141
|
+
import { IAiEngineApi, AiEngineApi } from "./ai-engine-connector";
|
|
140
142
|
|
|
141
143
|
export const apiInvokerBindings = new ContainerModule((bind: interfaces.Bind) => {
|
|
142
144
|
// UTILS bindings
|
|
@@ -240,4 +242,7 @@ export const apiInvokerBindings = new ContainerModule((bind: interfaces.Bind) =>
|
|
|
240
242
|
|
|
241
243
|
// Countries business
|
|
242
244
|
bind<ICountriesBusinessApi>("ICountriesBusinessApi").to(CountriesBusinessApi);
|
|
245
|
+
|
|
246
|
+
// AI Engine connector
|
|
247
|
+
bind<IAiEngineApi>("IAiEngineApi").to(AiEngineApi);
|
|
243
248
|
});
|
package/src/index.ts
CHANGED