feat: add open router proxy
This commit is contained in:
@@ -5,6 +5,7 @@ import { User } from '@/modules/users/entities/user.entity';
|
||||
import { Conversation } from '@/modules/conversation/entities/conversation.entity';
|
||||
import { ConversationService } from '@/modules/conversation/providers/conversation.service';
|
||||
import { MessageRole } from '@/modules/conversation/enums/message-role.enum';
|
||||
import { OpenRouterService } from '@/common/modules/open-router/providers/open-router.service';
|
||||
|
||||
@Injectable()
|
||||
export class ChatbotService {
|
||||
@@ -18,16 +19,13 @@ export class ChatbotService {
|
||||
* Inject Conversation Service
|
||||
*/
|
||||
private readonly conversationService: ConversationService,
|
||||
|
||||
/**
|
||||
* Inject OpenRouter Service
|
||||
*/
|
||||
private readonly openRouterService: OpenRouterService,
|
||||
) {}
|
||||
|
||||
private async getOpenRouter() {
|
||||
const { OpenRouter } = await import('@openrouter/sdk');
|
||||
|
||||
return new OpenRouter({
|
||||
apiKey: this.configService.getOrThrow<string>('openRouter.apiKey'),
|
||||
});
|
||||
}
|
||||
|
||||
private async getConversationMessages(
|
||||
user: User,
|
||||
message: string,
|
||||
@@ -77,7 +75,7 @@ export class ChatbotService {
|
||||
conversationId,
|
||||
);
|
||||
|
||||
const openRouter = await this.getOpenRouter();
|
||||
const openRouter = await this.openRouterService.getOpenRouter();
|
||||
|
||||
const response = await openRouter.chat.send({
|
||||
chatRequest: {
|
||||
@@ -119,7 +117,7 @@ export class ChatbotService {
|
||||
conversationId,
|
||||
);
|
||||
|
||||
const openRouter = await this.getOpenRouter();
|
||||
const openRouter = await this.openRouterService.getOpenRouter();
|
||||
|
||||
const response = await openRouter.chat.send({
|
||||
chatRequest: {
|
||||
|
||||
Reference in New Issue
Block a user