Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomaz Bratanic authored and Tomaz Bratanic committed Jan 7, 2024
1 parent 163f8ea commit bec848e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
6 changes: 4 additions & 2 deletions templates/neo4j-semantic-layer/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# Import movie information

movies_query = """
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/tomasonjo/blog-datasets/main/movies/movies.csv' AS row
LOAD CSV WITH HEADERS FROM
'https://raw.githubusercontent.com/tomasonjo/blog-datasets/main/movies/movies.csv' AS row

Check failure on line 16 in templates/neo4j-semantic-layer/ingest.py

View workflow job for this annotation

GitHub Actions / lint / build (3.8)

Ruff (E501)

neo4j-semantic-layer/ingest.py:16:89: E501 Line too long (89 > 88)

Check failure on line 16 in templates/neo4j-semantic-layer/ingest.py

View workflow job for this annotation

GitHub Actions / lint / build (3.8)

Ruff (E501)

templates/neo4j-semantic-layer/ingest.py:16:89: E501 Line too long (89 > 88)

Check failure on line 16 in templates/neo4j-semantic-layer/ingest.py

View workflow job for this annotation

GitHub Actions / lint / build (3.11)

Ruff (E501)

neo4j-semantic-layer/ingest.py:16:89: E501 Line too long (89 > 88)

Check failure on line 16 in templates/neo4j-semantic-layer/ingest.py

View workflow job for this annotation

GitHub Actions / lint / build (3.11)

Ruff (E501)

templates/neo4j-semantic-layer/ingest.py:16:89: E501 Line too long (89 > 88)
CALL {
WITH row
MERGE (m:Movie {id:row.movieId})
Expand All @@ -35,7 +36,8 @@

# Import rating information
rating_query = """
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/tomasonjo/blog-datasets/main/movies/ratings.csv' AS row
LOAD CSV WITH HEADERS FROM
'https://raw.githubusercontent.com/tomasonjo/blog-datasets/main/movies/ratings.csv' AS row

Check failure on line 40 in templates/neo4j-semantic-layer/ingest.py

View workflow job for this annotation

GitHub Actions / lint / build (3.8)

Ruff (E501)

neo4j-semantic-layer/ingest.py:40:89: E501 Line too long (90 > 88)

Check failure on line 40 in templates/neo4j-semantic-layer/ingest.py

View workflow job for this annotation

GitHub Actions / lint / build (3.8)

Ruff (E501)

templates/neo4j-semantic-layer/ingest.py:40:89: E501 Line too long (90 > 88)

Check failure on line 40 in templates/neo4j-semantic-layer/ingest.py

View workflow job for this annotation

GitHub Actions / lint / build (3.11)

Ruff (E501)

neo4j-semantic-layer/ingest.py:40:89: E501 Line too long (90 > 88)

Check failure on line 40 in templates/neo4j-semantic-layer/ingest.py

View workflow job for this annotation

GitHub Actions / lint / build (3.11)

Ruff (E501)

