Spaces:
Runtime error
Runtime error
Update src/chatbot.py
Browse files- src/chatbot.py +15 -12
src/chatbot.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 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 |
-
|
| 7 |
from langchain.chains.combine_documents import create_stuff_documents_chain
|
| 8 |
from langchain.chains import create_retrieval_chain
|
| 9 |
|
|
@@ -19,22 +20,24 @@ load_dotenv(find_dotenv())
|
|
| 19 |
|
| 20 |
# Define important variables
|
| 21 |
embeddings = HuggingFaceEmbeddings(model_name="paraphrase-multilingual-MiniLM-L12-v2") # Remove embedding input parameter from functions?
|
| 22 |
-
llm =
|
| 23 |
# ToDo: Try different models here
|
| 24 |
-
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 25 |
-
#repo_id
|
| 26 |
-
#repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 27 |
# repo_id="CohereForAI/c4ai-command-r-v01", # too large 69gb
|
| 28 |
# repo_id="CohereForAI/c4ai-command-r-v01-4bit", # too large 22gb
|
| 29 |
# repo_id="meta-llama/Meta-Llama-3-8B", # too large 16 gb
|
|
|
|
| 30 |
task="text-generation",
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
"temperature": 0.01,
|
| 35 |
-
|
| 36 |
-
}
|
| 37 |
)
|
|
|
|
|
|
|
| 38 |
# ToDo: Experiment with different templates
|
| 39 |
prompt_test = ChatPromptTemplate.from_template("""<s>[INST]
|
| 40 |
Instruction: Beantworte die folgende Frage auf deutsch und nur auf der Grundlage des angegebenen Kontexts:
|
|
|
|
| 1 |
from langchain_core.prompts import ChatPromptTemplate
|
| 2 |
+
# from langchain_community.llms.huggingface_hub import HuggingFaceHub # deprecated
|
| 3 |
+
# from langchain_community.embeddings import HuggingFaceEmbeddings # deprecated
|
| 4 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
| 5 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 6 |
from langchain_community.vectorstores import FAISS
|
| 7 |
|
|
|
|
| 8 |
from langchain.chains.combine_documents import create_stuff_documents_chain
|
| 9 |
from langchain.chains import create_retrieval_chain
|
| 10 |
|
|
|
|
| 20 |
|
| 21 |
# Define important variables
|
| 22 |
embeddings = HuggingFaceEmbeddings(model_name="paraphrase-multilingual-MiniLM-L12-v2") # Remove embedding input parameter from functions?
|
| 23 |
+
llm = HuggingFaceEndpoint(
|
| 24 |
# ToDo: Try different models here
|
| 25 |
+
# repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 26 |
+
# repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
|
|
| 27 |
# repo_id="CohereForAI/c4ai-command-r-v01", # too large 69gb
|
| 28 |
# repo_id="CohereForAI/c4ai-command-r-v01-4bit", # too large 22gb
|
| 29 |
# repo_id="meta-llama/Meta-Llama-3-8B", # too large 16 gb
|
| 30 |
+
repo_id="mistralai/Ministral-8B-Instruct-2410",
|
| 31 |
task="text-generation",
|
| 32 |
+
max_new_tokens=512,
|
| 33 |
+
repetition_penalty=1.03,
|
| 34 |
+
parameters={
|
| 35 |
+
"top_k": 30,
|
| 36 |
"temperature": 0.01,
|
| 37 |
+
}
|
|
|
|
| 38 |
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
# ToDo: Experiment with different templates
|
| 42 |
prompt_test = ChatPromptTemplate.from_template("""<s>[INST]
|
| 43 |
Instruction: Beantworte die folgende Frage auf deutsch und nur auf der Grundlage des angegebenen Kontexts:
|