Spaces:
Sleeping
Sleeping
alexanderHSG commited on
Commit ·
846cfa0
1
Parent(s): 072c027
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,8 +11,8 @@ import re
|
|
| 11 |
import mysql.connector
|
| 12 |
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
|
| 18 |
|
|
@@ -128,7 +128,7 @@ def custom_filtering(filter_prompt, current_cypher_query, neo4j_response):
|
|
| 128 |
Do not include any nicities, greetings or repeat the task. Keep the query concise and only answer in this format.
|
| 129 |
"""
|
| 130 |
|
| 131 |
-
|
| 132 |
response = openai.chat.completions.create(
|
| 133 |
model = "gpt-4o",
|
| 134 |
response_format = {"type": "json_object"},
|
|
@@ -323,7 +323,34 @@ def profile_user(username, password):
|
|
| 323 |
def get_neo4j_response(query):
|
| 324 |
with driver.session() as session:
|
| 325 |
result = session.run(query)
|
| 326 |
-
response = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
return response
|
| 328 |
|
| 329 |
def construct_hmtl(highest_similarities = None, nodes_to_show=["SLIDE_DECK", "SLIDE", "STORYPOINT"], query=None):
|
|
|
|
| 11 |
import mysql.connector
|
| 12 |
|
| 13 |
|
| 14 |
+
from dotenv import load_dotenv
|
| 15 |
+
load_dotenv()
|
| 16 |
|
| 17 |
|
| 18 |
|
|
|
|
| 128 |
Do not include any nicities, greetings or repeat the task. Keep the query concise and only answer in this format.
|
| 129 |
"""
|
| 130 |
|
| 131 |
+
print("system_prompt\n", system_prompt)
|
| 132 |
response = openai.chat.completions.create(
|
| 133 |
model = "gpt-4o",
|
| 134 |
response_format = {"type": "json_object"},
|
|
|
|
| 323 |
def get_neo4j_response(query):
|
| 324 |
with driver.session() as session:
|
| 325 |
result = session.run(query)
|
| 326 |
+
response = []
|
| 327 |
+
for record in result:
|
| 328 |
+
clean_record = {}
|
| 329 |
+
for key, element in record.items():
|
| 330 |
+
if hasattr(element, 'properties'): # Check if element has 'properties' attribute
|
| 331 |
+
# Filter out unwanted properties and handle both Node and Relationship objects
|
| 332 |
+
filtered_properties = {k: v for k, v in element.properties.items() if k not in ['textual_content', 'embedding']}
|
| 333 |
+
clean_record[key] = filtered_properties
|
| 334 |
+
elif hasattr(element, '__iter__') and not isinstance(element, str): # Check for iterable elements except strings
|
| 335 |
+
# Handle lists or other iterable, non-string elements
|
| 336 |
+
iterable_clean = []
|
| 337 |
+
for item in element:
|
| 338 |
+
if hasattr(item, 'properties'):
|
| 339 |
+
item_properties = {k: v for k, v in item.properties.items() if k not in ['textual_content', 'embedding']}
|
| 340 |
+
iterable_clean.append(item_properties)
|
| 341 |
+
else:
|
| 342 |
+
iterable_clean.append(item)
|
| 343 |
+
clean_record[key] = iterable_clean
|
| 344 |
+
else:
|
| 345 |
+
# For other data types that are neither nodes nor relationships
|
| 346 |
+
clean_record[key] = element
|
| 347 |
+
response.append(clean_record)
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
#save to txt file
|
| 351 |
+
with open("neo4j_response.txt", "w") as f:
|
| 352 |
+
f.write(str(response))
|
| 353 |
+
|
| 354 |
return response
|
| 355 |
|
| 356 |
def construct_hmtl(highest_similarities = None, nodes_to_show=["SLIDE_DECK", "SLIDE", "STORYPOINT"], query=None):
|