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

feat:Add streamlit+groq+llama3 to build use case of simple chatbot #709

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions example/streamlit-groq-llama3-chatbot/README.md
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.
Copy link

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.

- using streamlit、groq and llama3.
+ using streamlit, groq, and llama3.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
The `app.py` is an example of building a mathematical chatbot using streamlitgroq and llama3.
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
Copy link

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
streamlit run app.py
```
streamlit run app.py

42 changes: 42 additions & 0 deletions example/streamlit-groq-llama3-chatbot/app.py
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)
3 changes: 3 additions & 0 deletions example/streamlit-groq-llama3-chatbot/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
streamlit>=1.28
Copy link
Owner

Choose a reason for hiding this comment

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

here need to add pne pkg.

promptulate
groq