Spaces:
Runtime error
Runtime error
added eqe manual
Browse files- InnovationHub/llm/chain.py +10 -12
InnovationHub/llm/chain.py
CHANGED
@@ -19,7 +19,6 @@ class VehicleManualChatbot:
|
|
19 |
self.embeddings = embeddings
|
20 |
self.chatgpt_chain = self._create_chatgpt_chain()
|
21 |
|
22 |
-
|
23 |
def _create_chatgpt_chain(self, temperature=0.5):
|
24 |
template = """
|
25 |
{history}
|
@@ -38,7 +37,6 @@ class VehicleManualChatbot:
|
|
38 |
memory=ConversationalBufferWindowMemory(k=2),
|
39 |
)
|
40 |
|
41 |
-
|
42 |
def _get_prompt(self, question, vehicle, k=4):
|
43 |
prompt = f"""
|
44 |
I need information from my {vehicle} manual.
|
@@ -57,7 +55,6 @@ class VehicleManualChatbot:
|
|
57 |
'\n'.join(context[:k]) + '\n' + 'Question:\n' + question
|
58 |
return user_input
|
59 |
|
60 |
-
|
61 |
def _ask_question(self, question, vehicle, k=2):
|
62 |
index = FAISS.load_local(
|
63 |
folder_path=self.db_paths[vehicle], embeddings=self.embeddings)
|
@@ -67,27 +64,28 @@ class VehicleManualChatbot:
|
|
67 |
response = self.chatgpt_chain.predict(human_input=prompt)
|
68 |
return response
|
69 |
|
70 |
-
|
71 |
def chat(self, question, vehicle, k=2, temperature=0.5):
|
72 |
-
self.chatgpt_chain = self._create_chatgpt_chain(
|
|
|
73 |
response = self._ask_question(question=question, vehicle=vehicle,
|
74 |
-
|
75 |
return response
|
76 |
|
77 |
|
78 |
-
|
79 |
db_paths = {
|
80 |
"S-Class": "data/s-class-manual",
|
81 |
-
"EQS": "data/eqs-manual"
|
|
|
82 |
}
|
83 |
|
84 |
embeddings = HuggingFaceEmbeddings()
|
85 |
|
86 |
-
vehicle_options = ["S-Class", "EQS"]
|
87 |
chatbot = VehicleManualChatbot(db_paths=db_paths,
|
88 |
vehicle_options=vehicle_options,
|
89 |
embeddings=embeddings)
|
90 |
|
|
|
91 |
def start_ui():
|
92 |
chatbot_interface = gradio.Interface(
|
93 |
fn=chatbot.chat,
|
@@ -95,7 +93,7 @@ def start_ui():
|
|
95 |
gradio.inputs.Dropdown(
|
96 |
vehicle_options, label="Select Vehicle Model"),
|
97 |
gradio.inputs.Slider(minimum=1, maximum=10, step=1, label="k")
|
98 |
-
|
99 |
outputs="text",
|
100 |
title="Owner's Manual",
|
101 |
description="Ask your vehicle manual and get a response.",
|
@@ -103,7 +101,7 @@ def start_ui():
|
|
103 |
["What is flacon?", "S-Class", 3],
|
104 |
["What is hyperscreen?", "EQS", 2],
|
105 |
["Where can I find my vin?", "EQS", 3]
|
106 |
-
|
107 |
)
|
108 |
|
109 |
-
chatbot_interface.launch()
|
|
|
19 |
self.embeddings = embeddings
|
20 |
self.chatgpt_chain = self._create_chatgpt_chain()
|
21 |
|
|
|
22 |
def _create_chatgpt_chain(self, temperature=0.5):
|
23 |
template = """
|
24 |
{history}
|
|
|
37 |
memory=ConversationalBufferWindowMemory(k=2),
|
38 |
)
|
39 |
|
|
|
40 |
def _get_prompt(self, question, vehicle, k=4):
|
41 |
prompt = f"""
|
42 |
I need information from my {vehicle} manual.
|
|
|
55 |
'\n'.join(context[:k]) + '\n' + 'Question:\n' + question
|
56 |
return user_input
|
57 |
|
|
|
58 |
def _ask_question(self, question, vehicle, k=2):
|
59 |
index = FAISS.load_local(
|
60 |
folder_path=self.db_paths[vehicle], embeddings=self.embeddings)
|
|
|
64 |
response = self.chatgpt_chain.predict(human_input=prompt)
|
65 |
return response
|
66 |
|
|
|
67 |
def chat(self, question, vehicle, k=2, temperature=0.5):
|
68 |
+
self.chatgpt_chain = self._create_chatgpt_chain(
|
69 |
+
temperature=temperature)
|
70 |
response = self._ask_question(question=question, vehicle=vehicle,
|
71 |
+
k=k)
|
72 |
return response
|
73 |
|
74 |
|
|
|
75 |
db_paths = {
|
76 |
"S-Class": "data/s-class-manual",
|
77 |
+
"EQS": "data/eqs-manual",
|
78 |
+
"EQE": "data/eqe-manual",
|
79 |
}
|
80 |
|
81 |
embeddings = HuggingFaceEmbeddings()
|
82 |
|
83 |
+
vehicle_options = ["S-Class", "EQS", "EQE"]
|
84 |
chatbot = VehicleManualChatbot(db_paths=db_paths,
|
85 |
vehicle_options=vehicle_options,
|
86 |
embeddings=embeddings)
|
87 |
|
88 |
+
|
89 |
def start_ui():
|
90 |
chatbot_interface = gradio.Interface(
|
91 |
fn=chatbot.chat,
|
|
|
93 |
gradio.inputs.Dropdown(
|
94 |
vehicle_options, label="Select Vehicle Model"),
|
95 |
gradio.inputs.Slider(minimum=1, maximum=10, step=1, label="k")
|
96 |
+
],
|
97 |
outputs="text",
|
98 |
title="Owner's Manual",
|
99 |
description="Ask your vehicle manual and get a response.",
|
|
|
101 |
["What is flacon?", "S-Class", 3],
|
102 |
["What is hyperscreen?", "EQS", 2],
|
103 |
["Where can I find my vin?", "EQS", 3]
|
104 |
+
]
|
105 |
)
|
106 |
|
107 |
+
chatbot_interface.launch()
|