Spaces:
Runtime error
Runtime error
revert keywordearch to static
Browse files- src/chatbot.py +2 -5
src/chatbot.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
from langchain_core.prompts import ChatPromptTemplate
|
| 2 |
from langchain_community.llms.huggingface_hub import HuggingFaceHub
|
| 3 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 4 |
-
from langchain_community.vectorstores import FAISS
|
| 5 |
|
| 6 |
from src.vectordatabase import RAG, get_vectorstore
|
| 7 |
import pandas as pd
|
|
@@ -12,8 +11,6 @@ import pandas as pd
|
|
| 12 |
|
| 13 |
# Define important variables
|
| 14 |
embeddings = HuggingFaceEmbeddings(model_name="paraphrase-multilingual-MiniLM-L12-v2") # Remove embedding input parameter from functions?
|
| 15 |
-
db_all = FAISS.load_local(folder_path="./src/FAISS", index_name="speeches_1949_09_12",
|
| 16 |
-
embeddings=embeddings, allow_dangerous_deserialization=True)
|
| 17 |
llm = HuggingFaceHub(
|
| 18 |
# ToDo: Try different models here
|
| 19 |
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
@@ -112,7 +109,7 @@ def chatbot(message, history, db_inputs, prompt_language, llm=llm):
|
|
| 112 |
return response
|
| 113 |
|
| 114 |
|
| 115 |
-
def keyword_search(query,
|
| 116 |
"""
|
| 117 |
Retrieve speech contents based on keywords using a specified method.
|
| 118 |
|
|
@@ -154,7 +151,7 @@ def keyword_search(query, db=db_all, n=10, embeddings=embeddings, method='ss', p
|
|
| 154 |
- The `party_filter` parameter is a filter for retrieving speech contents by party affiliation. Specify 'All' to retrieve
|
| 155 |
speeches from all parties (default is 'All').
|
| 156 |
"""
|
| 157 |
-
|
| 158 |
query_embedding = embeddings.embed_query(query)
|
| 159 |
|
| 160 |
# Maximal Marginal Relevance
|
|
|
|
| 1 |
from langchain_core.prompts import ChatPromptTemplate
|
| 2 |
from langchain_community.llms.huggingface_hub import HuggingFaceHub
|
| 3 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
|
|
|
| 4 |
|
| 5 |
from src.vectordatabase import RAG, get_vectorstore
|
| 6 |
import pandas as pd
|
|
|
|
| 11 |
|
| 12 |
# Define important variables
|
| 13 |
embeddings = HuggingFaceEmbeddings(model_name="paraphrase-multilingual-MiniLM-L12-v2") # Remove embedding input parameter from functions?
|
|
|
|
|
|
|
| 14 |
llm = HuggingFaceHub(
|
| 15 |
# ToDo: Try different models here
|
| 16 |
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
|
|
| 109 |
return response
|
| 110 |
|
| 111 |
|
| 112 |
+
def keyword_search(query, n=10, embeddings=embeddings, method='ss', party_filter='All'):
|
| 113 |
"""
|
| 114 |
Retrieve speech contents based on keywords using a specified method.
|
| 115 |
|
|
|
|
| 151 |
- The `party_filter` parameter is a filter for retrieving speech contents by party affiliation. Specify 'All' to retrieve
|
| 152 |
speeches from all parties (default is 'All').
|
| 153 |
"""
|
| 154 |
+
db = get_vectorstore(inputs="All", embeddings=embeddings)
|
| 155 |
query_embedding = embeddings.embed_query(query)
|
| 156 |
|
| 157 |
# Maximal Marginal Relevance
|