rsaketh02 commited on
Commit
a4555f8
·
verified ·
1 Parent(s): 7d41fca

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +46 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_groq import ChatGroq
2
+ from langchain_core.prompts import ChatPromptTemplate
3
+ from langchain_core.output_parsers import StrOutputParser
4
+ import streamlit as st
5
+
6
+ import os
7
+ from dotenv import load_dotenv
8
+ load_dotenv()
9
+
10
+
11
+ ## Langsmith Tracking
12
+ os.environ['LANGCHAIN_API_KEY'] = os.getenv('LANGCHAIN_API_KEY')
13
+ os.environ['LANGCHAIN_TRACING_V2'] = 'true'
14
+ os.environ['LANGCHAIN_PROJECT'] = "Simple Q&A Chatbot With OpenAI"
15
+ os.environ['GROQ_API_KEY'] = os.getenv('GROQ_API_KEY')
16
+
17
+ ## Prompt Template
18
+ propmt = ChatPromptTemplate(
19
+ [
20
+ ("system", "You are an helpful AI assistant. Please answer to the questions to the best of your ability."),
21
+ ("human","question:{question}"),
22
+ ]
23
+ )
24
+
25
+
26
+ def get_response(question, model):
27
+ model = ChatGroq(model=model)
28
+ output_parser = StrOutputParser()
29
+ chain = propmt|model|output_parser
30
+ response = chain.invoke({"question": question})
31
+ return response
32
+
33
+
34
+ st.title("Simple Q&A Chatbot With GROQ")
35
+
36
+ model = st.selectbox("Select a model", ["llama-3.1-8b-instant","gemma2-9b-it","llama-3.1-405b-reasoning"])
37
+ st.write("This is a simple Q&A chatbot that uses GROQ to answer questions. Ask any question and the chatbot will try to answer it.")
38
+ input_question = st.text_input("Ask a question")
39
+
40
+ if input_question:
41
+ response = get_response(input_question, model)
42
+ st.write(response)
43
+ else:
44
+ st.write("Please ask a question")
45
+
46
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ langchain_groq
2
+ langchain
3
+ python-dotenv
4
+ langchain_community
5
+ langchain_core
6
+ streamlit