yxmiler commited on
Commit
06c1242
·
verified ·
1 Parent(s): 8fd3a7a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +8 -7
index.js CHANGED
@@ -8,12 +8,12 @@ import dotenv from 'dotenv';
8
  // 配置加载
9
  dotenv.config();
10
 
11
-
12
  // 配置常量
13
  const CONFIG = {
14
  API: {
15
  BASE_URL: "wss://api.inkeep.com/graphql",
16
  API_KEY: process.env.API_KEY || "sk-123456",
 
17
  },
18
  MODELS: {
19
  'claude-3-5-sonnet-20241022': 'claude-3-5-sonnet-20241022',
@@ -71,7 +71,7 @@ class AiApiClient {
71
 
72
  if (currentContent === null) return acc;
73
 
74
- const currentMessageRole = current.role === "system" || current.role === "user" ? "HUMAN" : "ASSISTANT";
75
 
76
  // 系统消息处理逻辑
77
  if (current.role === "system") {
@@ -186,7 +186,7 @@ class WebSocketUtils {
186
  static async createWebSocketClient(requestPayload) {
187
  // 检查当前连接数是否达到上限
188
  if (this.activeConnections.size >= this.MAX_CONNECTIONS) {
189
- throw new Error(`当前连接数已达到上限 (${this.MAX_CONNECTIONS}),请稍后重试喵!`);
190
  }
191
 
192
  let timeoutId;
@@ -310,7 +310,7 @@ class WebSocketUtils {
310
  organizationId: 'org_JfjtEvzbwOikUEUn',
311
  integrationId: 'clwtqz9sq001izszu8ms5g4om',
312
  chatMode: 'AUTO',
313
- context: requestPayload.systemMessage,
314
  messageAttributes: {},
315
  includeAIAnnotations: false,
316
  environment: 'production'
@@ -333,6 +333,7 @@ class WebSocketUtils {
333
  }
334
  };
335
 
 
336
  if (ws.readyState === WebSocket.OPEN) {
337
  ws.send(JSON.stringify(subscribeMessage));
338
  }
@@ -369,7 +370,7 @@ app.use(cors({
369
 
370
 
371
  // 获取模型列表路由
372
- app.get('/hf/v1/models', (req, res) => {
373
  res.json({
374
  object: "list",
375
  data: [{
@@ -382,7 +383,7 @@ app.get('/hf/v1/models', (req, res) => {
382
  });
383
 
384
  // 聊天完成路由
385
- app.post('/hf/v1/chat/completions', async (req, res) => {
386
  try {
387
  const { messages, model, stream } = req.body;
388
  const authToken = req.headers.authorization?.replace('Bearer ', '');
@@ -420,4 +421,4 @@ app.use((req, res) => {
420
  // 启动服务器
421
  app.listen(CONFIG.SERVER.PORT, () => {
422
  console.log(`服务器运行在 http://localhost:${CONFIG.SERVER.PORT}`);
423
- });
 
8
  // 配置加载
9
  dotenv.config();
10
 
 
11
  // 配置常量
12
  const CONFIG = {
13
  API: {
14
  BASE_URL: "wss://api.inkeep.com/graphql",
15
  API_KEY: process.env.API_KEY || "sk-123456",
16
+ SYSTEM_MESSAGE: process.env.SYSTEM_MESSAGE || null
17
  },
18
  MODELS: {
19
  'claude-3-5-sonnet-20241022': 'claude-3-5-sonnet-20241022',
 
71
 
72
  if (currentContent === null) return acc;
73
 
74
+ const currentMessageRole = current.role === "system" || current.role === "user" ? "Human" : "Assistant";
75
 
76
  // 系统消息处理逻辑
77
  if (current.role === "system") {
 
186
  static async createWebSocketClient(requestPayload) {
187
  // 检查当前连接数是否达到上限
188
  if (this.activeConnections.size >= this.MAX_CONNECTIONS) {
189
+ throw new Error(`当前连接数已达到上限 (${this.MAX_CONNECTIONS}),请稍后重试!`);
190
  }
191
 
192
  let timeoutId;
 
310
  organizationId: 'org_JfjtEvzbwOikUEUn',
311
  integrationId: 'clwtqz9sq001izszu8ms5g4om',
312
  chatMode: 'AUTO',
313
+ context: requestPayload.systemMessage || CONFIG.API.SYSTEM_MESSAGE,
314
  messageAttributes: {},
315
  includeAIAnnotations: false,
316
  environment: 'production'
 
333
  }
334
  };
335
 
336
+ console.log(JSON.stringify(subscribeMessage,null,2));
337
  if (ws.readyState === WebSocket.OPEN) {
338
  ws.send(JSON.stringify(subscribeMessage));
339
  }
 
370
 
371
 
372
  // 获取模型列表路由
373
+ app.get('/v1/models', (req, res) => {
374
  res.json({
375
  object: "list",
376
  data: [{
 
383
  });
384
 
385
  // 聊天完成路由
386
+ app.post('/v1/chat/completions', async (req, res) => {
387
  try {
388
  const { messages, model, stream } = req.body;
389
  const authToken = req.headers.authorization?.replace('Bearer ', '');
 
421
  // 启动服务器
422
  app.listen(CONFIG.SERVER.PORT, () => {
423
  console.log(`服务器运行在 http://localhost:${CONFIG.SERVER.PORT}`);
424
+ });