smgc commited on
Commit
8d7241f
·
verified ·
1 Parent(s): 6ab875a

Update api/index.js

Browse files
Files changed (1) hide show
  1. api/index.js +11 -23
api/index.js CHANGED
@@ -23,7 +23,6 @@ class Config {
23
  this.GPT_GRPC = 'runtime-native-io-gpt-inference-grpc-service-lmuw6mcn3q-ul.a.run.app';
24
  this.GPT_PROTO = path.join(__dirname,'..', 'protos', 'GPTInferenceService.proto')
25
  this.PORT = process.env.PORT || 8787;
26
- this.USE_SSL = process.env.USE_SSL === 'true';
27
  }
28
  }
29
  class GRPCHandler {
@@ -95,14 +94,10 @@ router.get(config.API_PREFIX + '/v1/models', () =>
95
  router.post(config.API_PREFIX + '/v1/chat/completions', (req) => handleCompletion(req));
96
 
97
  async function GrpcToPieces(models, message, rules, stream, temperature, top_p) {
98
- let credentials;
99
- if (config.USE_SSL) {
100
- credentials = grpc.credentials.createSsl();
101
- } else {
102
- credentials = grpc.credentials.createInsecure();
103
- }
104
-
105
- let client, request;
106
  if (models.includes('gpt')){
107
  // 加载proto文件
108
  const packageDefinition = new GRPCHandler(config.GPT_PROTO).packageDefinition;
@@ -287,18 +282,11 @@ async function handleCompletion(request) {
287
  }
288
 
289
  (async () => {
290
- if (typeof addEventListener === 'function') return;
291
-
292
- const ittyServer = createServerAdapter(router.fetch);
293
- const httpServer = createServer(ittyServer);
294
-
295
- // 添加错误处理
296
- httpServer.on('error', (error) => {
297
- console.error('Server error:', error);
298
- });
299
-
300
- // 确保监听所有接口
301
- httpServer.listen(config.PORT, '0.0.0.0', () => {
302
- console.log(`Server is running on http://0.0.0.0:${config.PORT}`);
303
- });
304
  })();
 
23
  this.GPT_GRPC = 'runtime-native-io-gpt-inference-grpc-service-lmuw6mcn3q-ul.a.run.app';
24
  this.GPT_PROTO = path.join(__dirname,'..', 'protos', 'GPTInferenceService.proto')
25
  this.PORT = process.env.PORT || 8787;
 
26
  }
27
  }
28
  class GRPCHandler {
 
94
  router.post(config.API_PREFIX + '/v1/chat/completions', (req) => handleCompletion(req));
95
 
96
  async function GrpcToPieces(models, message, rules, stream, temperature, top_p) {
97
+ // 在非GPT类型的模型中,temperature和top_p是无效的
98
+ // 使用系统的根证书
99
+ const credentials = grpc.credentials.createSsl();
100
+ let client,request;
 
 
 
 
101
  if (models.includes('gpt')){
102
  // 加载proto文件
103
  const packageDefinition = new GRPCHandler(config.GPT_PROTO).packageDefinition;
 
282
  }
283
 
284
  (async () => {
285
+ //For Cloudflare Workers
286
+ if (typeof addEventListener === 'function') return;
287
+ // For Nodejs
288
+ const ittyServer = createServerAdapter(router.fetch);
289
+ console.log(`Listening on http://localhost:${config.PORT}`);
290
+ const httpServer = createServer(ittyServer);
291
+ httpServer.listen(config.PORT);
 
 
 
 
 
 
 
292
  })();