mirror of
https://github.com/langgenius/webapp-conversation.git
synced 2025-12-22 22:56:39 +08:00
feat: lint code
This commit is contained in:
@ -1,16 +1,16 @@
|
||||
import { type NextRequest } from 'next/server'
|
||||
import { APP_ID, API_KEY, API_URL } from '@/config'
|
||||
import { ChatClient } from 'dify-client'
|
||||
import { v4 } from 'uuid'
|
||||
import { API_KEY, API_URL, APP_ID } from '@/config'
|
||||
|
||||
const userPrefix = `user_${APP_ID}:`;
|
||||
const userPrefix = `user_${APP_ID}:`
|
||||
|
||||
export const getInfo = (request: NextRequest) => {
|
||||
const sessionId = request.cookies.get('session_id')?.value || v4();
|
||||
const user = userPrefix + sessionId;
|
||||
const sessionId = request.cookies.get('session_id')?.value || v4()
|
||||
const user = userPrefix + sessionId
|
||||
return {
|
||||
sessionId,
|
||||
user
|
||||
user,
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,4 +18,4 @@ export const setSession = (sessionId: string) => {
|
||||
return { 'Set-Cookie': `session_id=${sessionId}` }
|
||||
}
|
||||
|
||||
export const client = new ChatClient(API_KEY, API_URL ? API_URL : undefined)
|
||||
export const client = new ChatClient(API_KEY, API_URL || undefined)
|
||||
|
||||
@ -1,25 +1,25 @@
|
||||
export async function OpenAIStream(res: { body: any }) {
|
||||
const reader = res.body.getReader();
|
||||
const reader = res.body.getReader()
|
||||
|
||||
const stream = new ReadableStream({
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams
|
||||
// https://github.com/whichlight/chatgpt-api-streaming/blob/master/pages/api/OpenAIStream.ts
|
||||
start(controller) {
|
||||
return pump();
|
||||
return pump()
|
||||
function pump() {
|
||||
return reader.read().then(({ done, value }: any) => {
|
||||
// When no more data needs to be consumed, close the stream
|
||||
if (done) {
|
||||
controller.close();
|
||||
return;
|
||||
controller.close()
|
||||
return
|
||||
}
|
||||
// Enqueue the next data chunk into our target stream
|
||||
controller.enqueue(value);
|
||||
return pump();
|
||||
});
|
||||
controller.enqueue(value)
|
||||
return pump()
|
||||
})
|
||||
}
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
return stream;
|
||||
}
|
||||
return stream
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user