Darka001 commited on
Commit
d381d58
·
verified ·
1 Parent(s): e154370

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -20,9 +20,9 @@ from langchain_core.runnables import RunnablePassthrough, RunnableParallel
20
 
21
 
22
 
23
- model_name= 'mistralai/Mistral-7B-Instruct-v0.2'
24
 
25
- #model_name='SherlockAssistant/Mistral-7B-Instruct-Ukrainian'
26
 
27
  tokenizer = AutoTokenizer.from_pretrained(model_name)
28
  tokenizer.pad_token = tokenizer.unk_token
@@ -98,7 +98,7 @@ db3 = Chroma(persist_directory="chroma/", embedding_function=instructor_embeddin
98
 
99
 
100
  retriever = db3.as_retriever(search_type="similarity_score_threshold",
101
- search_kwargs={"score_threshold": .5,
102
  "k": 20})
103
 
104
  #retriever = db3.as_retriever(search_kwargs={"k":15})
@@ -154,7 +154,7 @@ def format_result(result):
154
  def generate_with_filters(message, subject_input, rubric, date_beg, date_end):
155
  if date_beg == "2010-01-01" and date_end == "2025-01-01":
156
  rag_chain_with_filters = RunnableParallel(
157
- {"context": db3.as_retriever(search_type="mmr", search_kwargs={"k": 10,
158
  "filter": {'$and': [{'subject': {
159
  '$in': subject_input}}, {
160
  'rubric': {
@@ -163,7 +163,7 @@ def generate_with_filters(message, subject_input, rubric, date_beg, date_end):
163
  ).assign(answer=rag_chain_from_docs)
164
  else:
165
  rag_chain_with_filters = RunnableParallel(
166
- {"context": db3.as_retriever(search_type="mmr", search_kwargs={"k": 10,
167
  "filter": {'$and': [{'subject': {
168
  '$in': subject_input}}, {
169
  'rubric': {
@@ -215,7 +215,7 @@ def generate_answer(message, history, checkbox, subject_input, rubric, date_beg,
215
  'Галузевий розвиток', 'Економічна політика',
216
  'Державне будівництво', 'Соціальна політика', 'Правова політика',
217
  'Безпека і оборона', 'Гуманітарна політика']
218
- result = generate_with_filters(message)
219
 
220
 
221
  result['answer'] =result['answer'].split("[/INST]")[-1].strip()
 
20
 
21
 
22
 
23
+ #model_name= 'mistralai/Mistral-7B-Instruct-v0.2'
24
 
25
+ model_name='SherlockAssistant/Mistral-7B-Instruct-Ukrainian'
26
 
27
  tokenizer = AutoTokenizer.from_pretrained(model_name)
28
  tokenizer.pad_token = tokenizer.unk_token
 
98
 
99
 
100
  retriever = db3.as_retriever(search_type="similarity_score_threshold",
101
+ search_kwargs={"score_threshold": .8,
102
  "k": 20})
103
 
104
  #retriever = db3.as_retriever(search_kwargs={"k":15})
 
154
  def generate_with_filters(message, subject_input, rubric, date_beg, date_end):
155
  if date_beg == "2010-01-01" and date_end == "2025-01-01":
156
  rag_chain_with_filters = RunnableParallel(
157
+ {"context": db3.as_retriever(search_type="mmr", search_kwargs={"k": 15,
158
  "filter": {'$and': [{'subject': {
159
  '$in': subject_input}}, {
160
  'rubric': {
 
163
  ).assign(answer=rag_chain_from_docs)
164
  else:
165
  rag_chain_with_filters = RunnableParallel(
166
+ {"context": db3.as_retriever(search_type="mmr", search_kwargs={"k": 15,
167
  "filter": {'$and': [{'subject': {
168
  '$in': subject_input}}, {
169
  'rubric': {
 
215
  'Галузевий розвиток', 'Економічна політика',
216
  'Державне будівництво', 'Соціальна політика', 'Правова політика',
217
  'Безпека і оборона', 'Гуманітарна політика']
218
+ result = generate_with_filters(message, subject_input, rubric, date_beg, date_end)
219
 
220
 
221
  result['answer'] =result['answer'].split("[/INST]")[-1].strip()