@dnax/core 0.3.5 → 0.3.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.
package/index.ts CHANGED
@@ -7,7 +7,6 @@ import define from "./define";
7
7
  import moment from "moment";
8
8
  import * as utils from "./utils";
9
9
 
10
- import * as ai from "./ai";
11
10
  /**
12
11
  * v is internal data validation and based of Joi validation.
13
12
  * Note : v is an alias of Joi object API .
@@ -15,4 +14,4 @@ import * as ai from "./ai";
15
14
  */
16
15
  const v = Joi;
17
16
 
18
- export { runApp, define, utils, useRest, ai, v };
17
+ export { runApp, define, utils, useRest, v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,11 +16,9 @@
16
16
  "dependencies": {
17
17
  "@clack/prompts": "^0.7.0",
18
18
  "@colors/colors": "^1.6.0",
19
- "@google/generative-ai": "0.14.0",
20
19
  "@lukeed/ms": "^2.0.2",
21
20
  "@types/jsonwebtoken": "^9.0.6",
22
21
  "boxen": "^7.1.1",
23
- "bree": "^9.2.4",
24
22
  "chokidar": "^3.6.0",
25
23
  "clean-deep": "^3.4.0",
26
24
  "collect.js": "^4.36.1",
@@ -30,7 +28,6 @@
30
28
  "find-open-port": "^2.0.3",
31
29
  "generate-unique-id": "^2.0.3",
32
30
  "hono": "^4.4.3",
33
- "hono-sessions": "^0.5.8",
34
31
  "joi": "^17.13.3",
35
32
  "json-joy": "^16.8.0",
36
33
  "jsonwebtoken": "^9.0.2",
package/ai/gemini.ts DELETED
@@ -1,97 +0,0 @@
1
- import { GoogleGenerativeAI } from "@google/generative-ai";
2
- import { Cfg } from "../config";
3
- import { getCollection } from "../lib/collection";
4
-
5
- class Gemini {
6
- #genAI: InstanceType<typeof GoogleGenerativeAI>;
7
- #api_key: any;
8
- #tenant_id: any;
9
- #systemInstruction: string | undefined = "";
10
- #model: string = "gemini-1.5-flash";
11
-
12
- constructor(
13
- opts: {
14
- tenant_id?: string;
15
- key?: string;
16
- systemInstruction?: string;
17
- model?: string;
18
- } = {
19
- model: "gemini-1.5-flash",
20
- }
21
- ) {
22
- this.#genAI = new GoogleGenerativeAI(
23
- opts.key || Cfg.ai?.key || process.env.AI_KEY || ""
24
- );
25
- this.#systemInstruction = opts.systemInstruction;
26
- this.#tenant_id = opts?.tenant_id || null;
27
- this.#api_key = process.env.key || Cfg.ai?.key || "";
28
- this.#model = opts.model || "gemini-1.5-flash";
29
- }
30
-
31
- async generateContent(
32
- content: string,
33
- options: {
34
- systemInstruction: string;
35
- generationConfig?: {
36
- responseMimeType: string;
37
- };
38
- } = {
39
- systemInstruction: "",
40
- }
41
- ) {
42
- let model = this.#genAI.getGenerativeModel({
43
- model: this.#model,
44
- systemInstruction: options.systemInstruction || this.#systemInstruction,
45
- generationConfig: options.generationConfig || {},
46
- });
47
- let result = await model.generateContent(content);
48
- let response = await result.response.text();
49
- return response;
50
- }
51
-
52
- /* async generateFilter(opts: { collection: string; prompt: string }) {
53
- let col = getCollection(opts.collection, this.#tenant_id);
54
- let model = this.#genAI.getGenerativeModel({
55
- model: "gemini-1.5-flash",
56
- systemInstruction: `
57
-
58
- En te basant les informations json suivantes :
59
- Nom de la base de donnée : ${col?.slug}
60
- et de la structure des champs suivants :
61
- ${col?.fields}
62
-
63
- Merci de fourni un filtre $match(aggregate) de mongodb qui correspond à la demande du
64
- l'utilisateur et de retourner ce $match sous forme de JSON parse
65
-
66
- - Si la demande ne correspond pas à une generation de filter $match
67
- merci de retourner "{}" comme réponse en json parse .
68
-
69
- Exemple de format json de retour : {"$match":{"nom":"John"}}
70
-
71
- `,
72
- });
73
- let result = await model.generateContent(opts.prompt);
74
- let response = await result.response.text();
75
-
76
- return extractJson(response);
77
- } */
78
- }
79
- function extractJson(chaine: string) {
80
- try {
81
- // Utiliser une expression régulière pour extraire le contenu JSON
82
- const match = chaine.match(/\{.*\}/);
83
- if (match) {
84
- // Extraire le contenu JSON
85
- const jsonStr = match[0];
86
- // Convertir la chaîne JSON en objet JavaScript
87
- const jsonData = JSON.parse(jsonStr);
88
- return jsonData;
89
- } else {
90
- return null;
91
- }
92
- } catch (err: any) {
93
- console.log(err?.message);
94
- return {};
95
- }
96
- }
97
- export { Gemini };
package/ai/index.ts DELETED
@@ -1,2 +0,0 @@
1
- import { Gemini } from "./gemini";
2
- export { Gemini };
package/ai/mistral.ts DELETED
@@ -1,63 +0,0 @@
1
- import { GoogleGenerativeAI } from "@google/generative-ai";
2
- import { Cfg } from "../config";
3
- import { getCollection } from "../lib/collection";
4
-
5
- class Mistral {
6
- #genAI: InstanceType<typeof GoogleGenerativeAI>;
7
- #api_key: any;
8
- #tenant_id: any;
9
-
10
- constructor(opts: { tenant_id?: string; key?: string } = {}) {
11
- this.#genAI = new GoogleGenerativeAI(
12
- opts.key || Cfg.ai?.key || process.env.API_KEY || ""
13
- );
14
- this.#tenant_id = opts?.tenant_id || null;
15
- this.#api_key = process.env.key || Cfg.ai?.key || "";
16
- }
17
-
18
- async generateFilter(opts: { collection: string; prompt: string }) {
19
- let col = getCollection(opts.collection, this.#tenant_id);
20
- let model = this.#genAI.getGenerativeModel({
21
- model: "gemini-1.5-flash",
22
- systemInstruction: `
23
-
24
- En te basant les informations json suivantes :
25
- Nom de la base de donnée : ${col?.slug}
26
- et de la structure des champs suivants :
27
- ${col?.fields}
28
-
29
- Merci de fourni un filtre $match(aggregate) de mongodb qui correspond à la demande du
30
- l'utilisateur et de retourner ce $match sous forme de JSON parse
31
-
32
- - Si la demande ne correspond pas à une generation de filter $match
33
- merci de retourner "{}" comme réponse en json parse .
34
-
35
- Exemple de format json de retour : {"$match":{"nom":"John"}}
36
-
37
- `,
38
- });
39
- let result = await model.generateContent(opts.prompt);
40
- let response = await result.response.text();
41
-
42
- return extractJson(response);
43
- }
44
- }
45
- function extractJson(chaine: string) {
46
- try {
47
- // Utiliser une expression régulière pour extraire le contenu JSON
48
- const match = chaine.match(/\{.*\}/);
49
- if (match) {
50
- // Extraire le contenu JSON
51
- const jsonStr = match[0];
52
- // Convertir la chaîne JSON en objet JavaScript
53
- const jsonData = JSON.parse(jsonStr);
54
- return jsonData;
55
- } else {
56
- return null;
57
- }
58
- } catch (err: any) {
59
- console.log(err?.message);
60
- return {};
61
- }
62
- }
63
- export { Mistral };