Update controller.py
Browse files- controller.py +30 -0
controller.py
CHANGED
@@ -1,6 +1,13 @@
|
|
1 |
import os
|
2 |
from logger import log_response
|
3 |
from custom_agent import CustomHfAgent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
image = []
|
5 |
def handle_submission(user_message, selected_tools, url_endpoint, document, image, context):
|
6 |
|
@@ -24,4 +31,27 @@ def handle_submission(user_message, selected_tools, url_endpoint, document, imag
|
|
24 |
|
25 |
return response
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
from logger import log_response
|
3 |
from custom_agent import CustomHfAgent
|
4 |
+
|
5 |
+
|
6 |
+
from langchain.vectorstores import FAISS
|
7 |
+
from langchain.memory import ConversationBufferMemory
|
8 |
+
from langchain.chains import ConversationalRetrievalChain, ConversationChain
|
9 |
+
|
10 |
+
|
11 |
image = []
|
12 |
def handle_submission(user_message, selected_tools, url_endpoint, document, image, context):
|
13 |
|
|
|
31 |
|
32 |
return response
|
33 |
|
34 |
+
def handle_submission_chat(user_message, response):
|
35 |
+
agent_chat_bot =get_conversation_chain()
|
36 |
+
text = agent_chat_bot.predict(input=user_message, context=response)
|
37 |
+
print(text)
|
38 |
+
return text
|
39 |
+
|
40 |
+
def get_conversation_chain( ):
|
41 |
+
"""
|
42 |
+
Create a conversational retrieval chain and a language model.
|
43 |
+
|
44 |
+
"""
|
45 |
+
|
46 |
+
|
47 |
+
llm = HuggingFaceHub(
|
48 |
+
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
49 |
+
model_kwargs={"temperature": 0.5, "max_length": 1048},
|
50 |
+
)
|
51 |
+
# llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613")
|
52 |
|
53 |
+
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
54 |
+
conversation_chain = ConversationChain(
|
55 |
+
llm=llm, verbose=True, memory=ConversationBufferMemory()
|
56 |
+
)
|
57 |
+
return conversation_chain
|