@drax/ai-back 3.33.0 → 3.35.1

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.
Files changed (48) hide show
  1. package/dist/config/GoogleAiConfig.js +0 -1
  2. package/dist/config/OllamaAiConfig.js +9 -0
  3. package/dist/factory/AiProviderFactory.js +4 -0
  4. package/dist/factory/GoogleAiProviderFactory.js +1 -1
  5. package/dist/factory/OllamaAiProviderFactory.js +14 -0
  6. package/dist/index.js +4 -1
  7. package/dist/providers/OllamaAiProvider.js +342 -0
  8. package/package.json +2 -2
  9. package/src/config/GoogleAiConfig.ts +0 -1
  10. package/src/config/OllamaAiConfig.ts +14 -0
  11. package/src/factory/AiProviderFactory.ts +4 -0
  12. package/src/factory/GoogleAiProviderFactory.ts +1 -1
  13. package/src/factory/OllamaAiProviderFactory.ts +27 -0
  14. package/src/index.ts +6 -0
  15. package/src/providers/OllamaAiProvider.ts +469 -0
  16. package/tsconfig.tsbuildinfo +1 -1
  17. package/types/config/GoogleAiConfig.d.ts +0 -1
  18. package/types/config/GoogleAiConfig.d.ts.map +1 -1
  19. package/types/config/OllamaAiConfig.d.ts +9 -0
  20. package/types/config/OllamaAiConfig.d.ts.map +1 -0
  21. package/types/factory/AiProviderFactory.d.ts.map +1 -1
  22. package/types/factory/OllamaAiProviderFactory.d.ts +8 -0
  23. package/types/factory/OllamaAiProviderFactory.d.ts.map +1 -0
  24. package/types/index.d.ts.map +1 -1
  25. package/types/providers/OllamaAiProvider.d.ts +78 -0
  26. package/types/providers/OllamaAiProvider.d.ts.map +1 -0
  27. package/.env +0 -4
  28. package/dist/agents/ChatbotTaskService.js +0 -143
  29. package/dist/agents/ChatbotTaskTools.js +0 -756
  30. package/dist/controllers/AIController.js +0 -150
  31. package/dist/interfaces/IAILog.js +0 -1
  32. package/dist/routes/ChatbotTaskRoutes.js +0 -8
  33. package/dist/tools/ToolBuilder.js +0 -243
  34. package/dist/vectors/ChromaVector.js +0 -65
  35. package/types/agents/ChatbotTaskService.d.ts +0 -42
  36. package/types/agents/ChatbotTaskService.d.ts.map +0 -1
  37. package/types/agents/ChatbotTaskTools.d.ts +0 -54
  38. package/types/agents/ChatbotTaskTools.d.ts.map +0 -1
  39. package/types/controllers/AIController.d.ts +0 -25
  40. package/types/controllers/AIController.d.ts.map +0 -1
  41. package/types/interfaces/IAILog.d.ts +0 -77
  42. package/types/interfaces/IAILog.d.ts.map +0 -1
  43. package/types/routes/ChatbotTaskRoutes.d.ts +0 -4
  44. package/types/routes/ChatbotTaskRoutes.d.ts.map +0 -1
  45. package/types/tools/ToolBuilder.d.ts +0 -47
  46. package/types/tools/ToolBuilder.d.ts.map +0 -1
  47. package/types/vectors/ChromaVector.d.ts +0 -21
  48. package/types/vectors/ChromaVector.d.ts.map +0 -1
@@ -1,7 +1,6 @@
1
1
  var GoogleAiConfig;
2
2
  (function (GoogleAiConfig) {
3
3
  GoogleAiConfig["GoogleAiApiKey"] = "GOOGLE_AI_API_KEY";
4
- GoogleAiConfig["GoogleApiKey"] = "GOOGLE_API_KEY";
5
4
  GoogleAiConfig["GoogleAiModel"] = "GOOGLE_AI_MODEL";
6
5
  GoogleAiConfig["GoogleAiVisionModel"] = "GOOGLE_AI_VISION_MODEL";
7
6
  })(GoogleAiConfig || (GoogleAiConfig = {}));
