GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — groq_app/app.py at main · PinsaraPerera/groq_app

Expand file tree

/

app.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
60 lines (44 loc) · 1.62 KB
/

app.py

Copy path

File metadata and controls

60 lines (44 loc) · 1.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
import os
from groq import Groq
import random
from langchain.chains import ConversationChain
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
from langchain_groq import ChatGroq
from langchain.prompts import PromptTemplate
from dotenv import load_dotenv
load_dotenv()
groq_api_key = os.environ["GROQ_API_KEY"]
def main():
st.title("Groq Chat App")
# Add customization options to the sidebar
st.sidebar.title('Select an LLM')
model = st.sidebar.selectbox(
'Choose a model',
['mixtral-8x7b-32768', 'llama2-70b-4096']
)
conversational_memory_length = st.sidebar.slider('Conversational memory length:', 1, 10, value = 5)
memory=ConversationBufferWindowMemory(k=conversational_memory_length)
user_question = st.text_area("Ask a question:")
# session state variable
if 'chat_history' not in st.session_state:
st.session_state.chat_history=[]
else:
for message in st.session_state.chat_history:
memory.save_context({'input':message['human']},{'output':message['AI']})
# Initialize Groq Langchain chat object and conversation
groq_chat = ChatGroq(
groq_api_key=groq_api_key,
model_name=model
)
conversation = ConversationChain(
llm=groq_chat,
memory=memory
)
if user_question:
response = conversation(user_question)
message = {'human':user_question,'AI':response['response']}
st.session_state.chat_history.append(message)
st.write("Chatbot:", response['response'])
if __name__ == "__main__":
main()
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.