Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arturogonzalezm/chatbot_chatgpt
https://github.com/arturogonzalezm/chatbot_chatgpt
chatbot chatgpt-api python310 streamlit streamlit-application
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/arturogonzalezm/chatbot_chatgpt
- Owner: arturogonzalezm
- License: mit
- Created: 2024-03-25T03:08:49.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-03-26T03:12:29.000Z (9 months ago)
- Last Synced: 2024-03-26T04:36:35.987Z (9 months ago)
- Topics: chatbot, chatgpt-api, python310, streamlit, streamlit-application
- Language: Python
- Homepage:
- Size: 171 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![License: MIT](https://img.shields.io/badge/License-MIT-purple.svg)](https://github.com/arturogonzalezm/chatbot_chatgpt/blob/master/LICENSE)
[![Read the Docs](https://img.shields.io/readthedocs/:packageName)](https://github.com/arturogonzalezm/chatbot_chatgpt/wiki)
[![PyLint](https://github.com/arturogonzalezm/chatbot_chatgpt/actions/workflows/workflow.yml/badge.svg)](https://github.com/arturogonzalezm/chatbot_chatgpt/actions/workflows/workflow.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/arturogonzalezm/chatbot_chatgpt)# Streamlit Chatbot with OpenAI
This project integrates OpenAI's language models into a Streamlit web application, creating an interactive chatbot interface. It allows users to send messages and receive AI-generated responses, manage conversation history, and perform other interactions in real time.
## Features
- **Interactive Chat Interface**: Engage in a conversation with the AI, with the ability to view each message's response in real time.
- **Conversation History**: Maintains a log of the entire conversation for reference.
- **Conversation Management**: Supports starting new conversations, saving current conversations, renaming them, and switching between them.## Screenshots
- **White:**
![white](images/white.png)
- **Dark:**
![dark](images/dark.png)
## Tech Specs
- **Conda**: Python 3.10
- **Streamlit**: 1.32.2
- **OpenAI**: 1.14.3
- **ChatGPT**: gpt-4-turbo-preview## Code Breakdown
### OpenAI Integration
- `AsyncOpenAI Client`: Utilises `openai.AsyncOpenAI` for creating an asynchronous client with the OpenAI API, authorised via an environment-stored API key.
- `get_response`: An asynchronous function that sends user messages to the OpenAI API and awaits responses, utilizing the "gpt-4-turbo-preview" model.### Streamlit Interface
- **Initialization**: Checks and initialises `session_state` variables for storing conversation histories and saved conversations.
- **User Input Form**: Allows users to write and submit messages to the chatbot.
- **Display Area**: Shows the ongoing conversation history.
- **Sidebar Features**: Provides controls for new conversations, saving current chats, and managing saved conversations.### Conversation Management
- `save_current_chat`: Verifies whether the current conversation is already saved; if not, it saves the chat with a unique timestamp.
- **Sidebar Controls**: Include functionality for initiating new conversations, saving and renaming conversations, and loading previously saved chats.## Sequence Diagram
Below is a sequence diagram illustrating the interaction flow within the application:
```mermaid
sequenceDiagram
participant User
participant Interface as Streamlit Interface
participant Server as AsyncOpenAI ClientUser->>Interface: Enters message
Interface->>Server: Sends message
Server->>Server: Processes AI response
Server->>Interface: Returns AI response
Interface->>User: Displays response
```### Custom CSS
- **custom_css**: Custom CSS for styling the Streamlit interface, making the background gradient and adjusting other UI elements to improve the user experience.
## Usage
1. Install all required packages from the requirements.txt file.
2. Set your OpenAI API key in the `.env` file.
3. Run the Streamlit application using the command `streamlit run app.py`.
4. Interact with the chatbot through the web interface.## Note
- The application uses asynchronous calls to interact with OpenAI's API, ensuring that the user interface remains responsive.
- The chat history and saved conversations are stored in the session state, meaning they are temporary and will be cleared once the session ends or the app is reloaded.