sakuexe
commited on
Commit
·
6427fd5
1
Parent(s):
d01acd5
added debug prints
Browse files
app.py
CHANGED
@@ -40,7 +40,7 @@ MODEL_NAME = "google/gemma-2-2b-it"
|
|
40 |
model = AutoModelForCausalLM.from_pretrained(
|
41 |
MODEL_NAME,
|
42 |
# quantization_config=bnb_config,
|
43 |
-
device_map="
|
44 |
torch_dtype=torch.bfloat16
|
45 |
)
|
46 |
|
@@ -100,14 +100,18 @@ def generate_prompt(message_history: list[ChatMessage], max_history=5):
|
|
100 |
|
101 |
async def generate_answer(message_history: list[ChatMessage]):
|
102 |
# generate a vector store
|
|
|
103 |
db = await get_document_database("learning_material/*/*/*")
|
|
|
104 |
|
105 |
# initialize the similarity search
|
106 |
n_of_best_results = 4
|
107 |
retriever = db.as_retriever(
|
108 |
search_type="similarity", search_kwargs={"k": n_of_best_results})
|
109 |
|
|
|
110 |
prompt = generate_prompt(message_history, max_history=5)
|
|
|
111 |
|
112 |
# create the pipeline for generating a response
|
113 |
# RunnablePassthrough handles the invoke parameters
|
@@ -120,11 +124,13 @@ async def generate_answer(message_history: list[ChatMessage]):
|
|
120 |
|
121 |
# fetch the context using the latest message as the fetch string
|
122 |
user_input = message_history[-1]["content"]
|
|
|
123 |
response = retrieval_chain.invoke(user_input)
|
|
|
124 |
|
125 |
-
#
|
126 |
-
|
127 |
-
|
128 |
|
129 |
# get the next response from the AI
|
130 |
# first parse until the last user input and then get the first response
|
|
|
40 |
model = AutoModelForCausalLM.from_pretrained(
|
41 |
MODEL_NAME,
|
42 |
# quantization_config=bnb_config,
|
43 |
+
# device_map="cpu",
|
44 |
torch_dtype=torch.bfloat16
|
45 |
)
|
46 |
|
|
|
100 |
|
101 |
async def generate_answer(message_history: list[ChatMessage]):
|
102 |
# generate a vector store
|
103 |
+
print("creating the document database")
|
104 |
db = await get_document_database("learning_material/*/*/*")
|
105 |
+
print("Document database is ready")
|
106 |
|
107 |
# initialize the similarity search
|
108 |
n_of_best_results = 4
|
109 |
retriever = db.as_retriever(
|
110 |
search_type="similarity", search_kwargs={"k": n_of_best_results})
|
111 |
|
112 |
+
print("generating prompt")
|
113 |
prompt = generate_prompt(message_history, max_history=5)
|
114 |
+
print("prompt is ready")
|
115 |
|
116 |
# create the pipeline for generating a response
|
117 |
# RunnablePassthrough handles the invoke parameters
|
|
|
124 |
|
125 |
# fetch the context using the latest message as the fetch string
|
126 |
user_input = message_history[-1]["content"]
|
127 |
+
print("invoking")
|
128 |
response = retrieval_chain.invoke(user_input)
|
129 |
+
print("response recieved from invoke")
|
130 |
|
131 |
+
# debugging
|
132 |
+
print("=====raw response=====")
|
133 |
+
print(response)
|
134 |
|
135 |
# get the next response from the AI
|
136 |
# first parse until the last user input and then get the first response
|