Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide closeStream #6659

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ export class CopilotClient {
async chatText({
sessionId,
messageId,
signal,
}: {
sessionId: string;
messageId: string;
signal?: AbortSignal;
}) {
const url = new URL(`${this.backendUrl}/api/copilot/chat/${sessionId}`);
url.searchParams.set('messageId', messageId);
const response = await fetch(url.toString());
const response = await fetch(url.toString(), { signal });
return response.text();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type TextToTextOptions = {
params?: Record<string, string>;
timeout?: number;
stream?: boolean;
signal?: AbortSignal;
};

export function createChatSession({
Expand Down Expand Up @@ -102,6 +103,7 @@ export function textToText({
params,
sessionId,
stream,
signal,
timeout = TIMEOUT,
}: TextToTextOptions) {
if (stream) {
Expand All @@ -120,6 +122,15 @@ export function textToText({
sessionId: message.sessionId,
messageId: message.messageId,
});
if (signal) {
if (signal.aborted) {
EYHN marked this conversation as resolved.
Show resolved Hide resolved
eventSource.close();
return;
}
signal.onabort = () => {
regischen marked this conversation as resolved.
Show resolved Hide resolved
eventSource.close();
};
}
for await (const event of toTextStream(eventSource, { timeout })) {
if (event.type === 'message') {
yield event.data;
Expand Down
Loading