To use this chatbot, follow these steps:
- Make sure you have the required dependencies installed. You can install them using the following command:
pip install -r requirements.txt
- Get your CodeGPT API key and agent ID. You can either set them as environment variables or pass them as query parameters in the URL.
- Run the Streamlit app by executing the following command in your terminal:
streamlit run codegpt-agent-boilerplate-streamlit.py
- Create a folder named
.streamlit
in your project directory if it doesn't already exist. - Inside the
.streamlit
folder, create a file namedsecrets.toml
. - In
secrets.toml
, enter your CodeGPT API Key and Agent ID in the following format:
codegpt_api_key = "your-api-key"
codegpt_agent_id = "your-agent-id"
- If you prefer, you can pass the API Key and Agent ID as query parameters in the URL when running the Streamlit app. For example:
http://localhost:8501/?codegpt_api_key=your-api-key&codegpt_agent_id=your-agent-id
- Type your message in the input box and press Enter to send it to the chatbot.
- The chatbot will process your message using the CodeGPT Agent and provide a response.
The chatbot has memory functionality, which means it can store and use conversation history for context. By default, it remembers the last 10 messages, but you can modify this behavior.
The code is structured as follows:
-
Sending Messages: The
send_message()
function sends messages to the CodeGPT Agent API. It accepts a boolean argumentmemory
to control whether the full conversation history or only the latest message is sent. -
Initializing Chat History: The chat history is stored in the
st.session_state.messages
list. -
Displaying Messages: The app displays chat messages from history on rerun and allows users to input their messages.
-
Displaying Responses: The assistant's response is displayed using the
st.chat_message()
function. -
Streamlit Configuration: The Streamlit app is configured with a page title, icon, and menu items.
Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
For more information or assistance, you can visit the CodeGPT website or report issues on the GitHub repository.
This chatbot boilerplate is provided as-is and can serve as a foundation for test or building your own conversational applications.