feat: add development openrouter and fix changes
This commit is contained in:
@@ -27,6 +27,13 @@ export class OpenRouterService implements OnModuleDestroy {
|
|||||||
const { ProxyAgent, fetch: undiciFetch } = await import('undici');
|
const { ProxyAgent, fetch: undiciFetch } = await import('undici');
|
||||||
const { HTTPClient, OpenRouter } = await import('@openrouter/sdk');
|
const { HTTPClient, OpenRouter } = await import('@openrouter/sdk');
|
||||||
|
|
||||||
|
const env = this.configService.get<string>('app.environment');
|
||||||
|
const apiKey = this.configService.getOrThrow<string>('openRouter.apiKey');
|
||||||
|
|
||||||
|
if (env !== 'production') {
|
||||||
|
return new OpenRouter({ apiKey });
|
||||||
|
}
|
||||||
|
|
||||||
const proxyUrl = this.configService.getOrThrow<string>(
|
const proxyUrl = this.configService.getOrThrow<string>(
|
||||||
'openRouter.proxyUrl',
|
'openRouter.proxyUrl',
|
||||||
);
|
);
|
||||||
@@ -66,7 +73,7 @@ export class OpenRouterService implements OnModuleDestroy {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return new OpenRouter({
|
return new OpenRouter({
|
||||||
apiKey: this.configService.getOrThrow<string>('openRouter.apiKey'),
|
apiKey,
|
||||||
httpClient,
|
httpClient,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ export default Joi.object({
|
|||||||
// OpenRouter
|
// OpenRouter
|
||||||
OPENROUTER_API_KEY: Joi.string().required(),
|
OPENROUTER_API_KEY: Joi.string().required(),
|
||||||
OPENROUTER_MODEL: Joi.string().required(),
|
OPENROUTER_MODEL: Joi.string().required(),
|
||||||
OPENROUTER_PROXY_URL: Joi.string().required(),
|
OPENROUTER_PROXY_URL: Joi.string().optional(),
|
||||||
OPENROUTER_PROXY_USERNAME: Joi.string().required(),
|
OPENROUTER_PROXY_USERNAME: Joi.string().optional(),
|
||||||
OPENROUTER_PROXY_PASSWORD: Joi.string().required(),
|
OPENROUTER_PROXY_PASSWORD: Joi.string().optional(),
|
||||||
|
|
||||||
// Admin Panel (AdminJS)
|
// Admin Panel (AdminJS)
|
||||||
ADMIN_PANEL_ENABLED: Joi.string().valid('true', 'false').default('true'),
|
ADMIN_PANEL_ENABLED: Joi.string().valid('true', 'false').default('true'),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Conversation } from '@/modules/conversation/entities/conversation.entit
|
|||||||
import { ConversationService } from '@/modules/conversation/providers/conversation.service';
|
import { ConversationService } from '@/modules/conversation/providers/conversation.service';
|
||||||
import { MessageRole } from '@/modules/conversation/enums/message-role.enum';
|
import { MessageRole } from '@/modules/conversation/enums/message-role.enum';
|
||||||
import { OpenRouterService } from '@/common/modules/open-router/providers/open-router.service';
|
import { OpenRouterService } from '@/common/modules/open-router/providers/open-router.service';
|
||||||
|
import { SendChatCompletionRequestResponse } from '@openrouter/sdk/models/operations';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ChatbotService {
|
export class ChatbotService {
|
||||||
@@ -77,12 +78,19 @@ export class ChatbotService {
|
|||||||
|
|
||||||
const openRouter = await this.openRouterService.getOpenRouter();
|
const openRouter = await this.openRouterService.getOpenRouter();
|
||||||
|
|
||||||
const response = await openRouter.chat.send({
|
let response: SendChatCompletionRequestResponse;
|
||||||
chatRequest: {
|
|
||||||
model: this.configService.getOrThrow<string>('openRouter.model'),
|
try {
|
||||||
messages,
|
response = await openRouter.chat.send({
|
||||||
},
|
chatRequest: {
|
||||||
});
|
model: this.configService.getOrThrow<string>('openRouter.model'),
|
||||||
|
messages,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[ChatbotService] OpenRouter request failed:', err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
if (response instanceof ReadableStream) {
|
if (response instanceof ReadableStream) {
|
||||||
throw new Error('Expected non-streaming response');
|
throw new Error('Expected non-streaming response');
|
||||||
|
|||||||
Reference in New Issue
Block a user