jaothan/DockerGenAI_Streamlit
0
1class BaseLogger:
2 def __init__(self) -> None:
3 self.info = print
4
5
6def extract_title_and_question(input_string):
7 lines = input_string.strip().split("\n")
8
9 title = ""
10 question = ""
11 is_question = False # flag to know if we are inside a "Question" block
12
13 for line in lines:
14 if line.startswith("Title:"):
15 title = line.split("Title: ", 1)[1].strip()
16 elif line.startswith("Question:"):
17 question = line.split("Question: ", 1)[1].strip()
18 is_question = (
19 True # set the flag to True once we encounter a "Question:" line
20 )
21 elif is_question:
22 # if the line does not start with "Question:" but we are inside a "Question" block,
23 # then it is a continuation of the question
24 question += "\n" + line.strip()
25
26 return title, question
27
28
29def create_vector_index(driver) -> None:
30 index_query = "CREATE VECTOR INDEX stackoverflow IF NOT EXISTS FOR (m:Question) ON m.embedding"
31 try:
32 driver.query(index_query)
33 except: # Already exists
34 pass
35 index_query = "CREATE VECTOR INDEX top_answers IF NOT EXISTS FOR (m:Answer) ON m.embedding"
36 try:
37 driver.query(index_query)
38 except: # Already exists
39 pass
40
41
42def create_constraints(driver):
43 driver.query(
44 "CREATE CONSTRAINT question_id IF NOT EXISTS FOR (q:Question) REQUIRE (q.id) IS UNIQUE"
45 )
46 driver.query(
47 "CREATE CONSTRAINT answer_id IF NOT EXISTS FOR (a:Answer) REQUIRE (a.id) IS UNIQUE"
48 )
49 driver.query(
50 "CREATE CONSTRAINT user_id IF NOT EXISTS FOR (u:User) REQUIRE (u.id) IS UNIQUE"
51 )
52 driver.query(
53 "CREATE CONSTRAINT tag_name IF NOT EXISTS FOR (t:Tag) REQUIRE (t.name) IS UNIQUE"
54 )
55 