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 { 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>(
|
||||
'openRouter.proxyUrl',
|
||||
);
|
||||
@@ -66,7 +73,7 @@ export class OpenRouterService implements OnModuleDestroy {
|
||||
});
|
||||
|
||||
return new OpenRouter({
|
||||
apiKey: this.configService.getOrThrow<string>('openRouter.apiKey'),
|
||||
apiKey,
|
||||
httpClient,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -39,9 +39,9 @@ export default Joi.object({
|
||||
// OpenRouter
|
||||
OPENROUTER_API_KEY: Joi.string().required(),
|
||||
OPENROUTER_MODEL: Joi.string().required(),
|
||||
OPENROUTER_PROXY_URL: Joi.string().required(),
|
||||
OPENROUTER_PROXY_USERNAME: Joi.string().required(),
|
||||
OPENROUTER_PROXY_PASSWORD: Joi.string().required(),
|
||||
OPENROUTER_PROXY_URL: Joi.string().optional(),
|
||||
OPENROUTER_PROXY_USERNAME: Joi.string().optional(),
|
||||
OPENROUTER_PROXY_PASSWORD: Joi.string().optional(),
|
||||
|
||||
// Admin Panel (AdminJS)
|
||||
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 { MessageRole } from '@/modules/conversation/enums/message-role.enum';
|
||||
import { OpenRouterService } from '@/common/modules/open-router/providers/open-router.service';
|
||||
import { SendChatCompletionRequestResponse } from '@openrouter/sdk/models/operations';
|
||||
|
||||
@Injectable()
|
||||
export class ChatbotService {
|
||||
@@ -77,12 +78,19 @@ export class ChatbotService {
|
||||
|
||||
const openRouter = await this.openRouterService.getOpenRouter();
|
||||
|
||||
const response = await openRouter.chat.send({
|
||||
let response: SendChatCompletionRequestResponse;
|
||||
|
||||
try {
|
||||
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) {
|
||||
throw new Error('Expected non-streaming response');
|
||||
|
||||
Reference in New Issue
Block a user