-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat:Add streamlit+groq+llama3 to build use case of simple chatbot #709
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||
# Build a mathematical chatbot using streamlit and pne | ||||||||||
|
||||||||||
The `app.py` is an example of building a mathematical chatbot using streamlit、groq and llama3. | ||||||||||
|
||||||||||
# Quick Start | ||||||||||
|
||||||||||
1. Clone the repository and install the dependencies | ||||||||||
|
||||||||||
```shell | ||||||||||
git clone https://www.github.com/Undertone0809/promptulate | ||||||||||
``` | ||||||||||
|
||||||||||
2. Switch the current directory to the example | ||||||||||
|
||||||||||
```shell | ||||||||||
cd ./example/streamlit-groq-llama3-chatbot | ||||||||||
``` | ||||||||||
|
||||||||||
3. Install the dependencies | ||||||||||
|
||||||||||
```shell | ||||||||||
pip install -r requirements.txt | ||||||||||
``` | ||||||||||
|
||||||||||
4. Run the application | ||||||||||
|
||||||||||
```shell | ||||||||||
streamlit run app.py | ||||||||||
``` | ||||||||||
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Application run instructions are clear and correct. Ensure the file ends with a newline. + Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import streamlit as st | ||
|
||
import promptulate as pne | ||
|
||
# Create a sidebar to place the user parameter configuration | ||
with st.sidebar: | ||
groq_api_key = st.text_input("Groq API Key", key="chatbot_api_key", type="password") | ||
|
||
# Set title | ||
st.title("💬 Chat") | ||
st.caption("🚀 Hi there! 👋 I am a simple chatbot by groq and llama3 to help you ") | ||
|
||
# Determine whether to initialize the message variable | ||
# otherwise initialize a message dictionary | ||
if "messages" not in st.session_state: | ||
st.session_state["messages"] = [ | ||
{"role": "assistant", "content": "How can I help you?"} | ||
] | ||
|
||
# Traverse messages in session state | ||
for msg in st.session_state.messages: | ||
st.chat_message(msg["role"]).write(msg["content"]) | ||
|
||
# User input | ||
if prompt := st.chat_input(): | ||
if not groq_api_key: | ||
st.info("Please add your Groq API key to continue.") | ||
st.stop() | ||
|
||
# Add the message entered by the user to the list of messages in the session state | ||
st.session_state.messages.append({"role": "user", "content": prompt}) | ||
# Display in the chat interface | ||
st.chat_message("user").write(prompt) | ||
|
||
response: str = pne.chat( | ||
model="groq/llama3-8b-8192", | ||
messages=prompt, | ||
model_config={"api_key": groq_api_key}, | ||
) | ||
|
||
st.session_state.messages.append({"role": "assistant", "content": response}) | ||
st.chat_message("assistant").write(response) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
streamlit>=1.28 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here need to add pne pkg. |
||
promptulate | ||
groq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct punctuation inconsistency in the technology list.
Committable suggestion