FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
genai-stack/utils.py at main · RackStack-Tech/genai-stack · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
RackStack-Tech
/
genai-stack
Public
forked from
docker/genai-stack
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
genai-stack
/
utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (49 loc) · 1.84 KB
Breadcrumbs
genai-stack
/
utils.py
Copy path
File metadata and controls
60 lines (49 loc) · 1.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class
BaseLogger
:
def
__init__
(
self
)
->
None
:
self
.
info
=
print
def
extract_title_and_question
(
input_string
):
lines
=
input_string
.
strip
().
split
(
"
\n
"
)
title
=
""
question
=
""
is_question
=
False
# flag to know if we are inside a "Question" block
for
line
in
lines
:
if
line
.
startswith
(
"Title:"
):
title
=
line
.
split
(
"Title: "
,
1
)[
1
].
strip
()
elif
line
.
startswith
(
"Question:"
):
question
=
line
.
split
(
"Question: "
,
1
)[
1
].
strip
()
is_question
=
(
True
# set the flag to True once we encounter a "Question:" line
)
elif
is_question
:
# if the line does not start with "Question:" but we are inside a "Question" block,
# then it is a continuation of the question
question
+=
"
\n
"
+
line
.
strip
()
return
title
,
question
def
create_vector_index
(
driver
)
->
None
:
index_query
=
"CREATE VECTOR INDEX stackoverflow IF NOT EXISTS FOR (m:Question) ON m.embedding"
try
:
driver
.
query
(
index_query
)
except
:
# Already exists
pass
index_query
=
(
"CREATE VECTOR INDEX top_answers IF NOT EXISTS FOR (m:Answer) ON m.embedding"
)
try
:
driver
.
query
(
index_query
)
except
:
# Already exists
pass
def
create_constraints
(
driver
):
driver
.
query
(
"CREATE CONSTRAINT question_id IF NOT EXISTS FOR (q:Question) REQUIRE (q.id) IS UNIQUE"
)
driver
.
query
(
"CREATE CONSTRAINT answer_id IF NOT EXISTS FOR (a:Answer) REQUIRE (a.id) IS UNIQUE"
)
driver
.
query
(
"CREATE CONSTRAINT user_id IF NOT EXISTS FOR (u:User) REQUIRE (u.id) IS UNIQUE"
)
driver
.
query
(
"CREATE CONSTRAINT tag_name IF NOT EXISTS FOR (t:Tag) REQUIRE (t.name) IS UNIQUE"
)
def
format_docs
(
docs
):
return
"
\n
\n
"
.
join
(
doc
.
page_content
for
doc
in
docs
)
Back
|
FazBrowse Home
|
New Git URL