-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_service.py
24 lines (18 loc) · 961 Bytes
/
app_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from services.google_spreadsheets import get_answers_list, find_answer_by_question, find_suggestions_by_question, find_links_by_question, get_links_list, get_suggestions_list
from cydifflib import get_close_matches
def get_answer(question:str,n:int=3, cutoff:float=0.6) -> str | None:
kb:[str] = get_answers_list()
matches: list[str] = get_close_matches(
word=question,
possibilities=[q["question"] for q in kb],
n=n,
cutoff=cutoff)
if matches:
# return result from question knowledge base
return find_answer_by_question(question_as_key=matches[0],data_range=kb)
else:
return None
def get_suggestions(question:str) -> list | None:
return find_suggestions_by_question(question_as_key=question,data_range=get_suggestions_list())
def get_links(question:str) -> list | None:
return find_links_by_question(question_as_key=question,data_range=get_links_list())