@@ -0,0 +1,9 @@
1
+ var OllamaAiConfig;
2
+ (function (OllamaAiConfig) {
3
+ OllamaAiConfig["OllamaAiBaseUrl"] = "OLLAMA_AI_BASE_URL";
4
+ OllamaAiConfig["OllamaAiModel"] = "OLLAMA_AI_MODEL";
5
+ OllamaAiConfig["OllamaAiVisionModel"] = "OLLAMA_AI_VISION_MODEL";
6
+ OllamaAiConfig["OllamaAiEmbeddingModel"] = "OLLAMA_AI_EMBEDDING_MODEL";
7
+ })(OllamaAiConfig || (OllamaAiConfig = {}));
8
+ export default OllamaAiConfig;
9
+ export { OllamaAiConfig };
@@ -1,5 +1,6 @@
1
1
  import OpenAiProviderFactory from "./OpenAiProviderFactory.js";
2
2
  import GoogleAiProviderFactory from "./GoogleAiProviderFactory.js";
3
+ import OllamaAiProviderFactory from "./OllamaAiProviderFactory.js";
3
4
  class AiProviderFactory {
4
5
  static instance(provider = 'OpenAi') {
5
6
  if (!AiProviderFactory.singletons[provider]) {
@@ -10,6 +11,9 @@ class AiProviderFactory {
10
11
  case 'GoogleAi':
11
12
  AiProviderFactory.singletons[provider] = GoogleAiProviderFactory.instance();
12
13
  break;
14
+ case 'OllamaAi':
15
+ AiProviderFactory.singletons[provider] = OllamaAiProviderFactory.instance();
16
+ break;
13
17
  default:
14
18
  throw new Error(`Unsupported AI provider: ${provider}`);
15
19
  }
@@ -5,7 +5,7 @@ import AILogServiceFactory from "./services/AILogServiceFactory.js";
5
5
  class GoogleAiProviderFactory {
6
6
  static instance() {
7
7
  if (!GoogleAiProviderFactory.singleton) {
8
- GoogleAiProviderFactory.singleton = new GoogleAiProvider(DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiApiKey) ?? DraxConfig.getOrLoad(GoogleAiConfig.GoogleApiKey), DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiModel), DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiVisionModel), AILogServiceFactory.instance);
8
+ GoogleAiProviderFactory.singleton = new GoogleAiProvider(DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiApiKey), DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiModel), DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiVisionModel), AILogServiceFactory.instance);
9
9
  }
10
10
  return GoogleAiProviderFactory.singleton;
11
11
  }
@@ -0,0 +1,14 @@
1
+ import { DraxConfig } from "@drax/common-back";
2
+ import OllamaAiConfig from "../config/OllamaAiConfig.js";
3
+ import OllamaAiProvider from "../providers/OllamaAiProvider.js";
4
+ import AILogServiceFactory from "./services/AILogServiceFactory.js";
5
+ class OllamaAiProviderFactory {
6
+ static instance() {
7
+ if (!OllamaAiProviderFactory.singleton) {
8
+ OllamaAiProviderFactory.singleton = new OllamaAiProvider(DraxConfig.getOrLoad(OllamaAiConfig.OllamaAiBaseUrl, "string", "http://localhost:11434"), DraxConfig.getOrLoad(OllamaAiConfig.OllamaAiModel), DraxConfig.getOrLoad(OllamaAiConfig.OllamaAiVisionModel), DraxConfig.getOrLoad(OllamaAiConfig.OllamaAiEmbeddingModel), AILogServiceFactory.instance);
9
+ }
10
+ return OllamaAiProviderFactory.singleton;
11
+ }
12
+ }
13
+ export default OllamaAiProviderFactory;
14
+ export { OllamaAiProviderFactory };
package/dist/index.js CHANGED
@@ -1,15 +1,18 @@
1
1
  import { OpenAiConfig } from "./config/OpenAiConfig.js";
2
2
  import { GoogleAiConfig } from "./config/GoogleAiConfig.js";
3
+ import { OllamaAiConfig } from "./config/OllamaAiConfig.js";
3
4
  import { AILogSchema, AILogBaseSchema } from "./schemas/AILogSchema.js";
4
5
  import AILogModel from "./models/AILogModel.js";
5
6
  import AILogMongoRepository from "./repository/mongo/AILogMongoRepository.js";
6
7
  import AILogSqliteRepository from "./repository/sqlite/AILogSqliteRepository.js";
7
8
  import { OpenAiProviderFactory } from "./factory/OpenAiProviderFactory.js";
