Spaces:
Sleeping
Sleeping
Update util.py
Browse files
util.py
CHANGED
@@ -9,9 +9,9 @@ import git
|
|
9 |
|
10 |
# embeddings = HuggingFaceHubEmbeddings(model="thuan9889/llama_embedding_model_v1")
|
11 |
from chromadb.utils import embedding_functions
|
12 |
-
embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=os.environ['GOOGLE_API_KEY'], task_type="
|
13 |
|
14 |
-
model = ChatGoogleGenerativeAI(model="gemini-pro",google_api_key=os.environ['GOOGLE_API_KEY'],temperature=0.2,convert_system_message_to_human=
|
15 |
|
16 |
def get_folder_paths(directory = "githubCode"):
|
17 |
folder_paths = []
|
@@ -44,23 +44,20 @@ loader = TextLoader("Code.txt", encoding="utf-8")
|
|
44 |
pages = loader.load_and_split()
|
45 |
|
46 |
# Split data into chunks
|
47 |
-
text_splitter = RecursiveCharacterTextSplitter(chunk_size=
|
48 |
context = "\n\n".join(str(p.page_content) for p in pages)
|
49 |
texts = text_splitter.split_text(context)
|
50 |
|
51 |
-
vector_index = Chroma.from_texts(texts, embeddings).as_retriever(search_kwargs={"k":
|
52 |
|
53 |
-
# import shutil
|
54 |
-
# shutil.rmtree('githubCode')
|
55 |
-
# print("Directory removed!!")
|
56 |
qa_chain = RetrievalQA.from_chain_type(
|
57 |
model,
|
58 |
retriever=vector_index,
|
59 |
return_source_documents=True
|
60 |
)
|
61 |
-
|
62 |
# Function to generate assistant's response using ask function
|
63 |
-
def
|
64 |
answer = qa_chain({"query": question})
|
65 |
print(answer)
|
66 |
return answer['result']
|
|
|
9 |
|
10 |
# embeddings = HuggingFaceHubEmbeddings(model="thuan9889/llama_embedding_model_v1")
|
11 |
from chromadb.utils import embedding_functions
|
12 |
+
embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=os.environ['GOOGLE_API_KEY'], task_type="retrieval_document")
|
13 |
|
14 |
+
model = ChatGoogleGenerativeAI(model="gemini-pro",google_api_key=os.environ['GOOGLE_API_KEY'],temperature=0.2,convert_system_message_to_human=False)
|
15 |
|
16 |
def get_folder_paths(directory = "githubCode"):
|
17 |
folder_paths = []
|
|
|
44 |
pages = loader.load_and_split()
|
45 |
|
46 |
# Split data into chunks
|
47 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=4000, chunk_overlap=200)
|
48 |
context = "\n\n".join(str(p.page_content) for p in pages)
|
49 |
texts = text_splitter.split_text(context)
|
50 |
|
51 |
+
vector_index = Chroma.from_texts(texts, embeddings).as_retriever(search_kwargs={"k":3})
|
52 |
|
|
|
|
|
|
|
53 |
qa_chain = RetrievalQA.from_chain_type(
|
54 |
model,
|
55 |
retriever=vector_index,
|
56 |
return_source_documents=True
|
57 |
)
|
58 |
+
|
59 |
# Function to generate assistant's response using ask function
|
60 |
+
def ask(question):
|
61 |
answer = qa_chain({"query": question})
|
62 |
print(answer)
|
63 |
return answer['result']
|