Spaces:
Running
Running
h3110Fr13nd
commited on
Commit
•
5c21e57
1
Parent(s):
30122c4
credentials
Browse files
main.py
CHANGED
@@ -51,7 +51,7 @@ Don't try to make up an answer, if you don't know, say you can contact the suppo
|
|
51 |
Answer in the same language the question was asked.
|
52 |
Answer in a way that is easy to understand.
|
53 |
Try to limit the answer to 3-4 sentences.
|
54 |
-
Provide source url as well at the end of the answer.
|
55 |
Do not say "Based on the information you provided, ..." or "I think the answer is...". Just answer the question directly in detail.
|
56 |
|
57 |
History: {chat_history}
|
@@ -67,7 +67,7 @@ Answer:
|
|
67 |
)
|
68 |
self.db = Chroma(persist_directory="./pragetx_chroma", embedding_function=HuggingFaceEmbeddings(), collection_name="pragetx")
|
69 |
# self.llm = ChatOllama(model="phi3:3.8b", base_url="http://localhost:11434", num_gpu=16)
|
70 |
-
self.llm = HuggingChat(email = os.getenv("HF_EMAIL") , psw = os.getenv("HF_PASS") )
|
71 |
self.chain = (
|
72 |
{"chat_history": self.chat_history, "context": self.db.as_retriever(search_kwargs={"k":3}), "question": RunnablePassthrough()} |
|
73 |
self.prompt |
|
|
|
51 |
Answer in the same language the question was asked.
|
52 |
Answer in a way that is easy to understand.
|
53 |
Try to limit the answer to 3-4 sentences.
|
54 |
+
Provide source url as well at the end of the answer if possible.
|
55 |
Do not say "Based on the information you provided, ..." or "I think the answer is...". Just answer the question directly in detail.
|
56 |
|
57 |
History: {chat_history}
|
|
|
67 |
)
|
68 |
self.db = Chroma(persist_directory="./pragetx_chroma", embedding_function=HuggingFaceEmbeddings(), collection_name="pragetx")
|
69 |
# self.llm = ChatOllama(model="phi3:3.8b", base_url="http://localhost:11434", num_gpu=16)
|
70 |
+
self.llm = HuggingChat(email = os.getenv("HF_EMAIL") , psw = os.getenv("HF_PASS") , cookie_path="./usercookies")
|
71 |
self.chain = (
|
72 |
{"chat_history": self.chat_history, "context": self.db.as_retriever(search_kwargs={"k":3}), "question": RunnablePassthrough()} |
|
73 |
self.prompt |
|
utils.py
CHANGED
@@ -56,17 +56,22 @@ class HuggingChat(LLM):
|
|
56 |
raise ValueError("email, psw, or cookie_path is required.")
|
57 |
|
58 |
try:
|
59 |
-
if self.
|
|
|
|
|
60 |
# Create a ChatBot using email and psw
|
61 |
from hugchat.login import Login
|
62 |
start_time = time.time()
|
63 |
sign = Login(self.email, self.psw)
|
64 |
cookies = sign.login()
|
|
|
|
|
|
|
65 |
end_time = time.time()
|
66 |
if self.log : print(f"\n[LOG] Login successfull in {round(end_time - start_time)} seconds")
|
67 |
-
else:
|
68 |
-
|
69 |
-
|
70 |
|
71 |
self.chatbot = cookies.get_dict() and hugchat.ChatBot(cookies=cookies.get_dict())
|
72 |
if self.log : print(f"[LOG] LLM WRAPPER created successfully")
|
|
|
56 |
raise ValueError("email, psw, or cookie_path is required.")
|
57 |
|
58 |
try:
|
59 |
+
if self.cookie_path:
|
60 |
+
cookies = hugchat.ChatBot(cookie_path=self.cookie_path)
|
61 |
+
elif self.email and self.psw:
|
62 |
# Create a ChatBot using email and psw
|
63 |
from hugchat.login import Login
|
64 |
start_time = time.time()
|
65 |
sign = Login(self.email, self.psw)
|
66 |
cookies = sign.login()
|
67 |
+
# save cookies to cookie_path
|
68 |
+
if self.cookie_path:
|
69 |
+
sign.save_cookies(self.cookie_path)
|
70 |
end_time = time.time()
|
71 |
if self.log : print(f"\n[LOG] Login successfull in {round(end_time - start_time)} seconds")
|
72 |
+
# else:
|
73 |
+
# # Create a ChatBot using cookie_path
|
74 |
+
# cookies = self.cookie_path and hugchat.ChatBot(cookie_path=self.cookie_path)
|
75 |
|
76 |
self.chatbot = cookies.get_dict() and hugchat.ChatBot(cookies=cookies.get_dict())
|
77 |
if self.log : print(f"[LOG] LLM WRAPPER created successfully")
|