-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Stop generation button (closes #86) #88
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d8ef285
add stop generation button
Grsmto e9c2adf
update button position to be within the input + use CSS for transitio…
Grsmto c3f73e8
refactor stop generating button to not have useless dispatch event
Grsmto 25fabae
fix stop generation button positioning on mobile +
Grsmto c51b182
fix typo
Grsmto 05bf0c7
🔀 Merge remote-tracking branch 'origin/main' into stop-generation-button
coyotte508 421ca02
✨ Add backend code to abort generation
coyotte508 89415c8
✨ Update frontend to call abort endpoint
coyotte508 16fc8b5
Merge branch 'main' into stop-generation-button
coyotte508 74119a8
add abort controller on messages + update to latest hf.js
Grsmto 6635d81
Revert "add abort controller on messages + update to latest hf.js"
Grsmto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
<script lang="ts"> | ||
import CarbonPause from "~icons/carbon/pause-filled"; | ||
|
||
export let visible: boolean = false; | ||
export let className = ""; | ||
</script> | ||
|
||
<button | ||
type="button" | ||
on:click | ||
class="absolute btn flex rounded-lg border py-1 px-3 shadow-sm bg-white dark:bg-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:border-gray-600 transition-all | ||
{className} | ||
{visible ? 'opacity-100 visible' : 'opacity-0 invisible'} | ||
" | ||
> | ||
<CarbonPause class="mr-1 -ml-1 w-[1.1875rem] h-[1.25rem] text-gray-400" /> Stop generating | ||
</button> |
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,29 @@ | ||
// Shouldn't be needed if we dove into sveltekit internals, see https://github.com/huggingface/chat-ui/pull/88#issuecomment-1523173850 | ||
|
||
import { setTimeout } from "node:timers/promises"; | ||
import { collections } from "./database"; | ||
|
||
let closed = false; | ||
process.on("SIGINT", () => { | ||
closed = true; | ||
}); | ||
|
||
export let abortedGenerations: Map<string, Date> = new Map(); | ||
|
||
async function maintainAbortedGenerations() { | ||
while (!closed) { | ||
await setTimeout(1000); | ||
|
||
try { | ||
const aborts = await collections.abortedGenerations.find({}).sort({ createdAt: 1 }).toArray(); | ||
|
||
abortedGenerations = new Map( | ||
aborts.map(({ conversationId, createdAt }) => [conversationId.toString(), createdAt]) | ||
); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
} | ||
|
||
maintainAbortedGenerations(); |
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,9 @@ | ||
// Ideally shouldn't be needed, see https://github.com/huggingface/chat-ui/pull/88#issuecomment-1523173850 | ||
|
||
import type { Conversation } from "./Conversation"; | ||
|
||
export interface AbortedGeneration { | ||
createdAt: Date; | ||
updatedAt: Date; | ||
conversationId: Conversation["_id"]; | ||
} |
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,12 @@ | ||
import { sum } from "./sum"; | ||
|
||
export function concatUint8Arrays(arrays: Uint8Array[]): Uint8Array { | ||
const totalLength = sum(arrays.map((a) => a.length)); | ||
const result = new Uint8Array(totalLength); | ||
let offset = 0; | ||
for (const array of arrays) { | ||
result.set(array, offset); | ||
offset += array.length; | ||
} | ||
return result; | ||
} |
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,27 @@ | ||
import { collections } from "$lib/server/database"; | ||
import { error } from "@sveltejs/kit"; | ||
import { ObjectId } from "mongodb"; | ||
|
||
/** | ||
* Ideally, we'd be able to detect the client-side abort, see https://github.com/huggingface/chat-ui/pull/88#issuecomment-1523173850 | ||
*/ | ||
export async function POST({ params, locals }) { | ||
const conversationId = new ObjectId(params.id); | ||
|
||
const conversation = await collections.conversations.findOne({ | ||
_id: conversationId, | ||
sessionId: locals.sessionId, | ||
}); | ||
|
||
if (!conversation) { | ||
throw error(404, "Conversation not found"); | ||
} | ||
|
||
await collections.abortedGenerations.updateOne( | ||
{ conversationId }, | ||
{ $set: { updatedAt: new Date() }, $setOnInsert: { createdAt: new Date() } }, | ||
{ upsert: true } | ||
); | ||
|
||
return new Response(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove this, it reappeared in the last commit but not valid anymore