Skip to content

Svelte useAssistant stop function does not cancel run #1743

Closed
@andrewrisse

Description

@andrewrisse

Description

When using the stop function from useAssistant, the stream stops to the client, but the run continues. If you try to start another run, and the first one (the one you thought you cancelled) has not finished, you get the error:
"Can't add messages to thread_xyz while a run run_abc is active.",
The stop function should also cancel the run:
https://platform.openai.com/docs/api-reference/runs/cancelRun

Code example

const {
    status,
    input,
    messages,
    submitMessage,
    stop,
    error
  } = useAssistant({...})

const handleCancel = () => {
 if ($status === 'in_progress') stop();
}

Additional context

The 'error' also has a 'DOMException: BodyStreamBuffer was aborted' error when calling the stop function, but this error is expected and should be ignored.

Side note -If the useAssistant messages included more information about the message (for example, the assistant_id, or createdAt fields) this could also be super helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/uibugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions