-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JAQPOT-432): docker llm UI (#87)
* feat(JAQPOT-432): docker llm ui * feat: current progress of llm form * feat: send whole dataset for streaming prediction * feat: add chat grid component * feat: working version of streaming prediction * fix: remove console.logs * fix: remove obsolete code
- Loading branch information
Showing
19 changed files
with
624 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/app/api/models/[modelId]/predict/stream/[datasetId]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { NextResponse } from 'next/server'; | ||
import { | ||
ApiResponse, | ||
errorResponse, | ||
handleApiResponse, | ||
} from '@/app/util/response'; | ||
import { auth } from '@/auth'; | ||
import { isAuthenticated } from '@/app/util/auth'; | ||
import { DatasetDto } from '@/app/api.types'; | ||
import { NextApiResponse } from 'next'; | ||
|
||
function iteratorToStream(reader: any) { | ||
return new ReadableStream({ | ||
async pull(controller) { | ||
const { value, done } = await reader.read(); | ||
|
||
if (done) { | ||
controller.close(); | ||
} else { | ||
controller.enqueue(value); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
export async function POST( | ||
request: Request, | ||
{ params }: { params: { modelId: string; datasetId: string } }, | ||
) { | ||
const session = await auth(); | ||
if (!isAuthenticated(session)) { | ||
return errorResponse( | ||
'You need to be authenticated to access this endpoint', | ||
401, | ||
); | ||
} | ||
|
||
const body = await request.json(); | ||
|
||
const streamResponse = await fetch( | ||
`${process.env.API_URL}/v1/models/${params.modelId}/predict/stream/${params.datasetId}`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${session!.token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(body), | ||
}, | ||
); | ||
|
||
const reader = streamResponse | ||
.body!.pipeThrough(new TextDecoderStream()) | ||
.getReader(); | ||
|
||
const stream = iteratorToStream(reader); | ||
|
||
return new Response(stream); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { auth } from '@/auth'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { | ||
ApiResponse, | ||
errorResponse, | ||
handleApiResponse, | ||
} from '@/app/util/response'; | ||
import { isAuthenticated } from '@/app/util/auth'; | ||
import { generatePaginationAndSortingSearchParams } from '@/app/util/sort'; | ||
|
||
export async function POST( | ||
request: NextRequest, | ||
{ params }: { params: { modelId: string } }, | ||
): Promise<NextResponse<ApiResponse>> { | ||
const session = await auth(); | ||
if (!isAuthenticated(session)) { | ||
return errorResponse( | ||
'You need to be authenticated to access this endpoint', | ||
401, | ||
); | ||
} | ||
|
||
const data = await request.json(); | ||
|
||
const res = await fetch( | ||
`${process.env.API_URL}/v1/user/models/${params.modelId}/datasets`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${session!.token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(data), | ||
}, | ||
); | ||
|
||
return handleApiResponse(res); | ||
} | ||
|
||
export async function GET( | ||
request: NextRequest, | ||
{ params }: { params: { modelId: string } }, | ||
): Promise<NextResponse<ApiResponse>> { | ||
const session = await auth(); | ||
if (!isAuthenticated(session)) { | ||
return errorResponse( | ||
'You need to be authenticated to access this endpoint', | ||
401, | ||
); | ||
} | ||
|
||
const searchParams = generatePaginationAndSortingSearchParams(request); | ||
|
||
const res = await fetch( | ||
`${process.env.API_URL}/v1/user/models/${params.modelId}/datasets?${searchParams}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${session!.token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
); | ||
|
||
return handleApiResponse(res); | ||
} |
3 changes: 3 additions & 0 deletions
3
src/app/dashboard/models/[modelId]/[tabName]/[datasetId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Page from '../page'; | ||
|
||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.