Update app.py
Browse files
app.py
CHANGED
|
@@ -60,15 +60,6 @@ def run_llm(input_text,history):
|
|
| 60 |
qur= hf.embed_query(input_text)
|
| 61 |
docs = db.similarity_search_by_vector(qur, k=3)
|
| 62 |
|
| 63 |
-
'''if len(docs) >2:
|
| 64 |
-
|
| 65 |
-
doc_list = str(docs).split(" ")
|
| 66 |
-
if len(doc_list) > MAX_TOKENS:
|
| 67 |
-
doc_cnt = int(len(doc_list) / MAX_TOKENS)
|
| 68 |
-
print(doc_cnt)
|
| 69 |
-
for ea in doc_cnt:'''
|
| 70 |
-
|
| 71 |
-
|
| 72 |
print(docs)
|
| 73 |
|
| 74 |
callbacks = [StreamingStdOutCallbackHandler()]
|
|
@@ -85,30 +76,12 @@ def run_llm(input_text,history):
|
|
| 85 |
streaming=True,
|
| 86 |
huggingfacehub_api_token=token,
|
| 87 |
)
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
'''llm=HuggingFaceEndpoint(
|
| 91 |
-
endpoint_url=repo_id,
|
| 92 |
-
streaming=True,
|
| 93 |
-
max_new_tokens=2400,
|
| 94 |
-
huggingfacehub_api_token=token)'''
|
| 95 |
-
print(input_text)
|
| 96 |
-
print(history)
|
| 97 |
out=""
|
| 98 |
#prompt = ChatPromptTemplate.from_messages(
|
| 99 |
-
sys_prompt = f"Use this data to help answer users questions: {str(docs)}"
|
| 100 |
-
user_prompt = f"{input_text}"
|
| 101 |
prompt=[
|
| 102 |
{"role": "system", "content": f"[INST] Use this data to help answer users questions: {str(docs)} [/INST]"},
|
| 103 |
{"role": "user", "content": f"[INST]{input_text}[/INST]"},
|
| 104 |
]
|
| 105 |
-
#chat = ChatHuggingFace(llm=llm, verbose=True)
|
| 106 |
-
messages = [
|
| 107 |
-
("system", f"[INST] Use this data to help answer users questions: {str(docs)} [/INST]"),
|
| 108 |
-
("user", f"[INST]{input_text}[/INST]"),
|
| 109 |
-
]
|
| 110 |
-
|
| 111 |
-
#yield(llm.invoke(prompt))
|
| 112 |
|
| 113 |
t=llm.invoke(prompt)
|
| 114 |
for chunk in t:
|
|
|
|
| 60 |
qur= hf.embed_query(input_text)
|
| 61 |
docs = db.similarity_search_by_vector(qur, k=3)
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
print(docs)
|
| 64 |
|
| 65 |
callbacks = [StreamingStdOutCallbackHandler()]
|
|
|
|
| 76 |
streaming=True,
|
| 77 |
huggingfacehub_api_token=token,
|
| 78 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
out=""
|
| 80 |
#prompt = ChatPromptTemplate.from_messages(
|
|
|
|
|
|
|
| 81 |
prompt=[
|
| 82 |
{"role": "system", "content": f"[INST] Use this data to help answer users questions: {str(docs)} [/INST]"},
|
| 83 |
{"role": "user", "content": f"[INST]{input_text}[/INST]"},
|
| 84 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
t=llm.invoke(prompt)
|
| 87 |
for chunk in t:
|