fix: fix some change
This commit is contained in:
@@ -3,8 +3,6 @@ import { ConfigService } from '@nestjs/config';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ChatbotService {
|
export class ChatbotService {
|
||||||
private openRouter: any;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
/**
|
/**
|
||||||
* Inject Config Service
|
* Inject Config Service
|
||||||
@@ -13,23 +11,16 @@ export class ChatbotService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
private async getOpenRouter() {
|
private async getOpenRouter() {
|
||||||
if (!this.openRouter) {
|
|
||||||
const { OpenRouter } = await import('@openrouter/sdk');
|
const { OpenRouter } = await import('@openrouter/sdk');
|
||||||
|
|
||||||
this.openRouter = new OpenRouter({
|
return new OpenRouter({
|
||||||
apiKey: this.configService.get<string>('openRouter.apiKey'),
|
apiKey: this.configService.get<string>('openRouter.apiKey'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
||||||
return this.openRouter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async chat(message: string) {
|
public async chat(message: string) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
||||||
const openRouter = await this.getOpenRouter();
|
const openRouter = await this.getOpenRouter();
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
||||||
const response = await openRouter.chat.send({
|
const response = await openRouter.chat.send({
|
||||||
chatRequest: {
|
chatRequest: {
|
||||||
model: this.configService.get<string>('openRouter.model'),
|
model: this.configService.get<string>('openRouter.model'),
|
||||||
@@ -63,7 +54,6 @@ export class ChatbotService {
|
|||||||
throw new Error('Expected non-streaming response');
|
throw new Error('Expected non-streaming response');
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
||||||
const content = response.choices[0]?.message?.content;
|
const content = response.choices[0]?.message?.content;
|
||||||
|
|
||||||
if (typeof content !== 'string') {
|
if (typeof content !== 'string') {
|
||||||
|
|||||||
Reference in New Issue
Block a user