Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,8 +18,20 @@ llm = LlamaCpp(
|
|
| 18 |
)
|
| 19 |
print("creating ll ended")
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
### Instruction:
|
| 24 |
{question}
|
| 25 |
|
|
@@ -29,16 +41,31 @@ template = """You are the Finiantial expert:
|
|
| 29 |
### Response:
|
| 30 |
"""
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
print("creating model created")
|
| 36 |
|
| 37 |
|
| 38 |
def greet(question):
|
| 39 |
print(f"question is {question}")
|
| 40 |
|
| 41 |
-
out_gen =
|
| 42 |
print(f"out is {out_gen}")
|
| 43 |
return out_gen
|
| 44 |
|
|
|
|
| 18 |
)
|
| 19 |
print("creating ll ended")
|
| 20 |
|
| 21 |
+
from langchain.chains import RetrievalQA
|
| 22 |
+
from langchain.memory import ConversationBufferMemory
|
| 23 |
+
from langchain import PromptTemplate
|
| 24 |
+
from langchain.retrievers import TFIDFRetriever
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
retriever = TFIDFRetriever.from_texts(
|
| 29 |
+
["Finatial AI"])
|
| 30 |
|
| 31 |
+
|
| 32 |
+
template = """You are the Finiantial expert:
|
| 33 |
+
{history}
|
| 34 |
+
{context}
|
| 35 |
### Instruction:
|
| 36 |
{question}
|
| 37 |
|
|
|
|
| 41 |
### Response:
|
| 42 |
"""
|
| 43 |
|
| 44 |
+
prompt1 = PromptTemplate(
|
| 45 |
+
input_variables=["history", "context", "question"],
|
| 46 |
+
template=template,
|
| 47 |
+
)
|
| 48 |
|
| 49 |
+
qa = RetrievalQA.from_chain_type(
|
| 50 |
+
llm=llm,
|
| 51 |
+
chain_type='stuff',
|
| 52 |
+
retriever=retriever,
|
| 53 |
+
verbose=False,
|
| 54 |
+
chain_type_kwargs={
|
| 55 |
+
"verbose": False,
|
| 56 |
+
"prompt": prompt1,
|
| 57 |
+
"memory": ConversationBufferMemory(
|
| 58 |
+
memory_key="history",
|
| 59 |
+
input_key="question"),
|
| 60 |
+
}
|
| 61 |
+
)
|
| 62 |
print("creating model created")
|
| 63 |
|
| 64 |
|
| 65 |
def greet(question):
|
| 66 |
print(f"question is {question}")
|
| 67 |
|
| 68 |
+
out_gen = qa.run(question)
|
| 69 |
print(f"out is {out_gen}")
|
| 70 |
return out_gen
|
| 71 |
|