templates/neo4j-semantic-layer/ingest.py:40:89: E501 Line too long (90 > 88)
CALL {
WITH row
MATCH (m:Movie {id:row.movieId})
Expand Down
7 changes: 4 additions & 3 deletions templates/neo4j-semantic-layer/neo4j_semantic_layer/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
[
(
"system",
"You are a helpful assistant that finds information about movies and recommends them. "
"If tools require follow up questions, make sure to ask the user for clarification. "
"Make sure to include any available options that need to be clarified in the follow up questions",
"You are a helpful assistant that finds information about movies "
" and recommends them. If tools require follow up questions, "
"make sure to ask the user for clarification. Make sure to include "
"any available options that need to be clarified in the follow up questions",

Check failure on line 28 in templates/neo4j-semantic-layer/neo4j_semantic_layer/agent.py

View workflow job for this annotation

GitHub Actions / lint / build (3.8)

Ruff (E501)

neo4j-semantic-layer/neo4j_semantic_layer/agent.py:28:89: E501 Line too long (89 > 88)

Check failure on line 28 in templates/neo4j-semantic-layer/neo4j_semantic_layer/agent.py

View workflow job for this annotation

GitHub Actions / lint / build (3.8)

Ruff (E501)

templates/neo4j-semantic-layer/neo4j_semantic_layer/agent.py:28:89: E501 Line too long (89 > 88)

Check failure on line 28 in templates/neo4j-semantic-layer/neo4j_semantic_layer/agent.py

View workflow job for this annotation

GitHub Actions / lint / build (3.11)

Ruff (E501)

neo4j-semantic-layer/neo4j_semantic_layer/agent.py:28:89: E501 Line too long (89 > 88)

Check failure on line 28 in templates/neo4j-semantic-layer/neo4j_semantic_layer/agent.py

View workflow job for this annotation

GitHub Actions / lint / build (3.11)

Ruff (E501)

templates/neo4j-semantic-layer/neo4j_semantic_layer/agent.py:28:89: E501 Line too long (89 > 88)
),
MessagesPlaceholder(variable_name="chat_history"),
("user", "{input}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
WITH m, type(r) as type, collect(coalesce(t.name, t.title)) as names
WITH m, type+": "+reduce(s="", n IN names | s + n + ", ") as types
WITH m, collect(types) as contexts
WITH m, "type:" + labels(m)[0] + "\ntitle: "+ coalesce(m.title, m.name) + "\nyear: "+coalesce(m.released,"") +"\n" +
WITH m, "type:" + labels(m)[0] + "\ntitle: "+ coalesce(m.title, m.name)
+ "\nyear: "+coalesce(m.released,"") +"\n" +
reduce(s="", c in contexts | s + substring(c, 0, size(c)-2) +"\n") as context
RETURN context LIMIT 1
"""
Expand All @@ -30,7 +31,10 @@ def get_information(entity: str, type: str) -> str:
return "No information was found about the movie or person in the database"
elif len(candidates) > 1:
newline = "\n"
return f"Need additional information, which of these did you mean: {newline + newline.join(str(d) for d in candidates)}"
return (
"Need additional information, which of these "
f"did you mean: {newline + newline.join(str(d) for d in candidates)}"
)
data = graph.query(
description_query, params={"candidate": candidates[0]["candidate"]}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def store_movie_rating(movie: str, rating: int):
class MemoryInput(BaseModel):
movie: str = Field(description="movie the user liked")
rating: int = Field(
description="Rating from 1 to 5, where one represents heavy dislike and 5 represent the user loved the movie"
description=(
"Rating from 1 to 5, where one represents heavy dislike "
"and 5 represent the user loved the movie"
)
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def recommendation_query_movie(genre: bool) -> str:

def recommend_movie(movie: Optional[str] = None, genre: Optional[str] = None) -> str:
"""
Recommends movies based on user's history and preference for a specific movie and/or genre.
Recommends movies based on user's history and preference
for a specific movie and/or genre.
Returns:
str: A string containing a list of recommended movies, or an error message.
"""
Expand All @@ -66,14 +67,14 @@ def recommend_movie(movie: Optional[str] = None, genre: Optional[str] = None) ->
response = graph.query(recommendation_query_db_history, params)
try:
return ", ".join([el["movie"] for el in response])
except:
except Exception:
return "Can you tell us about some of the movies you liked?"
if not movie and genre:
# Recommend top voted movies in the genre the user haven't seen before
response = graph.query(recommendation_query_genre, params)
try:
return ", ".join([el["movie"] for el in response])
except:
except Exception:
return "Something went wrong"

candidates = get_candidates(movie, "movie")
Expand All @@ -84,7 +85,7 @@ def recommend_movie(movie: Optional[str] = None, genre: Optional[str] = None) ->
response = graph.query(query, params)
try:
return ", ".join([el["movie"] for el in response])
except:
except Exception:
return "Something went wrong"


Expand Down Expand Up @@ -114,7 +115,9 @@ def recommend_movie(movie: Optional[str] = None, genre: Optional[str] = None) ->
class RecommenderInput(BaseModel):
movie: Optional[str] = Field(description="movie used for recommendation")
genre: Optional[str] = Field(
description=f"genre used for recommendation. Available options are: {all_genres}"
description=(
"genre used for recommendation. Available options are:" f"{all_genres}"
)
)


Expand Down
3 changes: 2 additions & 1 deletion templates/neo4j-semantic-layer/neo4j_semantic_layer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def generate_full_text_query(input: str) -> str:
candidate_query = """
CALL db.index.fulltext.queryNodes($index, $fulltextQuery, {limit: $limit})
YIELD node
RETURN coalesce(node.name, node.title) AS candidate, [el in labels(node) WHERE el IN ['Person', 'Movie'] | el][0] AS label
RETURN coalesce(node.name, node.title) AS candidate,
[el in labels(node) WHERE el IN ['Person', 'Movie'] | el][0] AS label
"""


Expand Down

0 comments on commit bec848e

Please sign in to comment.