-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80d300b
commit d3ced63
Showing
6 changed files
with
2,393 additions
and
2,292 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// ResultContentsModal.tsx | ||
import React, { forwardRef } from "react"; | ||
|
||
interface ModalProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
const ResultContentsModal = forwardRef<HTMLDivElement, ModalProps>(({ isOpen, onClose }, ref) => { | ||
if (!isOpen) return null; | ||
|
||
return ( | ||
<div className="fixed inset-0 flex items-center justify-center z-50 bg-gray-700 bg-opacity-75"> | ||
<div className="bg-white w-1/2 p-4 h-[80%] flex flex-col justify-around rounded-md"> | ||
<div ref={ref} className="p-4 h-[90%] overflow-scroll bg-gray-100 rounded-md" /> | ||
<button onClick={onClose} className="mt-4 w-full bg-blue-500 text-white p-2 rounded-md hover:bg-blue-600"> | ||
닫기 | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}); | ||
|
||
ResultContentsModal.displayName = "ResultContentsModal"; | ||
|
||
export default ResultContentsModal; |
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,40 @@ | ||
// utils/streamHandler.ts | ||
export async function handleStreamResponse( | ||
stream: ReadableStream<Uint8Array> | null, | ||
callback: { (chunk: any): void; (arg0: any): void }, | ||
) { | ||
if (!stream) { | ||
throw new Error("Stream is null"); | ||
} | ||
|
||
const reader = stream.getReader(); | ||
const decoder = new TextDecoder(); | ||
let done = false; | ||
|
||
while (!done) { | ||
const { value, done: readerDone } = await reader.read(); | ||
done = readerDone; | ||
const chunk = decoder.decode(value, { stream: true }); | ||
|
||
// 각 줄을 분리하여 처리 | ||
const lines = chunk.split("\n").filter(line => line.trim() !== ""); | ||
for (const line of lines) { | ||
if (line.startsWith("data: ")) { | ||
const data = line.replace("data: ", ""); | ||
if (data === "[DONE]") { | ||
done = true; | ||
break; | ||
} | ||
try { | ||
const json = JSON.parse(data); | ||
const content = json.choices[0].delta.content; | ||
if (content) { | ||
callback(content); | ||
} | ||
} catch (e) { | ||
console.error("Error parsing stream data:", e); | ||
} | ||
} | ||
} | ||
} | ||
} |
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