themanas021 commited on
Commit
eef917b
1 Parent(s): 37942a7

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms import HuggingFaceEndpoint
2
+ from langchain.chains import LLMChain
3
+ from langchain.prompts import PromptTemplate
4
+ import chainlit as cl
5
+ import os
6
+ repo_id = "tiiuae/falcon-7b-instruct"
7
+
8
+ from config import HUGGINGFACEHUB_API_TOKEN
9
+
10
+ # Set the token as an environment variable
11
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACEHUB_API_TOKEN
12
+
13
+ llm = HuggingFaceEndpoint(
14
+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN
15
+ )
16
+
17
+
18
+ template = """ You're a general chatbot that can answer any thing related to enterprises.{question}
19
+ """
20
+
21
+
22
+ @cl.on_chat_start
23
+ def main():
24
+ # Instantiate the chain for that user session
25
+ prompt = PromptTemplate(template=template, input_variables=["question"])
26
+ llm_chain = LLMChain(prompt=prompt, llm=llm, verbose=True)
27
+
28
+ # Store the chain in the user session
29
+ cl.user_session.set("llm_chain", llm_chain)
30
+
31
+
32
+ @cl.on_message
33
+ async def main(message: cl.Message):
34
+ # Retrieve the chain from the user session
35
+ llm_chain = cl.user_session.get("llm_chain") # type: LLMChain
36
+
37
+ # Call the chain asynchronously
38
+ res = await llm_chain.acall(message.content, callbacks=[cl.AsyncLangchainCallbackHandler()])
39
+ await cl.Message(content=res["text"]).send()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ chainlit
2
+ langchain