Skip to content

Commit 7c2c53b

Browse files
Merge pull request #47 from boldare/feat/multi-assitant
feat: multi assistant support - allowing to pass assistant ID
2 parents ce5efb2 + 1645ff4 commit 7c2c53b

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

apps/api/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function bootstrap() {
99
const globalPrefix = 'api';
1010
const config = new DocumentBuilder()
1111
.setTitle('@boldare/openai-assistant')
12-
.setVersion('0.1.0')
12+
.setVersion('1.0.0')
1313
.build();
1414
const document = SwaggerModule.createDocument(app, config);
1515

libs/openai-assistant/src/lib/assistant/assistant.module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DynamicModule, Inject, Module, OnModuleInit } from '@nestjs/common';
1+
import { DynamicModule, Inject, Module, OnModuleInit, Optional } from '@nestjs/common';
22
import { HttpModule } from '@nestjs/axios';
33
import {
44
AssistantService,
@@ -38,10 +38,14 @@ export class AssistantModule implements OnModuleInit {
3838
constructor(
3939
private readonly assistantService: AssistantService,
4040
private readonly configService: ConfigService,
41-
@Inject('config') private config: AssistantConfigParams,
41+
@Inject('config') @Optional() private config: AssistantConfigParams,
4242
) {}
4343

4444
async onModuleInit(): Promise<void> {
45+
if (!this.config) {
46+
return;
47+
}
48+
4549
this.configService.set(this.config);
4650
await this.assistantService.init();
4751
}

libs/openai-assistant/src/lib/chat/chat.gateway.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class ChatGateway implements OnGatewayConnection {
2626
@ConnectedSocket() socket: Socket,
2727
) {
2828
this.logger.log(`Socket "${ChatEvents.SendMessage}" (${socket.id}):
29+
* assistant: ${request.assistantId}
2930
* thread: ${request.threadId}
3031
* files: ${request?.file_ids}
3132
* content: ${request.content}`);
@@ -34,6 +35,7 @@ export class ChatGateway implements OnGatewayConnection {
3435

3536
this.server?.to(socket.id).emit(ChatEvents.MessageReceived, message);
3637
this.logger.log(`Socket "${ChatEvents.MessageReceived}" (${socket.id}):
38+
* assistant: ${request.assistantId}
3739
* thread: ${message.threadId}
3840
* content: ${message.content}`);
3941
}

libs/openai-assistant/src/lib/chat/chat.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export class ChatCallDto {
3333
@ApiProperty()
3434
content!: string;
3535

36+
@ApiProperty({ required: false })
37+
assistantId?: string;
38+
3639
@ApiProperty({ required: false })
3740
file_ids?: string[];
3841

libs/openai-assistant/src/lib/chat/chat.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ export class ChatService {
2727

2828
await this.threads.messages.create(threadId, message);
2929

30-
const run = await this.threads.runs.create(threadId, {
31-
assistant_id: process.env['ASSISTANT_ID'] || '',
32-
});
30+
const assistant_id = payload?.assistantId || process.env['ASSISTANT_ID'] || '';
31+
const run = await this.threads.runs.create(threadId, { assistant_id });
3332

3433
await this.runService.resolve(run);
3534

0 commit comments

Comments
 (0)