8
9
  import { GoogleAiProviderFactory } from "./factory/GoogleAiProviderFactory.js";
10
+ import { OllamaAiProviderFactory } from "./factory/OllamaAiProviderFactory.js";
9
11
  import { AiProviderFactory } from "./factory/AiProviderFactory.js";
10
12
  import AILogServiceFactory from "./factory/services/AILogServiceFactory.js";
11
13
  import { OpenAiProvider } from "./providers/OpenAiProvider.js";
12
14
  import { GoogleAiProvider } from "./providers/GoogleAiProvider.js";
15
+ import { OllamaAiProvider } from "./providers/OllamaAiProvider.js";
13
16
  import { BuilderTool } from "./tools/BuilderTool.js";
14
17
  import { KnowledgeService } from "./services/KnowledgeService.js";
15
18
  import { AILogService } from "./services/AILogService.js";
@@ -27,7 +30,7 @@ import AIRoutes from "./routes/AIRoutes.js";
27
30
  import DraxAgentRoutes from "./routes/DraxAgentRoutes.js";
28
31
  import AgentSessionRoutes from "./routes/AgentSessionRoutes.js";
29
32
  import { DraxAgent } from "./agents/DraxAgent.js";
30
- export { OpenAiConfig, GoogleAiConfig, AILogSchema, AILogBaseSchema, AILogModel, AILogMongoRepository, AILogSqliteRepository, OpenAiProviderFactory, GoogleAiProviderFactory, AiProviderFactory, AILogServiceFactory, OpenAiProvider, GoogleAiProvider, BuilderTool,
33
+ export { OpenAiConfig, GoogleAiConfig, OllamaAiConfig, AILogSchema, AILogBaseSchema, AILogModel, AILogMongoRepository, AILogSqliteRepository, OpenAiProviderFactory, GoogleAiProviderFactory, OllamaAiProviderFactory, AiProviderFactory, AILogServiceFactory, OpenAiProvider, GoogleAiProvider, OllamaAiProvider, BuilderTool,
31
34
  //Service
32
35
  KnowledgeService, AILogService,
33
36
  //Permissions
@@ -0,0 +1,342 @@
1
+ import { toJSONSchema } from "zod";
2
+ class OllamaAiProvider {
3
+ constructor(baseUrl, model, visionModel, embeddingModel, aiLogService) {
4
+ if (!baseUrl) {
5
+ throw new Error("Ollama AI baseUrl required");
6
+ }
7
+ if (!model) {
8
+ throw new Error("Ollama AI model required");
9
+ }
10
+ this._baseUrl = baseUrl.replace(/\/+$/, "");
11
+ this._model = model;
12
+ this._visionModel = visionModel;
13
+ this._embeddingModel = embeddingModel;
14
+ this._aiLogService = aiLogService;
15
+ }
16
+ get model() {
17
+ if (!this._model) {
18
+ throw new Error("Ollama AI model not found");
19
+ }
20
+ return this._model;
21
+ }
22
+ get visionModel() {
23
+ return this._visionModel;
24
+ }
25
+ get embeddingModel() {
26
+ return this._embeddingModel ?? this.model;
27
+ }
28
+ async post(path, body) {
29
+ const response = await fetch(`${this._baseUrl}${path}`, {
30
+ method: "POST",
31
+ headers: {
32
+ "Content-Type": "application/json",
33
+ },
34
+ body: JSON.stringify(body),
35
+ });
36
+ if (!response.ok) {
37
+ const errorText = await response.text();
38
+ throw new Error(`Ollama AI request failed (${response.status}): ${errorText}`);
39
+ }
40
+ return await response.json();
41
+ }
42
+ async buildUserMessage(input) {
43
+ if (input.userContent && input.userContent.length > 0) {
44
+ return await this.mapContentPartsToMessage(input.userContent);
45
+ }
46
+ if (input.userImages && input.userImages.length > 0) {
47
+ return {
48
+ role: "user",
49
+ content: input.userInput ?? "",
50
+ images: await Promise.all(input.userImages.map(image => this.imageUrlToBase64(image.url))),
51
+ };
52
+ }
53
+ return {
54
+ role: "user",
55
+ content: input.userInput ?? "",
56
+ };
57
+ }
58
+ async mapContentPartsToMessage(content, role = "user") {
59
+ const text = [];
60
+ const images = [];
61
+ for (const part of content) {
62
+ if (part.type === "text") {
63
+ text.push(part.text);
64
+ continue;
65
+ }
66
+ images.push(await this.imageUrlToBase64(part.imageUrl));
67
+ }
68
+ return {
69
+ role,
70
+ content: text.join("\n"),
71
+ ...(images.length > 0 ? { images } : {}),
72
+ };
73
+ }
74
+ async imageUrlToBase64(url) {
75
+ const dataUrlMatch = url.match(/^data:[^;,]+;base64,(.+)$/);
76
+ if (dataUrlMatch) {
77
+ return dataUrlMatch[1];
78
+ }
79
+ const response = await fetch(url);
80
+ if (!response.ok) {
81
+ throw new Error(`Ollama AI image request failed (${response.status}): ${url}`);
82
+ }
83
+ const buffer = Buffer.from(await response.arrayBuffer());
84
+ return buffer.toString("base64");
85
+ }
86
+ async mapHistory(history = []) {
87
+ const messages = [];
88
+ for (const message of history) {
89
+ if (typeof message.content === "string") {
90
+ messages.push({
91
+ role: message.role,
92
+ content: message.content,
93
+ });
94
+ continue;
95
+ }
96
+ messages.push(await this.mapContentPartsToMessage(message.content, message.role));
97
+ }
98
+ return messages;
99
+ }
100
+ hasImageInput(input) {
101
+ if (input.userImages && input.userImages.length > 0) {
102
+ return true;
103
+ }
104
+ if (input.userContent?.some(part => part.type === 'image')) {
105
+ return true;
106
+ }
107
+ return input.history?.some(message => Array.isArray(message.content) && message.content.some(part => part.type === 'image')) ?? false;
108
+ }
109
+ serializePromptInput(input, systemPrompt) {
110
+ return JSON.stringify({
111
+ systemPrompt,
112
+ history: input.history,
113
+ userInput: input.userInput,
114
+ userContent: input.userContent,
115
+ memory: input.memory,
116
+ knowledgeBase: input.knowledgeBase,
117
+ tools: input.tools?.map(tool => ({
118
+ name: tool.name,
119
+ description: tool.description,
120
+ parameters: tool.parameters,
121
+ })),
122
+ });
123
+ }
124
+ serializePromptOutput(output) {
125
+ if (typeof output === "string") {
126
+ return output;
127
+ }
128
+ if (output === null || output === undefined) {
129
+ return undefined;
130
+ }
131
+ return JSON.stringify(output);
132
+ }
133
+ buildLogPayload(input, params) {
134
+ return {
135
+ provider: "ollamaai",
136
+ model: params.model,
137
+ operationTitle: input.operationTitle,
138
+ operationGroup: input.operationGroup,
139
+ ip: input.ip,
140
+ userAgent: input.userAgent,
141
+ input: this.serializePromptInput(input, params.systemPrompt),
142
+ inputImages: input.userImages?.map(image => ({
143
+ url: image.url,
144
+ })) ?? input.userContent
145
+ ?.filter(part => part.type === "image")
146
+ .map(part => ({
147
+ url: part.imageUrl,
148
+ })),
149
+ inputFiles: input.inputFiles,
150
+ inputTokens: params.inputTokens,
151
+ outputTokens: params.outputTokens,
152
+ tokens: params.tokens,
153
+ startedAt: params.startedAt,
154
+ endedAt: params.endedAt,
155
+ responseTime: params.endedAt ? `${params.endedAt.getTime() - params.startedAt.getTime()}ms` : undefined,
156
+ output: this.serializePromptOutput(params.output),
157
+ success: params.success,
158
+ errorMessage: params.errorMessage,
159
+ tenant: input.tenant,
160
+ user: input.user,
161
+ };
162
+ }
163
+ async registerPromptLog(input, params) {
164
+ if (!this._aiLogService) {
165
+ return;
166
+ }
167
+ try {
168
+ await this._aiLogService.create(this.buildLogPayload(input, params));
169
+ }
170
+ catch (e) {
171
+ console.error("Error registerPromptLog", {
172
+ name: e?.name,
173
+ message: e?.message,
174
+ stack: e?.stack,
175
+ });
176
+ }
177
+ }
178
+ async generateEmbedding({ text, model }) {
179
+ const response = await this.post("/api/embed", {
180
+ model: model ?? this.embeddingModel,
181
+ input: text,
182
+ });
183
+ return response.embeddings?.[0] ?? response.embedding ?? [];
184
+ }
185
+ mapTools(tools = []) {
186
+ return tools.map(tool => ({
187
+ type: "function",
188
+ function: {
189
+ name: tool.name,
190
+ description: tool.description,
191
+ parameters: tool.parameters ?? {
192
+ type: "object",
193
+ properties: {},
194
+ additionalProperties: false,
195
+ },
196
+ },
197
+ }));
198
+ }
199
+ normalizeResponseFormat(input) {
200
+ if (input.zodSchema) {
201
+ return toJSONSchema(input.zodSchema, {
202
+ target: "draft-7",
203
+ });
204
+ }
205
+ if (!input.jsonSchema) {
206
+ return undefined;
207
+ }
208
+ const jsonSchema = input.jsonSchema;
209
+ if (jsonSchema.type === "json_schema" && jsonSchema.json_schema?.schema) {
210
+ return jsonSchema.json_schema.schema;
211
+ }
212
+ return jsonSchema;
213
+ }
214
+ parseToolArguments(args) {
215
+ if (!args) {
216
+ return {};
217
+ }
218
+ if (typeof args === "object") {
219
+ return args;
220
+ }
221
+ try {
222
+ return JSON.parse(args);
223
+ }
224
+ catch (e) {
225
+ throw new Error(`Invalid tool arguments: ${args}`);
226
+ }
227
+ }
228
+ serializeToolOutput(output) {
229
+ if (typeof output === "string") {
230
+ return output;
231
+ }
232
+ if (output === undefined) {
233
+ return "";
234
+ }
235
+ return JSON.stringify(output);
236
+ }
237
+ async buildToolMessages(toolCalls = [], tools = []) {
238
+ const toolMessages = [];
239
+ for (const toolCall of toolCalls) {
240
+ const toolName = toolCall.function?.name;
241
+ const tool = tools.find(t => t.name === toolName);
242
+ if (!tool) {
243
+ throw new Error(`Tool not found: ${toolName}`);
244
+ }
245
+ const args = this.parseToolArguments(toolCall.function?.arguments);
246
+ const output = await tool.execute(args);
247
+ toolMessages.push({
248
+ role: "tool",
249
+ name: toolName,
250
+ content: this.serializeToolOutput(output),
251
+ });
252
+ }
253
+ return toolMessages;
254
+ }
255
+ async prompt(input) {
256
+ if (!input.systemPrompt) {
257
+ throw new Error("systemPrompt required");
258
+ }
259
+ let systemPrompt = input.systemPrompt;
260
+ if (input.memory && input.memory.length > 0) {
261
+ systemPrompt += `\n\n ${input.memoryHeader ?? '[MEMORIA]'}\n ${input.memory.map(m => `${m.key}: ${m.value}`).join('\n')}`;
262
+ }
263
+ if (input.knowledgeBase && input.knowledgeBase.length > 0) {
264
+ systemPrompt += `\n\n${input.knowledgeBaseHeader ?? '[BASE DE CONOCIMIENTO]'}\n ${input.knowledgeBase.join('\n')}`;
265
+ }
266
+ const model = input.model ?? (this.hasImageInput(input) ? this.visionModel ?? this.model : this.model);
267
+ const startedAt = new Date();
268
+ const startTime = performance.now();
269
+ let tokens = 0;
270
+ let inputTokens = 0;
271
+ let outputTokens = 0;
272
+ try {
273
+ const messages = [
274
+ { role: 'system', content: systemPrompt },
275
+ ...await this.mapHistory(input.history),
276
+ await this.buildUserMessage(input),
277
+ ];
278
+ const tools = input.tools ?? [];
279
+ const maxIterations = input.toolMaxIterations ?? 5;
280
+ const responseFormat = this.normalizeResponseFormat(input);
281
+ let output;
282
+ for (let iteration = 0; iteration < maxIterations; iteration++) {
283
+ const response = await this.post("/api/chat", {
284
+ model,
285
+ messages,
286
+ stream: false,
287
+ ...(responseFormat ? { format: responseFormat } : {}),
288
+ ...(tools.length > 0 ? { tools: this.mapTools(tools) } : {}),
289
+ });
290
+ inputTokens += response.prompt_eval_count ?? 0;
291
+ outputTokens += response.eval_count ?? 0;
292
+ tokens += (response.prompt_eval_count ?? 0) + (response.eval_count ?? 0);
293
+ const message = response.message ?? {};
294
+ const toolCalls = message.tool_calls ?? [];
295
+ if (toolCalls.length === 0) {
296
+ output = message.content ?? response.response ?? "";
297
+ break;
298
+ }
299
+ messages.push(message);
300
+ messages.push(...await this.buildToolMessages(toolCalls, tools));
301
+ }
302
+ if (output === undefined) {
303
+ throw new Error(`Tool max iterations reached: ${maxIterations}`);
304
+ }
305
+ const endTime = performance.now();
306
+ const time = endTime - startTime;
307
+ const endedAt = new Date();
308
+ await this.registerPromptLog(input, {
309
+ model,
310
+ systemPrompt,
311
+ startedAt,
312
+ endedAt,
313
+ inputTokens,
314
+ outputTokens,
315
+ tokens,
316
+ output,
317
+ success: true,
318
+ });
319
+ return {
320
+ output,
321
+ tokens,
322
+ inputTokens,
323
+ outputTokens,
324
+ time
325
+ };
326
+ }
327
+ catch (e) {
328
+ const endedAt = new Date();
329
+ await this.registerPromptLog(input, {
330
+ model,
331
+ systemPrompt,
332
+ startedAt,
333
+ endedAt,
334
+ success: false,
335
+ errorMessage: e?.message,
336
+ });
337
+ throw e;
338
+ }
339
+ }
340
+ }
341
+ export default OllamaAiProvider;
342
+ export { OllamaAiProvider };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.33.0",
6
+ "version": "3.35.1",
7
7
  "description": "Ai utils",
8
8
  "main": "dist/index.js",
9
9
  "types": "types/index.d.ts",
@@ -46,5 +46,5 @@
46
46
  "typescript": "^5.9.3",
47
47
  "vitest": "^3.0.8"
48
48
  },
49
- "gitHead": "e914874dd8474ca01a898be89423a85c7fabaee6"
49
+ "gitHead": "5c5d65ae83b6da98c044cc868150e5e1780e18ca"
50
50
  }
