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

Allow interrupting sync calls midway for ChatInterface #5990

Merged
merged 5 commits into from
Dec 5, 2023

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Dec 5, 2023

Makes it so that sync tasks are submitted to a separate thread so it's cancellable.

Screen.Recording.2023-12-04.at.10.58.51.PM.mov
import panel as pn
from openai import OpenAI

pn.extension()


def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": contents}],
        stream=True,
    )
    message = None
    for chunk in response:
        part = chunk.choices[0].delta.content
        if part is not None:
            message = instance.stream(part, user="OpenAI", message=message)


client = OpenAI()
chat_interface = pn.chat.ChatInterface(callback=callback, callback_user="ChatGPT")
chat_interface.send(
    "Send a message to get a reply from ChatGPT!", user="System", respond=False
)
chat_interface.stream("Hello")
chat_interface.show()

@ahuang11 ahuang11 changed the base branch from main to add_interrupt_async December 5, 2023 05:58
@ahuang11 ahuang11 changed the title Add interrupt sync Allow interrupting sync calls midway Dec 5, 2023
@ahuang11 ahuang11 changed the title Allow interrupting sync calls midway Allow interrupting sync calls midway for ChatInterface Dec 5, 2023
Copy link

codecov bot commented Dec 5, 2023

Codecov Report

Attention: 38 lines in your changes are missing coverage. Please review.

Comparison is base (1fb5aa8) 84.41% compared to head (30e9891) 40.77%.

❗ Current head 30e9891 differs from pull request most recent head e67f52e. Consider uploading reports for the commit e67f52e to get more accurate results

Files Patch % Lines
panel/chat/feed.py 16.66% 30 Missing ⚠️
panel/chat/interface.py 20.00% 4 Missing ⚠️
panel/tests/chat/test_feed.py 0.00% 3 Missing ⚠️
panel/tests/chat/test_interface.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           add_interrupt_async    #5990       +/-   ##
========================================================
- Coverage                84.41%   40.77%   -43.65%     
========================================================
  Files                      291      291               
  Lines                    43544    43544               
========================================================
- Hits                     36757    17753    -19004     
- Misses                    6787    25791    +19004     
Flag Coverage Δ
ui-tests 40.77% <17.39%> (-0.01%) ⬇️
unitexamples-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahuang11 ahuang11 marked this pull request as ready for review December 5, 2023 07:00
@ahuang11 ahuang11 merged commit 5823ecc into add_interrupt_async Dec 5, 2023
@ahuang11 ahuang11 deleted the add_interrupt_sync branch December 5, 2023 07:00
@hoxbro
Copy link
Member

hoxbro commented Dec 5, 2023

Was this PR ready to be merged? Failing tests seem very relevant.

Edit: I can see it was not merged into main. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants