dan92 commited on
Commit
0eba76f
·
verified ·
1 Parent(s): 4ba6a3e

Upload 2 files

Browse files
Files changed (1) hide show
  1. src/index.js +17 -2
src/index.js CHANGED
@@ -147,6 +147,15 @@ const handleChatCompletions = async (ctx) => {
147
  const { messages, stream = false, model = 'claude-3-5-sonnet' } = ctx.request.body
148
  const session_id = ctx.get('Authorization')?.replace('Bearer ', '')
149
 
 
 
 
 
 
 
 
 
 
150
  if (!session_id) {
151
  ctx.status = 401
152
  ctx.body = { error: '未提供有效的 session_id' }
@@ -160,6 +169,12 @@ const handleChatCompletions = async (ctx) => {
160
  throw new Error('Response body is null')
161
  }
162
 
 
 
 
 
 
 
163
  if (stream == "true" || stream == true) {
164
  ctx.set({
165
  'Content-Type': 'text/event-stream',
@@ -200,7 +215,7 @@ const handleChatCompletions = async (ctx) => {
200
  }
201
  ],
202
  "created": Math.floor(Date.now() / 1000),
203
- "model": models[`${model}`],
204
  "object": "chat.completion.chunk"
205
  })}\n\n`)
206
  }
@@ -235,7 +250,7 @@ const handleChatCompletions = async (ctx) => {
235
  }
236
  ],
237
  "created": Math.floor(Date.now() / 1000),
238
- "model": models[`${model}`],
239
  "object": "chat.completion.chunk"
240
  })}\n\n`)
241
  })
 
147
  const { messages, stream = false, model = 'claude-3-5-sonnet' } = ctx.request.body
148
  const session_id = ctx.get('Authorization')?.replace('Bearer ', '')
149
 
150
+ console.log('收到聊天请求:', {
151
+ path: ctx.path,
152
+ method: ctx.method,
153
+ model,
154
+ stream,
155
+ session_id: session_id ? '***' : undefined,
156
+ messages_count: messages?.length
157
+ })
158
+
159
  if (!session_id) {
160
  ctx.status = 401
161
  ctx.body = { error: '未提供有效的 session_id' }
 
169
  throw new Error('Response body is null')
170
  }
171
 
172
+ console.log('处理响应中...', {
173
+ status: response.status,
174
+ headers: Object.fromEntries(response.headers.entries()),
175
+ stream
176
+ })
177
+
178
  if (stream == "true" || stream == true) {
179
  ctx.set({
180
  'Content-Type': 'text/event-stream',
 
215
  }
216
  ],
217
  "created": Math.floor(Date.now() / 1000),
218
+ "model": model,
219
  "object": "chat.completion.chunk"
220
  })}\n\n`)
221
  }
 
250
  }
251
  ],
252
  "created": Math.floor(Date.now() / 1000),
253
+ "model": model,
254
  "object": "chat.completion.chunk"
255
  })}\n\n`)
256
  })