Read only demo database

This commit is contained in:
Tomaz Bratanic
2024-01-12 10:54:35 +01:00
parent 2abec87169
commit b0b6069474
2 changed files with 7 additions and 6 deletions
@@ -14,7 +14,7 @@ from neo4j_semantic_layer.memory_tool import MemoryTool
from neo4j_semantic_layer.recommendation_tool import RecommenderTool
llm = ChatOpenAI(temperature=0, model="gpt-4")
tools = [InformationTool(), RecommenderTool(), MemoryTool()]
tools = [InformationTool(), RecommenderTool()]# MemoryTool()]
llm_with_tools = llm.bind(functions=[format_tool_to_openai_function(t) for t in tools])
@@ -41,7 +41,7 @@ def remove_lucene_chars(text: str) -> str:
return text.strip()
def generate_full_text_query(input: str) -> str:
def generate_full_text_query(input: str, type: str) -> str:
"""
Generate a full-text search query for a given input string.
@@ -51,11 +51,12 @@ def generate_full_text_query(input: str) -> str:
operator. Useful for mapping movies and people from user questions
to database values, and allows for some misspelings.
"""
property_map = {'movie': 'title', 'person': 'name'}
full_text_query = ""
words = [el for el in remove_lucene_chars(input).split() if el]
for word in words[:-1]:
full_text_query += f" {word}~0.8 AND"
full_text_query += f" {words[-1]}~0.8"
full_text_query += f" {property_map[type]}:{word}~0.8 AND"
full_text_query += f" {property_map[type]}:{words[-1]}~0.8"
return full_text_query.strip()
@@ -77,8 +78,8 @@ def get_candidates(input: str, type: str, limit: int = 3) -> List[Dict[str, str]
matching the query, with each candidate being a dictionary containing their name
(or title) and label (either 'Person' or 'Movie').
"""
ft_query = generate_full_text_query(input)
ft_query = generate_full_text_query(input, type)
candidates = graph.query(
candidate_query, {"fulltextQuery": ft_query, "index": type, "limit": limit}
candidate_query, {"fulltextQuery": ft_query, "index": type + 'Fulltext', "limit": limit}
)
return candidates