gingun18 commited on
Commit
cebb1eb
·
verified ·
1 Parent(s): 7b05acb

Upload SimpleChatBotQ&A.py

Browse files
Files changed (1) hide show
  1. SimpleChatBotQ&A.py +38 -0
SimpleChatBotQ&A.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot
2
+ from langchain_community.llms import HuggingFaceEndpoint
3
+ from langchain.chains import LLMChain
4
+ from langchain.prompts import PromptTemplate
5
+
6
+ from dotenv import load_dotenv
7
+ load_dotenv() # take environment variables from .env
8
+
9
+ import streamlit as st
10
+ import os
11
+
12
+ ## Function to load AI model and get responses. Here I can incorporate prompt template also
13
+
14
+ def get_model_response(question):
15
+ llm = HuggingFaceEndpoint(
16
+ repo_id="mistralai/Mistral-7B-Instruct-v0.2", max_length=128, temperature=0.5)
17
+ template = """Question: {question}
18
+ Answer:"""
19
+ prompt = PromptTemplate.from_template(template)
20
+ llm_chain = LLMChain(prompt=prompt, llm=llm)
21
+ response = llm_chain.invoke({"question": question})
22
+ return response
23
+
24
+
25
+ ## Initialize our StreamLit app
26
+ st.set_page_config(page_title="Simple Chatbot")
27
+
28
+ st.header("Langchain Application - Simple Chatbot")
29
+
30
+ input = st.text_input("Input: ", key="input")
31
+ response = get_model_response(input)
32
+
33
+ submit = st.button("Ask the question")
34
+
35
+ ## If ask button is clicked
36
+ if submit:
37
+ st.subheader("The response is: ")
38
+ st.write(response)