@@ -2,7 +2,6 @@
2
2
  enum GoogleAiConfig {
3
3
 
4
4
  GoogleAiApiKey = "GOOGLE_AI_API_KEY",
5
- GoogleApiKey = "GOOGLE_API_KEY",
6
5
  GoogleAiModel = "GOOGLE_AI_MODEL",
7
6
  GoogleAiVisionModel = "GOOGLE_AI_VISION_MODEL",
8
7
 
@@ -0,0 +1,14 @@
1
+
2
+ enum OllamaAiConfig {
3
+
4
+ OllamaAiBaseUrl = "OLLAMA_AI_BASE_URL",
5
+ OllamaAiModel = "OLLAMA_AI_MODEL",
6
+ OllamaAiVisionModel = "OLLAMA_AI_VISION_MODEL",
7
+ OllamaAiEmbeddingModel = "OLLAMA_AI_EMBEDDING_MODEL",
8
+
9
+ }
10
+
11
+
12
+ export default OllamaAiConfig;
13
+
14
+ export {OllamaAiConfig}
@@ -1,6 +1,7 @@
1
1
  import type {IAIProvider} from "../interfaces/IAIProvider"
2
2
  import OpenAiProviderFactory from "./OpenAiProviderFactory.js";
3
3
  import GoogleAiProviderFactory from "./GoogleAiProviderFactory.js";
4
+ import OllamaAiProviderFactory from "./OllamaAiProviderFactory.js";
4
5
 
5
6
  class AiProviderFactory {
6
7
  private static singletons: Record<string, IAIProvider> = {};
@@ -14,6 +15,9 @@ class AiProviderFactory {
14
15
  case 'GoogleAi':
15
16
  AiProviderFactory.singletons[provider] = GoogleAiProviderFactory.instance()
16
17
  break;
18
+ case 'OllamaAi':
19
+ AiProviderFactory.singletons[provider] = OllamaAiProviderFactory.instance()
20
+ break;
17
21
  default:
18
22
  throw new Error(`Unsupported AI provider: ${provider}`);
19
23
  }
@@ -10,7 +10,7 @@ class GoogleAiProviderFactory {
10
10
  public static instance(): IAIProvider {
11
11
  if (!GoogleAiProviderFactory.singleton) {
12
12
  GoogleAiProviderFactory.singleton = new GoogleAiProvider(
13
- DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiApiKey) ?? DraxConfig.getOrLoad(GoogleAiConfig.GoogleApiKey),
13
+ DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiApiKey),
14
14
  DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiModel),
15
15
  DraxConfig.getOrLoad(GoogleAiConfig.GoogleAiVisionModel),
16
16
  AILogServiceFactory.instance
@@ -0,0 +1,27 @@
1
+ import {DraxConfig} from "@drax/common-back";
2
+ import OllamaAiConfig from "../config/OllamaAiConfig.js";
3
+ import type {IAIProvider} from "../interfaces/IAIProvider"
4
+ import OllamaAiProvider from "../providers/OllamaAiProvider.js";
5
+ import AILogServiceFactory from "./services/AILogServiceFactory.js";
6
+
7
+ class OllamaAiProviderFactory {
8
+ private static singleton: IAIProvider;
9
+
10
+ public static instance(): IAIProvider {
11
+ if (!OllamaAiProviderFactory.singleton) {
12
+ OllamaAiProviderFactory.singleton = new OllamaAiProvider(
13
+ DraxConfig.getOrLoad(OllamaAiConfig.OllamaAiBaseUrl, "string", "http://localhost:11434"),
14
+ DraxConfig.getOrLoad(OllamaAiConfig.OllamaAiModel),
15
+ DraxConfig.getOrLoad(OllamaAiConfig.OllamaAiVisionModel),
16
+ DraxConfig.getOrLoad(OllamaAiConfig.OllamaAiEmbeddingModel),
17
+ AILogServiceFactory.instance
18
+ );
19
+ }
20
+ return OllamaAiProviderFactory.singleton;
21
+ }
22
+ }
23
+
24
+ export default OllamaAiProviderFactory
25
+ export {
26
+ OllamaAiProviderFactory
27
+ }
package/src/index.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  import {OpenAiConfig} from "./config/OpenAiConfig.js";
2
2
  import {GoogleAiConfig} from "./config/GoogleAiConfig.js";
3
+ import {OllamaAiConfig} from "./config/OllamaAiConfig.js";
3
4
  import {AILogSchema, AILogBaseSchema} from "./schemas/AILogSchema.js";
4
5
  import AILogModel from "./models/AILogModel.js";
5
6
  import AILogMongoRepository from "./repository/mongo/AILogMongoRepository.js";
6
7
  import AILogSqliteRepository from "./repository/sqlite/AILogSqliteRepository.js";
7
8
  import {OpenAiProviderFactory} from "./factory/OpenAiProviderFactory.js";
8
9
  import {GoogleAiProviderFactory} from "./factory/GoogleAiProviderFactory.js";
10
+ import {OllamaAiProviderFactory} from "./factory/OllamaAiProviderFactory.js";
9
11
  import {AiProviderFactory} from "./factory/AiProviderFactory.js";
10
12
  import AILogServiceFactory from "./factory/services/AILogServiceFactory.js";
11
13
  import {OpenAiProvider} from "./providers/OpenAiProvider.js";
12
14
  import {GoogleAiProvider} from "./providers/GoogleAiProvider.js";
15
+ import {OllamaAiProvider} from "./providers/OllamaAiProvider.js";
13
16
  import {BuilderTool} from "./tools/BuilderTool.js";
14
17
  import {KnowledgeService} from "./services/KnowledgeService.js";
15
18
  import {AILogService} from "./services/AILogService.js";
@@ -99,6 +102,7 @@ export type {
99
102
  export {
100
103
  OpenAiConfig,
101
104
  GoogleAiConfig,
105
+ OllamaAiConfig,
102
106
  AILogSchema,
103
107
  AILogBaseSchema,
104
108
  AILogModel,
@@ -106,10 +110,12 @@ export {
106
110
  AILogSqliteRepository,
107
111
  OpenAiProviderFactory,
108
112
  GoogleAiProviderFactory,
113
+ OllamaAiProviderFactory,
109
114
  AiProviderFactory,
110
115
  AILogServiceFactory,
111
116
  OpenAiProvider,
112
117
  GoogleAiProvider,
118
+ OllamaAiProvider,
113
119
  BuilderTool,
114
120
  //Service
115
121
  KnowledgeService,