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

Chat with CSV fix #160

Merged
merged 10 commits into from
Mar 25, 2024
Merged

Chat with CSV fix #160

merged 10 commits into from
Mar 25, 2024

Conversation

neelasha23
Copy link
Contributor

@neelasha23 neelasha23 commented Mar 21, 2024

Closes #152


📚 Documentation preview 📚: https://ploomber-doc--160.org.readthedocs.build/en/160/

@neelasha23
Copy link
Contributor Author

Deployed without OpenAI key: https://calm-pond-0229.ploomberapp.io/
Deployed with OpenAI key: https://ancient-dream-9242.ploomberapp.io/
@edublancas

@neelasha23 neelasha23 marked this pull request as ready for review March 21, 2024 12:10
@neelasha23 neelasha23 marked this pull request as draft March 21, 2024 13:38
@neelasha23
Copy link
Contributor Author

neelasha23 commented Mar 25, 2024

Approach 1: (works in Jupyterlab but not Voila)

If OpenAI key not set then display input box where users can input the key. It will get saved and run all the below cells again to display the chatbox by running:

app = JupyterFrontEnd()
app.commands.execute('notebook:run-all-below')

The last cell re-running is needed because there's an if condition which checks whether OpenAI API key is set and only if it's set it creates and displays the chat input box.

This works in Jupyterlab:

Screen.Recording.2024-03-25.at.5.22.22.PM.mov

But this doesn't work in Voila, found a related issue: voila-dashboards/voila#614

Screen.Recording.2024-03-25.at.5.21.31.PM.mov

Approach 2 (Works):

Have removed the if openai.api_key != "YOUR_API_KEY" condition altogether from the last cell:

if openai.api_key != "YOUR_API_KEY":
    # chat output
    chat_output = widgets.Output()
    display(chat_output)
    
    # text input
    user_input = widgets.Text(placeholder='Type your message...')
    user_input.on_submit(handle_submit_button)
    display(user_input)
    
    # submit button
    submit_button = widgets.Button(description='Submit')
    submit_button.on_click(handle_submit_button)
    display(submit_button)
else:
    print("**No Open AI key was found. Please update your Open AI key in the notebook before continuing!**")

This will create the chat input box irrespective of whether OpenAI API key is found or not. But it would be disabled till user inputs the API Key. This would eliminate the need to rerun this cell. And user will be prompted for entering the API key when uploading data or using sample data.

I was also getting an error when uploading a file, fixed it by changing this line to uploaded_file = uploaded_files[0]:
Screenshot 2024-03-25 at 5 46 21 PM

Deployed apps:
https://jolly-morning-8112.ploomberapp.io/ (deployed without OpenAI API Key)
https://purple-surf-9968.ploomberapp.io/ (deployed with OpenAI key)

Please review @edublancas

@@ -1,4 +1,5 @@
# requirements for chat-with-csv
sqlalchemy==2.0.28
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest version of sqlalchemy is breaking DuckDB

@neelasha23 neelasha23 marked this pull request as ready for review March 25, 2024 14:13
@edublancas edublancas merged commit 13f0cc0 into main Mar 25, 2024
1 check passed
@edublancas edublancas deleted the issue152 branch March 25, 2024 14:51
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.

chat with csv example should ask for a key if missing
2 participants