Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a30f2e1

Browse filesBrowse files
Updated README and llama_cpp/llama.py
1 parent e72a718 commit a30f2e1
Copy full SHA for a30f2e1

File tree

Expand file treeCollapse file tree

2 files changed

+17
-13
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-13
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ passages1 = llama_cpp.passSearch()
666666
import os
667667
username = os.getenv("USERNAME")
668668
modelPath = LlamaX(
669-
model_path=f"C:\\Users\\{username}\\Models\\cross-encoder\\ms-marco-TinyBERT-L-2",
669+
model_path=models(),
670670
)
671671

672672
# Load LlamaCpp GGUF embeddings model and parse in the searchQuery function with the scored passages to generate embeddings
@@ -679,8 +679,8 @@ try:
679679
)
680680
# Store each document in a vector embedding database
681681
for i, d in enumerate(llama_cpp.searchQuery(
682-
question=question,
683-
model_path=modelPath)):
682+
question=question
683+
)):
684684
response = llm_embed.create_embedding(
685685
input=d
686686
)

‎llama_cpp/llama.py

Copy file name to clipboardExpand all lines: llama_cpp/llama.py
+14-10Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,26 @@
5656
from ._logger import set_verbose
5757
from ._utils import suppress_stdout_stderr
5858

59-
# LlamaX class that takes a string as input and returns that string
59+
username = os.getenv("USERNAME")
60+
61+
def models():
62+
try:
63+
model = CrossEncoder(model_name="cross-encoder/ms-marco-TinyBERT-L-2")
64+
return model
65+
except Exception as e:
66+
print("Please add your cross-encoder model.")
67+
6068
class LlamaX:
61-
def __init__(self, model_path: str):
62-
self.model_path = model_path
69+
def __init__(self):
70+
self.model_path = models()
6371

6472
def get_model_path(self) -> str:
6573
return self.model_path
6674

67-
# nltk dataloader. requires nltk to be installed
6875
def nlLoader(nltkData):
6976
nltk_data_dir = Path(nltkData)
7077
nltk.data.path.append(str(nltk_data_dir))
7178

72-
# Sentence-splitter function
7379
def sentSplit():
7480

7581
username = os.getenv('USERNAME')
@@ -84,7 +90,6 @@ def sentSplit():
8490
if filename.endswith('.txt'):
8591
with open(file_path, encoding='utf-8') as file:
8692
document = file.read()
87-
return document
8893

8994
## We split this article into paragraphs and then every paragraph into sentences
9095
paragraphs = []
@@ -99,7 +104,6 @@ def sentSplit():
99104
Please add your text dataset to the Data directory. Before continuing. Thank you!''')
100105
print(e)
101106

102-
# Paragraph search function. Window-size may be adjusted
103107
def passSearch():
104108
window_size = 3
105109
passages = []
@@ -109,15 +113,15 @@ def passSearch():
109113
passages.append(" ".join(paragraph[start_idx:end_idx]))
110114
return passages
111115

112-
# Search in a loop for individual queries and predict the scores for the [query, passage] pairs
113-
def searchQuery(question, model_path: str):
116+
117+
def searchQuery(question):
114118
query = []
115119
query.append(question)
116120
docs = []
117121

118122
for que in query:
119123
try:
120-
model = model_path
124+
model = models()
121125
# Concatenate the query and all passages and predict the scores for the pairs [query, passage]
122126
model_inputs = [[que, passage] for passage in passSearch()]
123127
scores = model.predict(model_inputs)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.