forked from menloparklab/falcon-langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
26 lines (17 loc) · 754 Bytes
/
app.py
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
import chainlit as cl
import os
huggingfacehub_api_token = os.environ['HUGGINGFACEHUB_API_TOKEN']
from langchain import HuggingFaceHub, PromptTemplate, LLMChain
repo_id = "tiiuae/falcon-7b-instruct"
llm = HuggingFaceHub(huggingfacehub_api_token=huggingfacehub_api_token,
repo_id=repo_id,
model_kwargs={"temperature":0.6, "max_new_tokens":2000})
template = """
You are an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.
{question}
"""
@cl.langchain_factory
def factory():
prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=llm, verbose=True)
return llm_chain