@dataclouder/conversation-card-nestjs 0.0.15 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/libs/conversation-cards/src/ai-models.service.d.ts +12 -0
- package/dist/libs/conversation-cards/src/ai-models.service.js +82 -0
- package/dist/libs/conversation-cards/src/ai-models.service.js.map +1 -0
- package/dist/libs/conversation-cards/src/conversation-ai.controller.d.ts +8 -6
- package/dist/libs/conversation-cards/src/conversation-ai.controller.js +53 -51
- package/dist/libs/conversation-cards/src/conversation-ai.controller.js.map +1 -1
- package/dist/libs/conversation-cards/src/conversation-ai.module.js +3 -2
- package/dist/libs/conversation-cards/src/conversation-ai.module.js.map +1 -1
- package/dist/libs/conversation-cards/src/conversation-ai.service.d.ts +1 -5
- package/dist/libs/conversation-cards/src/conversation-ai.service.js +1 -48
- package/dist/libs/conversation-cards/src/conversation-ai.service.js.map +1 -1
- package/dist/libs/conversation-cards/src/conversation-cards.module.js +3 -2
- package/dist/libs/conversation-cards/src/conversation-cards.module.js.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/readme.md +14 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Model } from 'mongoose';
|
2
|
+
import { ChatCompletionMessageParam } from 'groq-sdk/resources/chat/completions';
|
3
|
+
import { ChatMessageDict } from './clases/conversation.interface';
|
4
|
+
import { ConversationDocument } from './entities/conversation.entity';
|
5
|
+
export declare class IAModelsService {
|
6
|
+
private conversationModel;
|
7
|
+
private readonly groqClient;
|
8
|
+
constructor(conversationModel: Model<ConversationDocument>);
|
9
|
+
chat(messages: ChatCompletionMessageParam[]): Promise<ChatMessageDict>;
|
10
|
+
generateCompletion(prompt: string): Promise<string>;
|
11
|
+
getCompletion(prompt: string): Promise<string>;
|
12
|
+
}
|
@@ -0,0 +1,82 @@
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.IAModelsService = void 0;
|
16
|
+
const common_1 = require("@nestjs/common");
|
17
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
18
|
+
const mongoose_2 = require("mongoose");
|
19
|
+
const groq_sdk_1 = require("groq-sdk");
|
20
|
+
const conversation_interface_1 = require("./clases/conversation.interface");
|
21
|
+
const conversation_entity_1 = require("./entities/conversation.entity");
|
22
|
+
let IAModelsService = class IAModelsService {
|
23
|
+
constructor(conversationModel) {
|
24
|
+
this.conversationModel = conversationModel;
|
25
|
+
this.groqClient = new groq_sdk_1.default({
|
26
|
+
apiKey: process.env['GROQ_API_KEY'],
|
27
|
+
});
|
28
|
+
}
|
29
|
+
async chat(messages) {
|
30
|
+
try {
|
31
|
+
const completion = await this.groqClient.chat.completions.create({
|
32
|
+
messages,
|
33
|
+
model: 'mixtral-8x7b-32768',
|
34
|
+
temperature: 0.7,
|
35
|
+
max_tokens: 1024,
|
36
|
+
});
|
37
|
+
return {
|
38
|
+
content: completion.choices[0]?.message?.content || '',
|
39
|
+
role: conversation_interface_1.ChatRole.Assistant,
|
40
|
+
metadata: null,
|
41
|
+
};
|
42
|
+
}
|
43
|
+
catch (error) {
|
44
|
+
throw new Error(`Failed to generate completion: ${error.message}`);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
async generateCompletion(prompt) {
|
48
|
+
try {
|
49
|
+
const completion = await this.groqClient.chat.completions.create({
|
50
|
+
messages: [{ role: 'user', content: prompt }],
|
51
|
+
model: 'mixtral-8x7b-32768',
|
52
|
+
temperature: 0.7,
|
53
|
+
max_tokens: 1024,
|
54
|
+
});
|
55
|
+
return completion.choices[0]?.message?.content || '';
|
56
|
+
}
|
57
|
+
catch (error) {
|
58
|
+
throw new Error(`Failed to generate completion: ${error.message}`);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
async getCompletion(prompt) {
|
62
|
+
try {
|
63
|
+
const completion = await this.groqClient.chat.completions.create({
|
64
|
+
messages: [{ role: 'user', content: prompt }],
|
65
|
+
model: 'mixtral-8x7b-32768',
|
66
|
+
temperature: 0.7,
|
67
|
+
max_tokens: 1024,
|
68
|
+
});
|
69
|
+
return completion.choices[0]?.message?.content || '';
|
70
|
+
}
|
71
|
+
catch (error) {
|
72
|
+
throw new Error(`Failed to generate completion: ${error.message}`);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
};
|
76
|
+
exports.IAModelsService = IAModelsService;
|
77
|
+
exports.IAModelsService = IAModelsService = __decorate([
|
78
|
+
(0, common_1.Injectable)(),
|
79
|
+
__param(0, (0, mongoose_1.InjectModel)(conversation_entity_1.Conversation.name)),
|
80
|
+
__metadata("design:paramtypes", [mongoose_2.Model])
|
81
|
+
], IAModelsService);
|
82
|
+
//# sourceMappingURL=ai-models.service.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ai-models.service.js","sourceRoot":"","sources":["../../../../src/ai-models.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA+C;AAC/C,uCAAiC;AACjC,uCAA4B;AAG5B,4EAA4E;AAC5E,wEAAoF;AAG7E,IAAM,eAAe,GAArB,MAAM,eAAe;IAG1B,YAAo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AE,CAAC,CAAC;SACpE;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAAc;QAChC,IAAI;YACF,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;gBAC/D,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;gBAC7C,KAAK,EAAE,oBAAoB;gBAC3B,WAAW,EAAE,GAAG;gBAChB,UAAU,EAAE,IAAI;aACjB,CAAC,CAAC;YAEH,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;SACtD;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SACpE;IACH,CAAC;CACF,CAAA;AAxDY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,sBAAW,EAAC,kCAAY,CAAC,IAAI,CAAC,CAAA;qCAA4B,gBAAK;GAHjE,eAAe,CAwD3B"}
|
@@ -1,20 +1,22 @@
|
|
1
|
+
import { FastifyReply } from 'fastify';
|
1
2
|
import { ConversationAiService } from './conversation-ai.service';
|
2
3
|
import { ConversationDTO } from './dto/create-conversation.dto';
|
3
4
|
import { ChatMessageDict, IConversationCard } from './clases/conversation.interface';
|
4
5
|
import { Conversation, ConversationDocument } from './entities/conversation.entity';
|
5
6
|
import { TTSDto } from './tts/tts.classes';
|
6
7
|
import { TTSService } from './tts/tts-service';
|
7
|
-
import {
|
8
|
+
import { IAModelsService } from './ai-models.service';
|
8
9
|
export declare class ConversationAiController {
|
9
10
|
private readonly conversationAiService;
|
11
|
+
private readonly aiModel;
|
10
12
|
private readonly ttsService;
|
11
|
-
constructor(conversationAiService: ConversationAiService, ttsService: TTSService);
|
12
|
-
test(): Promise<string>;
|
13
|
-
saveConversation(conversation: IConversationCard): Promise<ConversationDocument>;
|
14
|
-
continueConversation(conversation: ConversationDTO): Promise<ChatMessageDict>;
|
15
|
-
getTTS(tts: TTSDto, res: FastifyReply): Promise<any>;
|
13
|
+
constructor(conversationAiService: ConversationAiService, aiModel: IAModelsService, ttsService: TTSService);
|
16
14
|
getConversations(): Promise<ConversationDocument[]>;
|
15
|
+
saveConversation(conversation: IConversationCard): Promise<ConversationDocument>;
|
17
16
|
getConversationById(id: string): Promise<ConversationDocument>;
|
18
17
|
updateConversation(id: string, updateData: Partial<Conversation>): Promise<ConversationDocument>;
|
19
18
|
deleteConversationById(id: string): Promise<ConversationDocument>;
|
19
|
+
continueConversation(conversation: ConversationDTO): Promise<ChatMessageDict>;
|
20
|
+
getTTS(tts: TTSDto, res: FastifyReply): Promise<any>;
|
21
|
+
test(): Promise<string>;
|
20
22
|
}
|
@@ -14,29 +14,40 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
exports.ConversationAiController = void 0;
|
16
16
|
const common_1 = require("@nestjs/common");
|
17
|
+
const swagger_1 = require("@nestjs/swagger");
|
17
18
|
const conversation_ai_service_1 = require("./conversation-ai.service");
|
18
19
|
const create_conversation_dto_1 = require("./dto/create-conversation.dto");
|
19
|
-
const swagger_1 = require("@nestjs/swagger");
|
20
20
|
const conversation_interface_1 = require("./clases/conversation.interface");
|
21
21
|
const conversation_entity_1 = require("./entities/conversation.entity");
|
22
22
|
const tts_classes_1 = require("./tts/tts.classes");
|
23
23
|
const tts_service_1 = require("./tts/tts-service");
|
24
|
+
const ai_models_service_1 = require("./ai-models.service");
|
24
25
|
let ConversationAiController = class ConversationAiController {
|
25
|
-
constructor(conversationAiService, ttsService) {
|
26
|
+
constructor(conversationAiService, aiModel, ttsService) {
|
26
27
|
this.conversationAiService = conversationAiService;
|
28
|
+
this.aiModel = aiModel;
|
27
29
|
this.ttsService = ttsService;
|
28
30
|
}
|
29
|
-
async
|
30
|
-
|
31
|
+
async getConversations() {
|
32
|
+
console.log('getConversations');
|
33
|
+
return this.conversationAiService.getConversations();
|
31
34
|
}
|
32
35
|
async saveConversation(conversation) {
|
33
|
-
console.log('conversation', conversation);
|
34
36
|
return this.conversationAiService.saveConversation(conversation);
|
35
37
|
}
|
38
|
+
async getConversationById(id) {
|
39
|
+
return this.conversationAiService.getConversationById(id);
|
40
|
+
}
|
41
|
+
async updateConversation(id, updateData) {
|
42
|
+
return this.conversationAiService.updateConversation(id, updateData);
|
43
|
+
}
|
44
|
+
async deleteConversationById(id) {
|
45
|
+
return this.conversationAiService.deleteConversationById(id);
|
46
|
+
}
|
36
47
|
async continueConversation(conversation) {
|
37
48
|
const messages = conversation.messages;
|
38
49
|
console.log('messages', messages);
|
39
|
-
const response = await this.
|
50
|
+
const response = await this.aiModel.chat(messages);
|
40
51
|
console.log('response', response);
|
41
52
|
return response;
|
42
53
|
}
|
@@ -55,65 +66,28 @@ let ConversationAiController = class ConversationAiController {
|
|
55
66
|
res.header('transcription', 'This is a transcription');
|
56
67
|
return audioContent;
|
57
68
|
}
|
58
|
-
async
|
59
|
-
|
60
|
-
return this.conversationAiService.getConversations();
|
61
|
-
}
|
62
|
-
async getConversationById(id) {
|
63
|
-
return this.conversationAiService.getConversationById(id);
|
64
|
-
}
|
65
|
-
async updateConversation(id, updateData) {
|
66
|
-
return this.conversationAiService.updateConversation(id, updateData);
|
67
|
-
}
|
68
|
-
async deleteConversationById(id) {
|
69
|
-
return this.conversationAiService.deleteConversationById(id);
|
69
|
+
async test() {
|
70
|
+
return 'Hello World' + conversation_interface_1.TextEngines.MarkdownMultiMessages;
|
70
71
|
}
|
71
72
|
};
|
72
73
|
exports.ConversationAiController = ConversationAiController;
|
73
74
|
__decorate([
|
74
|
-
(0, common_1.Get)('/
|
75
|
-
(0, swagger_1.ApiOperation)({ summary: '
|
76
|
-
(0, swagger_1.ApiResponse)({ status: 200, description: 'Return
|
75
|
+
(0, common_1.Get)('/conversation'),
|
76
|
+
(0, swagger_1.ApiOperation)({ summary: 'Get all conversations' }),
|
77
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: 'Return all conversations.' }),
|
77
78
|
__metadata("design:type", Function),
|
78
79
|
__metadata("design:paramtypes", []),
|
79
80
|
__metadata("design:returntype", Promise)
|
80
|
-
], ConversationAiController.prototype, "
|
81
|
+
], ConversationAiController.prototype, "getConversations", null);
|
81
82
|
__decorate([
|
82
83
|
(0, common_1.Post)('/conversation'),
|
83
|
-
(0, swagger_1.ApiOperation)({ summary: 'Save
|
84
|
+
(0, swagger_1.ApiOperation)({ summary: 'Save new conversations' }),
|
84
85
|
(0, swagger_1.ApiResponse)({ status: 201, description: 'The conversation has been successfully created.', type: conversation_entity_1.Conversation }),
|
85
86
|
__param(0, (0, common_1.Body)()),
|
86
87
|
__metadata("design:type", Function),
|
87
88
|
__metadata("design:paramtypes", [Object]),
|
88
89
|
__metadata("design:returntype", Promise)
|
89
90
|
], ConversationAiController.prototype, "saveConversation", null);
|
90
|
-
__decorate([
|
91
|
-
(0, common_1.Post)('/chat'),
|
92
|
-
(0, swagger_1.ApiOperation)({ summary: 'Continue the conversation' }),
|
93
|
-
(0, swagger_1.ApiResponse)({ status: 200, description: 'Return the conversation.' }),
|
94
|
-
__param(0, (0, common_1.Body)()),
|
95
|
-
__metadata("design:type", Function),
|
96
|
-
__metadata("design:paramtypes", [create_conversation_dto_1.ConversationDTO]),
|
97
|
-
__metadata("design:returntype", Promise)
|
98
|
-
], ConversationAiController.prototype, "continueConversation", null);
|
99
|
-
__decorate([
|
100
|
-
(0, common_1.Post)('/tts'),
|
101
|
-
(0, swagger_1.ApiOperation)({ summary: 'Generate TTS audio' }),
|
102
|
-
(0, swagger_1.ApiResponse)({ status: 200, description: 'Return the TTS audio.' }),
|
103
|
-
__param(0, (0, common_1.Body)()),
|
104
|
-
__param(1, (0, common_1.Res)({ passthrough: true })),
|
105
|
-
__metadata("design:type", Function),
|
106
|
-
__metadata("design:paramtypes", [tts_classes_1.TTSDto, Object]),
|
107
|
-
__metadata("design:returntype", Promise)
|
108
|
-
], ConversationAiController.prototype, "getTTS", null);
|
109
|
-
__decorate([
|
110
|
-
(0, common_1.Get)('/conversation'),
|
111
|
-
(0, swagger_1.ApiOperation)({ summary: 'Get all conversations' }),
|
112
|
-
(0, swagger_1.ApiResponse)({ status: 200, description: 'Return all conversations.' }),
|
113
|
-
__metadata("design:type", Function),
|
114
|
-
__metadata("design:paramtypes", []),
|
115
|
-
__metadata("design:returntype", Promise)
|
116
|
-
], ConversationAiController.prototype, "getConversations", null);
|
117
91
|
__decorate([
|
118
92
|
(0, common_1.Get)('/conversation/:id'),
|
119
93
|
(0, swagger_1.ApiOperation)({ summary: 'Get a conversation by ID' }),
|
@@ -142,10 +116,38 @@ __decorate([
|
|
142
116
|
__metadata("design:paramtypes", [String]),
|
143
117
|
__metadata("design:returntype", Promise)
|
144
118
|
], ConversationAiController.prototype, "deleteConversationById", null);
|
119
|
+
__decorate([
|
120
|
+
(0, common_1.Post)('/chat'),
|
121
|
+
(0, swagger_1.ApiOperation)({ summary: 'Continue the conversation' }),
|
122
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: 'Return the conversation.' }),
|
123
|
+
__param(0, (0, common_1.Body)()),
|
124
|
+
__metadata("design:type", Function),
|
125
|
+
__metadata("design:paramtypes", [create_conversation_dto_1.ConversationDTO]),
|
126
|
+
__metadata("design:returntype", Promise)
|
127
|
+
], ConversationAiController.prototype, "continueConversation", null);
|
128
|
+
__decorate([
|
129
|
+
(0, common_1.Post)('/tts'),
|
130
|
+
(0, swagger_1.ApiOperation)({ summary: 'Generate TTS audio' }),
|
131
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: 'Return the TTS audio.' }),
|
132
|
+
__param(0, (0, common_1.Body)()),
|
133
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
134
|
+
__metadata("design:type", Function),
|
135
|
+
__metadata("design:paramtypes", [tts_classes_1.TTSDto, Object]),
|
136
|
+
__metadata("design:returntype", Promise)
|
137
|
+
], ConversationAiController.prototype, "getTTS", null);
|
138
|
+
__decorate([
|
139
|
+
(0, common_1.Get)('/test'),
|
140
|
+
(0, swagger_1.ApiOperation)({ summary: 'Test the conversation AI' }),
|
141
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: 'Return the test result.' }),
|
142
|
+
__metadata("design:type", Function),
|
143
|
+
__metadata("design:paramtypes", []),
|
144
|
+
__metadata("design:returntype", Promise)
|
145
|
+
], ConversationAiController.prototype, "test", null);
|
145
146
|
exports.ConversationAiController = ConversationAiController = __decorate([
|
146
147
|
(0, swagger_1.ApiTags)('conversation-ai-cards'),
|
147
|
-
(0, common_1.Controller)('api/conversation-ai'),
|
148
|
+
(0, common_1.Controller)('api/conversation-ai-cards'),
|
148
149
|
__metadata("design:paramtypes", [conversation_ai_service_1.ConversationAiService,
|
150
|
+
ai_models_service_1.IAModelsService,
|
149
151
|
tts_service_1.TTSService])
|
150
152
|
], ConversationAiController);
|
151
153
|
//# sourceMappingURL=conversation-ai.controller.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"conversation-ai.controller.js","sourceRoot":"","sources":["../../../../src/conversation-ai.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAsF;AACtF,uEAAkE;AAClE,2EAAgE;AAChE,
|
1
|
+
{"version":3,"file":"conversation-ai.controller.js","sourceRoot":"","sources":["../../../../src/conversation-ai.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAsF;AACtF,6CAAqE;AAGrE,uEAAkE;AAClE,2EAAgE;AAChE,4EAAkG;AAClG,wEAAoF;AACpF,mDAA2C;AAC3C,mDAA+C;AAC/C,2DAAsD;AAI/C,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACnC,YACmB,qBAA4C,EAC5C,OAAwB,EAExB,UAAsB;QAHtB,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,YAAO,GAAP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IAAe,WAAA,IAAA,YAAG,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;;qCAAnC,oBAAM;;sDAgB/B;AAKK;IAHL,IAAA,YAAG,EAAC,OAAO,CAAC;IACZ,IAAA,sBAAY,EAAC,EAAE,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACrD,IAAA,qBAAW,EAAC,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;;;;oDAIpE;mCAlFU,wBAAwB;IAFpC,IAAA,iBAAO,EAAC,uBAAuB,CAAC;IAChC,IAAA,mBAAU,EAAC,2BAA2B,CAAC;qCAGI,+CAAqB;QACnC,mCAAe;QAEZ,wBAAU;GAL9B,wBAAwB,CAmFpC"}
|
@@ -13,6 +13,7 @@ const conversation_ai_controller_1 = require("./conversation-ai.controller");
|
|
13
13
|
const conversation_ai_service_1 = require("./conversation-ai.service");
|
14
14
|
const conversation_entity_1 = require("./entities/conversation.entity");
|
15
15
|
const tts_service_1 = require("./tts/tts-service");
|
16
|
+
const ai_models_service_1 = require("./ai-models.service");
|
16
17
|
let ConversationAiModule = class ConversationAiModule {
|
17
18
|
};
|
18
19
|
exports.ConversationAiModule = ConversationAiModule;
|
@@ -20,8 +21,8 @@ exports.ConversationAiModule = ConversationAiModule = __decorate([
|
|
20
21
|
(0, common_1.Module)({
|
21
22
|
imports: [mongoose_1.MongooseModule.forFeature([{ name: conversation_entity_1.Conversation.name, schema: conversation_entity_1.ConversationSchema }])],
|
22
23
|
controllers: [conversation_ai_controller_1.ConversationAiController],
|
23
|
-
providers: [conversation_ai_service_1.ConversationAiService, tts_service_1.TTSService],
|
24
|
-
exports: [conversation_ai_service_1.ConversationAiService],
|
24
|
+
providers: [conversation_ai_service_1.ConversationAiService, tts_service_1.TTSService, ai_models_service_1.IAModelsService],
|
25
|
+
exports: [conversation_ai_service_1.ConversationAiService, tts_service_1.TTSService, ai_models_service_1.IAModelsService],
|
25
26
|
})
|
26
27
|
], ConversationAiModule);
|
27
28
|
//# sourceMappingURL=conversation-ai.module.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"conversation-ai.module.js","sourceRoot":"","sources":["../../../../src/conversation-ai.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+CAAkD;AAClD,6EAAwE;AACxE,uEAAkE;AAClE,wEAAkF;AAClF,mDAA+C;
|
1
|
+
{"version":3,"file":"conversation-ai.module.js","sourceRoot":"","sources":["../../../../src/conversation-ai.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+CAAkD;AAClD,6EAAwE;AACxE,uEAAkE;AAClE,wEAAkF;AAClF,mDAA+C;AAC/C,2DAAsD;AAQ/C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oDAAoB;+BAApB,oBAAoB;IANhC,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,yBAAc,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,kCAAY,CAAC,IAAI,EAAE,MAAM,EAAE,wCAAkB,EAAE,CAAC,CAAC,CAAC;QAC/F,WAAW,EAAE,CAAC,qDAAwB,CAAC;QACvC,SAAS,EAAE,CAAC,+CAAqB,EAAE,wBAAU,EAAE,mCAAe,CAAC;QAC/D,OAAO,EAAE,CAAC,+CAAqB,EAAE,wBAAU,EAAE,mCAAe,CAAC;KAC9D,CAAC;GACW,oBAAoB,CAAG"}
|
@@ -1,14 +1,10 @@
|
|
1
1
|
import { Model } from 'mongoose';
|
2
|
-
import {
|
3
|
-
import { ChatMessageDict, IConversationCard } from './clases/conversation.interface';
|
2
|
+
import { IConversationCard } from './clases/conversation.interface';
|
4
3
|
import { Conversation, ConversationDocument } from './entities/conversation.entity';
|
5
4
|
export declare class ConversationAiService {
|
6
5
|
private conversationModel;
|
7
6
|
private readonly groqClient;
|
8
7
|
constructor(conversationModel: Model<ConversationDocument>);
|
9
|
-
generateCompletion(prompt: string): Promise<string>;
|
10
|
-
chat(messages: ChatCompletionMessageParam[]): Promise<ChatMessageDict>;
|
11
|
-
getCompletion(prompt: string): Promise<string>;
|
12
8
|
saveConversation(conversation: IConversationCard): Promise<ConversationDocument>;
|
13
9
|
updateConversation(id: string, updateData: Partial<Conversation>): Promise<ConversationDocument>;
|
14
10
|
getConversations(): Promise<ConversationDocument[]>;
|
@@ -17,9 +17,8 @@ const common_1 = require("@nestjs/common");
|
|
17
17
|
const mongoose_1 = require("@nestjs/mongoose");
|
18
18
|
const mongoose_2 = require("mongoose");
|
19
19
|
const groq_sdk_1 = require("groq-sdk");
|
20
|
-
const conversation_interface_1 = require("./clases/conversation.interface");
|
21
|
-
const conversation_entity_1 = require("./entities/conversation.entity");
|
22
20
|
const mongodb_1 = require("mongodb");
|
21
|
+
const conversation_entity_1 = require("./entities/conversation.entity");
|
23
22
|
let ConversationAiService = class ConversationAiService {
|
24
23
|
constructor(conversationModel) {
|
25
24
|
this.conversationModel = conversationModel;
|
@@ -27,52 +26,6 @@ let ConversationAiService = class ConversationAiService {
|
|
27
26
|
apiKey: process.env['GROQ_API_KEY'],
|
28
27
|
});
|
29
28
|
}
|
30
|
-
async generateCompletion(prompt) {
|
31
|
-
try {
|
32
|
-
const completion = await this.groqClient.chat.completions.create({
|
33
|
-
messages: [{ role: 'user', content: prompt }],
|
34
|
-
model: 'mixtral-8x7b-32768',
|
35
|
-
temperature: 0.7,
|
36
|
-
max_tokens: 1024,
|
37
|
-
});
|
38
|
-
return completion.choices[0]?.message?.content || '';
|
39
|
-
}
|
40
|
-
catch (error) {
|
41
|
-
throw new Error(`Failed to generate completion: ${error.message}`);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
async chat(messages) {
|
45
|
-
try {
|
46
|
-
const completion = await this.groqClient.chat.completions.create({
|
47
|
-
messages,
|
48
|
-
model: 'mixtral-8x7b-32768',
|
49
|
-
temperature: 0.7,
|
50
|
-
max_tokens: 1024,
|
51
|
-
});
|
52
|
-
return {
|
53
|
-
content: completion.choices[0]?.message?.content || '',
|
54
|
-
role: conversation_interface_1.ChatRole.Assistant,
|
55
|
-
metadata: null,
|
56
|
-
};
|
57
|
-
}
|
58
|
-
catch (error) {
|
59
|
-
throw new Error(`Failed to generate completion: ${error.message}`);
|
60
|
-
}
|
61
|
-
}
|
62
|
-
async getCompletion(prompt) {
|
63
|
-
try {
|
64
|
-
const completion = await this.groqClient.chat.completions.create({
|
65
|
-
messages: [{ role: 'user', content: prompt }],
|
66
|
-
model: 'mixtral-8x7b-32768',
|
67
|
-
temperature: 0.7,
|
68
|
-
max_tokens: 1024,
|
69
|
-
});
|
70
|
-
return completion.choices[0]?.message?.content || '';
|
71
|
-
}
|
72
|
-
catch (error) {
|
73
|
-
throw new Error(`Failed to generate completion: ${error.message}`);
|
74
|
-
}
|
75
|
-
}
|
76
29
|
async saveConversation(conversation) {
|
77
30
|
if (!conversation['_id']) {
|
78
31
|
delete conversation['_id'];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"conversation-ai.service.js","sourceRoot":"","sources":["../../../../src/conversation-ai.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA+C;AAC/C,uCAAiC;AACjC,uCAA4B;AAE5B,
|
1
|
+
{"version":3,"file":"conversation-ai.service.js","sourceRoot":"","sources":["../../../../src/conversation-ai.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA+C;AAC/C,uCAAiC;AACjC,uCAA4B;AAE5B,qCAAmC;AAGnC,wEAAoF;AAG7E,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAGhC,YAAoD,iBAA8C;QAA9C,sBAAiB,GAAjB,iBAAiB,CAA6B;QAChG,IAAI,CAAC,UAAU,GAAG,IAAI,kBAAI,CAAC;YACzB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;SACpC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,gBAA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require("./conversation-ai.controller");
|
|
13
13
|
const conversation_ai_service_1 = require("./conversation-ai.service");
|
14
14
|
const conversation_entity_1 = require("./entities/conversation.entity");
|
15
15
|
const tts_service_1 = require("./tts/tts-service");
|
16
|
+
const ai_models_service_1 = require("./ai-models.service");
|
16
17
|
let ConversationCardsModule = class ConversationCardsModule {
|
17
18
|
};
|
18
19
|
exports.ConversationCardsModule = ConversationCardsModule;
|
@@ -20,8 +21,8 @@ exports.ConversationCardsModule = ConversationCardsModule = __decorate([
|
|
20
21
|
(0, common_1.Module)({
|
21
22
|
imports: [mongoose_1.MongooseModule.forFeature([{ name: conversation_entity_1.Conversation.name, schema: conversation_entity_1.ConversationSchema }])],
|
22
23
|
controllers: [conversation_ai_controller_1.ConversationAiController],
|
23
|
-
providers: [conversation_ai_service_1.ConversationAiService, tts_service_1.TTSService],
|
24
|
-
exports: [conversation_ai_service_1.ConversationAiService],
|
24
|
+
providers: [conversation_ai_service_1.ConversationAiService, tts_service_1.TTSService, ai_models_service_1.IAModelsService],
|
25
|
+
exports: [conversation_ai_service_1.ConversationAiService, ai_models_service_1.IAModelsService, tts_service_1.TTSService],
|
25
26
|
})
|
26
27
|
], ConversationCardsModule);
|
27
28
|
//# sourceMappingURL=conversation-cards.module.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"conversation-cards.module.js","sourceRoot":"","sources":["../../../../src/conversation-cards.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+CAAkD;AAClD,6EAAwE;AACxE,uEAAkE;AAClE,wEAAkF;AAClF,mDAA+C;
|
1
|
+
{"version":3,"file":"conversation-cards.module.js","sourceRoot":"","sources":["../../../../src/conversation-cards.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+CAAkD;AAClD,6EAAwE;AACxE,uEAAkE;AAClE,wEAAkF;AAClF,mDAA+C;AAC/C,2DAAsD;AAQ/C,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;CAAG,CAAA;AAA1B,0DAAuB;kCAAvB,uBAAuB;IANnC,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,yBAAc,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,kCAAY,CAAC,IAAI,EAAE,MAAM,EAAE,wCAAkB,EAAE,CAAC,CAAC,CAAC;QAC/F,WAAW,EAAE,CAAC,qDAAwB,CAAC;QACvC,SAAS,EAAE,CAAC,+CAAqB,EAAE,wBAAU,EAAE,mCAAe,CAAC;QAC/D,OAAO,EAAE,CAAC,+CAAqB,EAAE,mCAAe,EAAE,wBAAU,CAAC;KAC9D,CAAC;GACW,uBAAuB,CAAG"}
|