Syed Junaid Iqbal commited on
Commit
c81853b
β€’
1 Parent(s): b8af443

Upload 3 files

Browse files
Langchain-FastEmbedEmbeddings.ipynb ADDED
@@ -0,0 +1,822 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "bc011235-240e-454b-9a88-410ebaa2b5d0",
7
+ "metadata": {
8
+ "scrolled": true
9
+ },
10
+ "outputs": [],
11
+ "source": [
12
+ "# ! pip install 'qdrant-client[fastembed]'"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": 1,
18
+ "id": "c0fbae00-7731-41b3-a45d-ba3c7495759d",
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "from warnings import filterwarnings\n",
23
+ "filterwarnings(\"ignore\")\n",
24
+ "from langchain.llms import LlamaCpp\n",
25
+ "from langchain.callbacks.manager import CallbackManager\n",
26
+ "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
27
+ "from langchain.document_loaders import PyPDFLoader\n",
28
+ "from langchain.embeddings import FastEmbedEmbeddings\n",
29
+ "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
30
+ "from langchain.vectorstores import Chroma\n",
31
+ "import glob\n",
32
+ "\n",
33
+ "import gc"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "markdown",
38
+ "id": "af0a35aa-223f-4db8-b01d-e098dad29d84",
39
+ "metadata": {},
40
+ "source": [
41
+ "### 1. Load the model"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 2,
47
+ "id": "b0483f28-6544-431b-995e-d31d3c5abc8a",
48
+ "metadata": {
49
+ "scrolled": true
50
+ },
51
+ "outputs": [
52
+ {
53
+ "name": "stderr",
54
+ "output_type": "stream",
55
+ "text": [
56
+ "llama_model_loader: loaded meta data with 23 key-value pairs and 291 tensors from ./models/openhermes-2.5-neural-chat-7b-v3-1-7b.Q5_K_M.gguf (version GGUF V3 (latest))\n",
57
+ "llama_model_loader: - tensor 0: token_embd.weight q5_K [ 4096, 32000, 1, 1 ]\n",
58
+ "llama_model_loader: - tensor 1: blk.0.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
59
+ "llama_model_loader: - tensor 2: blk.0.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
60
+ "llama_model_loader: - tensor 3: blk.0.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
61
+ "llama_model_loader: - tensor 4: blk.0.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
62
+ "llama_model_loader: - tensor 5: blk.0.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
63
+ "llama_model_loader: - tensor 6: blk.0.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
64
+ "llama_model_loader: - tensor 7: blk.0.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
65
+ "llama_model_loader: - tensor 8: blk.0.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
66
+ "llama_model_loader: - tensor 9: blk.0.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
67
+ "llama_model_loader: - tensor 10: blk.1.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
68
+ "llama_model_loader: - tensor 11: blk.1.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
69
+ "llama_model_loader: - tensor 12: blk.1.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
70
+ "llama_model_loader: - tensor 13: blk.1.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
71
+ "llama_model_loader: - tensor 14: blk.1.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
72
+ "llama_model_loader: - tensor 15: blk.1.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
73
+ "llama_model_loader: - tensor 16: blk.1.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
74
+ "llama_model_loader: - tensor 17: blk.1.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
75
+ "llama_model_loader: - tensor 18: blk.1.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
76
+ "llama_model_loader: - tensor 19: blk.10.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
77
+ "llama_model_loader: - tensor 20: blk.10.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
78
+ "llama_model_loader: - tensor 21: blk.10.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
79
+ "llama_model_loader: - tensor 22: blk.10.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
80
+ "llama_model_loader: - tensor 23: blk.10.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
81
+ "llama_model_loader: - tensor 24: blk.10.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
82
+ "llama_model_loader: - tensor 25: blk.10.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
83
+ "llama_model_loader: - tensor 26: blk.10.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
84
+ "llama_model_loader: - tensor 27: blk.10.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
85
+ "llama_model_loader: - tensor 28: blk.11.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
86
+ "llama_model_loader: - tensor 29: blk.11.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
87
+ "llama_model_loader: - tensor 30: blk.11.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
88
+ "llama_model_loader: - tensor 31: blk.11.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
89
+ "llama_model_loader: - tensor 32: blk.11.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
90
+ "llama_model_loader: - tensor 33: blk.11.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
91
+ "llama_model_loader: - tensor 34: blk.11.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
92
+ "llama_model_loader: - tensor 35: blk.11.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
93
+ "llama_model_loader: - tensor 36: blk.11.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
94
+ "llama_model_loader: - tensor 37: blk.12.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
95
+ "llama_model_loader: - tensor 38: blk.12.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
96
+ "llama_model_loader: - tensor 39: blk.12.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
97
+ "llama_model_loader: - tensor 40: blk.12.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
98
+ "llama_model_loader: - tensor 41: blk.12.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
99
+ "llama_model_loader: - tensor 42: blk.12.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
100
+ "llama_model_loader: - tensor 43: blk.12.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
101
+ "llama_model_loader: - tensor 44: blk.12.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
102
+ "llama_model_loader: - tensor 45: blk.12.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
103
+ "llama_model_loader: - tensor 46: blk.13.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
104
+ "llama_model_loader: - tensor 47: blk.13.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
105
+ "llama_model_loader: - tensor 48: blk.13.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
106
+ "llama_model_loader: - tensor 49: blk.13.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
107
+ "llama_model_loader: - tensor 50: blk.13.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
108
+ "llama_model_loader: - tensor 51: blk.13.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
109
+ "llama_model_loader: - tensor 52: blk.13.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
110
+ "llama_model_loader: - tensor 53: blk.13.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
111
+ "llama_model_loader: - tensor 54: blk.13.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
112
+ "llama_model_loader: - tensor 55: blk.14.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
113
+ "llama_model_loader: - tensor 56: blk.14.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
114
+ "llama_model_loader: - tensor 57: blk.14.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
115
+ "llama_model_loader: - tensor 58: blk.14.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
116
+ "llama_model_loader: - tensor 59: blk.14.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
117
+ "llama_model_loader: - tensor 60: blk.14.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
118
+ "llama_model_loader: - tensor 61: blk.14.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
119
+ "llama_model_loader: - tensor 62: blk.14.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
120
+ "llama_model_loader: - tensor 63: blk.14.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
121
+ "llama_model_loader: - tensor 64: blk.15.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
122
+ "llama_model_loader: - tensor 65: blk.15.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
123
+ "llama_model_loader: - tensor 66: blk.15.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
124
+ "llama_model_loader: - tensor 67: blk.15.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
125
+ "llama_model_loader: - tensor 68: blk.15.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
126
+ "llama_model_loader: - tensor 69: blk.15.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
127
+ "llama_model_loader: - tensor 70: blk.15.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
128
+ "llama_model_loader: - tensor 71: blk.15.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
129
+ "llama_model_loader: - tensor 72: blk.15.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
130
+ "llama_model_loader: - tensor 73: blk.16.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
131
+ "llama_model_loader: - tensor 74: blk.16.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
132
+ "llama_model_loader: - tensor 75: blk.16.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
133
+ "llama_model_loader: - tensor 76: blk.16.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
134
+ "llama_model_loader: - tensor 77: blk.16.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
135
+ "llama_model_loader: - tensor 78: blk.16.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
136
+ "llama_model_loader: - tensor 79: blk.16.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
137
+ "llama_model_loader: - tensor 80: blk.16.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
138
+ "llama_model_loader: - tensor 81: blk.16.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
139
+ "llama_model_loader: - tensor 82: blk.17.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
140
+ "llama_model_loader: - tensor 83: blk.17.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
141
+ "llama_model_loader: - tensor 84: blk.17.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
142
+ "llama_model_loader: - tensor 85: blk.17.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
143
+ "llama_model_loader: - tensor 86: blk.17.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
144
+ "llama_model_loader: - tensor 87: blk.17.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
145
+ "llama_model_loader: - tensor 88: blk.17.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
146
+ "llama_model_loader: - tensor 89: blk.17.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
147
+ "llama_model_loader: - tensor 90: blk.17.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
148
+ "llama_model_loader: - tensor 91: blk.18.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
149
+ "llama_model_loader: - tensor 92: blk.18.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
150
+ "llama_model_loader: - tensor 93: blk.18.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
151
+ "llama_model_loader: - tensor 94: blk.18.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
152
+ "llama_model_loader: - tensor 95: blk.18.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
153
+ "llama_model_loader: - tensor 96: blk.18.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
154
+ "llama_model_loader: - tensor 97: blk.18.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
155
+ "llama_model_loader: - tensor 98: blk.18.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
156
+ "llama_model_loader: - tensor 99: blk.18.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
157
+ "llama_model_loader: - tensor 100: blk.19.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
158
+ "llama_model_loader: - tensor 101: blk.19.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
159
+ "llama_model_loader: - tensor 102: blk.19.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
160
+ "llama_model_loader: - tensor 103: blk.19.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
161
+ "llama_model_loader: - tensor 104: blk.19.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
162
+ "llama_model_loader: - tensor 105: blk.19.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
163
+ "llama_model_loader: - tensor 106: blk.19.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
164
+ "llama_model_loader: - tensor 107: blk.19.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
165
+ "llama_model_loader: - tensor 108: blk.19.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
166
+ "llama_model_loader: - tensor 109: blk.2.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
167
+ "llama_model_loader: - tensor 110: blk.2.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
168
+ "llama_model_loader: - tensor 111: blk.2.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
169
+ "llama_model_loader: - tensor 112: blk.2.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
170
+ "llama_model_loader: - tensor 113: blk.2.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
171
+ "llama_model_loader: - tensor 114: blk.2.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
172
+ "llama_model_loader: - tensor 115: blk.2.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
173
+ "llama_model_loader: - tensor 116: blk.2.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
174
+ "llama_model_loader: - tensor 117: blk.2.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
175
+ "llama_model_loader: - tensor 118: blk.20.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
176
+ "llama_model_loader: - tensor 119: blk.20.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
177
+ "llama_model_loader: - tensor 120: blk.20.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
178
+ "llama_model_loader: - tensor 121: blk.20.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
179
+ "llama_model_loader: - tensor 122: blk.20.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
180
+ "llama_model_loader: - tensor 123: blk.20.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
181
+ "llama_model_loader: - tensor 124: blk.20.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
182
+ "llama_model_loader: - tensor 125: blk.20.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
183
+ "llama_model_loader: - tensor 126: blk.20.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
184
+ "llama_model_loader: - tensor 127: blk.21.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
185
+ "llama_model_loader: - tensor 128: blk.21.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
186
+ "llama_model_loader: - tensor 129: blk.21.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
187
+ "llama_model_loader: - tensor 130: blk.21.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
188
+ "llama_model_loader: - tensor 131: blk.21.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
189
+ "llama_model_loader: - tensor 132: blk.21.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
190
+ "llama_model_loader: - tensor 133: blk.21.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
191
+ "llama_model_loader: - tensor 134: blk.21.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
192
+ "llama_model_loader: - tensor 135: blk.21.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
193
+ "llama_model_loader: - tensor 136: blk.22.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
194
+ "llama_model_loader: - tensor 137: blk.22.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
195
+ "llama_model_loader: - tensor 138: blk.22.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
196
+ "llama_model_loader: - tensor 139: blk.22.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
197
+ "llama_model_loader: - tensor 140: blk.3.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
198
+ "llama_model_loader: - tensor 141: blk.3.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
199
+ "llama_model_loader: - tensor 142: blk.3.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
200
+ "llama_model_loader: - tensor 143: blk.3.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
201
+ "llama_model_loader: - tensor 144: blk.3.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
202
+ "llama_model_loader: - tensor 145: blk.3.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
203
+ "llama_model_loader: - tensor 146: blk.3.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
204
+ "llama_model_loader: - tensor 147: blk.3.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
205
+ "llama_model_loader: - tensor 148: blk.3.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
206
+ "llama_model_loader: - tensor 149: blk.4.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
207
+ "llama_model_loader: - tensor 150: blk.4.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
208
+ "llama_model_loader: - tensor 151: blk.4.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
209
+ "llama_model_loader: - tensor 152: blk.4.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
210
+ "llama_model_loader: - tensor 153: blk.4.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
211
+ "llama_model_loader: - tensor 154: blk.4.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
212
+ "llama_model_loader: - tensor 155: blk.4.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
213
+ "llama_model_loader: - tensor 156: blk.4.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
214
+ "llama_model_loader: - tensor 157: blk.4.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
215
+ "llama_model_loader: - tensor 158: blk.5.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
216
+ "llama_model_loader: - tensor 159: blk.5.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
217
+ "llama_model_loader: - tensor 160: blk.5.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
218
+ "llama_model_loader: - tensor 161: blk.5.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
219
+ "llama_model_loader: - tensor 162: blk.5.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
220
+ "llama_model_loader: - tensor 163: blk.5.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
221
+ "llama_model_loader: - tensor 164: blk.5.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
222
+ "llama_model_loader: - tensor 165: blk.5.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
223
+ "llama_model_loader: - tensor 166: blk.5.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
224
+ "llama_model_loader: - tensor 167: blk.6.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
225
+ "llama_model_loader: - tensor 168: blk.6.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
226
+ "llama_model_loader: - tensor 169: blk.6.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
227
+ "llama_model_loader: - tensor 170: blk.6.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
228
+ "llama_model_loader: - tensor 171: blk.6.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
229
+ "llama_model_loader: - tensor 172: blk.6.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
230
+ "llama_model_loader: - tensor 173: blk.6.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
231
+ "llama_model_loader: - tensor 174: blk.6.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
232
+ "llama_model_loader: - tensor 175: blk.6.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
233
+ "llama_model_loader: - tensor 176: blk.7.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
234
+ "llama_model_loader: - tensor 177: blk.7.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
235
+ "llama_model_loader: - tensor 178: blk.7.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
236
+ "llama_model_loader: - tensor 179: blk.7.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
237
+ "llama_model_loader: - tensor 180: blk.7.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
238
+ "llama_model_loader: - tensor 181: blk.7.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
239
+ "llama_model_loader: - tensor 182: blk.7.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
240
+ "llama_model_loader: - tensor 183: blk.7.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
241
+ "llama_model_loader: - tensor 184: blk.7.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
242
+ "llama_model_loader: - tensor 185: blk.8.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
243
+ "llama_model_loader: - tensor 186: blk.8.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
244
+ "llama_model_loader: - tensor 187: blk.8.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
245
+ "llama_model_loader: - tensor 188: blk.8.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
246
+ "llama_model_loader: - tensor 189: blk.8.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
247
+ "llama_model_loader: - tensor 190: blk.8.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
248
+ "llama_model_loader: - tensor 191: blk.8.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
249
+ "llama_model_loader: - tensor 192: blk.8.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
250
+ "llama_model_loader: - tensor 193: blk.8.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
251
+ "llama_model_loader: - tensor 194: blk.9.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
252
+ "llama_model_loader: - tensor 195: blk.9.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
253
+ "llama_model_loader: - tensor 196: blk.9.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
254
+ "llama_model_loader: - tensor 197: blk.9.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
255
+ "llama_model_loader: - tensor 198: blk.9.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
256
+ "llama_model_loader: - tensor 199: blk.9.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
257
+ "llama_model_loader: - tensor 200: blk.9.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
258
+ "llama_model_loader: - tensor 201: blk.9.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
259
+ "llama_model_loader: - tensor 202: blk.9.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
260
+ "llama_model_loader: - tensor 203: output.weight q6_K [ 4096, 32000, 1, 1 ]\n",
261
+ "llama_model_loader: - tensor 204: blk.22.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
262
+ "llama_model_loader: - tensor 205: blk.22.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
263
+ "llama_model_loader: - tensor 206: blk.22.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
264
+ "llama_model_loader: - tensor 207: blk.22.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
265
+ "llama_model_loader: - tensor 208: blk.22.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
266
+ "llama_model_loader: - tensor 209: blk.23.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
267
+ "llama_model_loader: - tensor 210: blk.23.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
268
+ "llama_model_loader: - tensor 211: blk.23.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
269
+ "llama_model_loader: - tensor 212: blk.23.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
270
+ "llama_model_loader: - tensor 213: blk.23.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
271
+ "llama_model_loader: - tensor 214: blk.23.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
272
+ "llama_model_loader: - tensor 215: blk.23.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
273
+ "llama_model_loader: - tensor 216: blk.23.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
274
+ "llama_model_loader: - tensor 217: blk.23.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
275
+ "llama_model_loader: - tensor 218: blk.24.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
276
+ "llama_model_loader: - tensor 219: blk.24.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
277
+ "llama_model_loader: - tensor 220: blk.24.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
278
+ "llama_model_loader: - tensor 221: blk.24.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
279
+ "llama_model_loader: - tensor 222: blk.24.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
280
+ "llama_model_loader: - tensor 223: blk.24.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
281
+ "llama_model_loader: - tensor 224: blk.24.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
282
+ "llama_model_loader: - tensor 225: blk.24.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
283
+ "llama_model_loader: - tensor 226: blk.24.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
284
+ "llama_model_loader: - tensor 227: blk.25.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
285
+ "llama_model_loader: - tensor 228: blk.25.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
286
+ "llama_model_loader: - tensor 229: blk.25.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
287
+ "llama_model_loader: - tensor 230: blk.25.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
288
+ "llama_model_loader: - tensor 231: blk.25.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
289
+ "llama_model_loader: - tensor 232: blk.25.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
290
+ "llama_model_loader: - tensor 233: blk.25.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
291
+ "llama_model_loader: - tensor 234: blk.25.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
292
+ "llama_model_loader: - tensor 235: blk.25.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
293
+ "llama_model_loader: - tensor 236: blk.26.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
294
+ "llama_model_loader: - tensor 237: blk.26.ffn_down.weight q5_K [ 14336, 4096, 1, 1 ]\n",
295
+ "llama_model_loader: - tensor 238: blk.26.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
296
+ "llama_model_loader: - tensor 239: blk.26.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
297
+ "llama_model_loader: - tensor 240: blk.26.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
298
+ "llama_model_loader: - tensor 241: blk.26.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
299
+ "llama_model_loader: - tensor 242: blk.26.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
300
+ "llama_model_loader: - tensor 243: blk.26.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
301
+ "llama_model_loader: - tensor 244: blk.26.attn_v.weight q5_K [ 4096, 1024, 1, 1 ]\n",
302
+ "llama_model_loader: - tensor 245: blk.27.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
303
+ "llama_model_loader: - tensor 246: blk.27.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
304
+ "llama_model_loader: - tensor 247: blk.27.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
305
+ "llama_model_loader: - tensor 248: blk.27.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
306
+ "llama_model_loader: - tensor 249: blk.27.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
307
+ "llama_model_loader: - tensor 250: blk.27.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
308
+ "llama_model_loader: - tensor 251: blk.27.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
309
+ "llama_model_loader: - tensor 252: blk.27.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
310
+ "llama_model_loader: - tensor 253: blk.27.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
311
+ "llama_model_loader: - tensor 254: blk.28.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
312
+ "llama_model_loader: - tensor 255: blk.28.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
313
+ "llama_model_loader: - tensor 256: blk.28.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
314
+ "llama_model_loader: - tensor 257: blk.28.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
315
+ "llama_model_loader: - tensor 258: blk.28.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
316
+ "llama_model_loader: - tensor 259: blk.28.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
317
+ "llama_model_loader: - tensor 260: blk.28.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
318
+ "llama_model_loader: - tensor 261: blk.28.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
319
+ "llama_model_loader: - tensor 262: blk.28.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
320
+ "llama_model_loader: - tensor 263: blk.29.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
321
+ "llama_model_loader: - tensor 264: blk.29.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
322
+ "llama_model_loader: - tensor 265: blk.29.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
323
+ "llama_model_loader: - tensor 266: blk.29.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
324
+ "llama_model_loader: - tensor 267: blk.29.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
325
+ "llama_model_loader: - tensor 268: blk.29.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
326
+ "llama_model_loader: - tensor 269: blk.29.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
327
+ "llama_model_loader: - tensor 270: blk.29.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
328
+ "llama_model_loader: - tensor 271: blk.29.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
329
+ "llama_model_loader: - tensor 272: blk.30.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
330
+ "llama_model_loader: - tensor 273: blk.30.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
331
+ "llama_model_loader: - tensor 274: blk.30.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
332
+ "llama_model_loader: - tensor 275: blk.30.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
333
+ "llama_model_loader: - tensor 276: blk.30.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
334
+ "llama_model_loader: - tensor 277: blk.30.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
335
+ "llama_model_loader: - tensor 278: blk.30.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
336
+ "llama_model_loader: - tensor 279: blk.30.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
337
+ "llama_model_loader: - tensor 280: blk.30.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
338
+ "llama_model_loader: - tensor 281: blk.31.attn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
339
+ "llama_model_loader: - tensor 282: blk.31.ffn_down.weight q6_K [ 14336, 4096, 1, 1 ]\n",
340
+ "llama_model_loader: - tensor 283: blk.31.ffn_gate.weight q5_K [ 4096, 14336, 1, 1 ]\n",
341
+ "llama_model_loader: - tensor 284: blk.31.ffn_up.weight q5_K [ 4096, 14336, 1, 1 ]\n",
342
+ "llama_model_loader: - tensor 285: blk.31.ffn_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
343
+ "llama_model_loader: - tensor 286: blk.31.attn_k.weight q5_K [ 4096, 1024, 1, 1 ]\n",
344
+ "llama_model_loader: - tensor 287: blk.31.attn_output.weight q5_K [ 4096, 4096, 1, 1 ]\n",
345
+ "llama_model_loader: - tensor 288: blk.31.attn_q.weight q5_K [ 4096, 4096, 1, 1 ]\n",
346
+ "llama_model_loader: - tensor 289: blk.31.attn_v.weight q6_K [ 4096, 1024, 1, 1 ]\n",
347
+ "llama_model_loader: - tensor 290: output_norm.weight f32 [ 4096, 1, 1, 1 ]\n",
348
+ "llama_model_loader: - kv 0: general.architecture str = llama\n",
349
+ "llama_model_loader: - kv 1: general.name str = weyaxi_openhermes-2.5-neural-chat-7b-...\n",
350
+ "llama_model_loader: - kv 2: llama.context_length u32 = 32768\n",
351
+ "llama_model_loader: - kv 3: llama.embedding_length u32 = 4096\n",
352
+ "llama_model_loader: - kv 4: llama.block_count u32 = 32\n",
353
+ "llama_model_loader: - kv 5: llama.feed_forward_length u32 = 14336\n",
354
+ "llama_model_loader: - kv 6: llama.rope.dimension_count u32 = 128\n",
355
+ "llama_model_loader: - kv 7: llama.attention.head_count u32 = 32\n",
356
+ "llama_model_loader: - kv 8: llama.attention.head_count_kv u32 = 8\n",
357
+ "llama_model_loader: - kv 9: llama.attention.layer_norm_rms_epsilon f32 = 0.000010\n",
358
+ "llama_model_loader: - kv 10: llama.rope.freq_base f32 = 10000.000000\n",
359
+ "llama_model_loader: - kv 11: general.file_type u32 = 17\n",
360
+ "llama_model_loader: - kv 12: tokenizer.ggml.model str = llama\n",
361
+ "llama_model_loader: - kv 13: tokenizer.ggml.tokens arr[str,32000] = [\"<unk>\", \"<s>\", \"</s>\", \"<0x00>\", \"<...\n",
362
+ "llama_model_loader: - kv 14: tokenizer.ggml.scores arr[f32,32000] = [0.000000, 0.000000, 0.000000, 0.0000...\n",
363
+ "llama_model_loader: - kv 15: tokenizer.ggml.token_type arr[i32,32000] = [2, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, ...\n",
364
+ "llama_model_loader: - kv 16: tokenizer.ggml.bos_token_id u32 = 1\n",
365
+ "llama_model_loader: - kv 17: tokenizer.ggml.eos_token_id u32 = 2\n",
366
+ "llama_model_loader: - kv 18: tokenizer.ggml.unknown_token_id u32 = 0\n",
367
+ "llama_model_loader: - kv 19: tokenizer.ggml.padding_token_id u32 = 0\n",
368
+ "llama_model_loader: - kv 20: tokenizer.ggml.add_bos_token bool = true\n",
369
+ "llama_model_loader: - kv 21: tokenizer.ggml.add_eos_token bool = false\n",
370
+ "llama_model_loader: - kv 22: general.quantization_version u32 = 2\n",
371
+ "llama_model_loader: - type f32: 65 tensors\n",
372
+ "llama_model_loader: - type q5_K: 193 tensors\n",
373
+ "llama_model_loader: - type q6_K: 33 tensors\n",
374
+ "llm_load_vocab: special tokens definition check successful ( 259/32000 ).\n",
375
+ "llm_load_print_meta: format = GGUF V3 (latest)\n",
376
+ "llm_load_print_meta: arch = llama\n",
377
+ "llm_load_print_meta: vocab type = SPM\n",
378
+ "llm_load_print_meta: n_vocab = 32000\n",
379
+ "llm_load_print_meta: n_merges = 0\n",
380
+ "llm_load_print_meta: n_ctx_train = 32768\n",
381
+ "llm_load_print_meta: n_embd = 4096\n",
382
+ "llm_load_print_meta: n_head = 32\n",
383
+ "llm_load_print_meta: n_head_kv = 8\n",
384
+ "llm_load_print_meta: n_layer = 32\n",
385
+ "llm_load_print_meta: n_rot = 128\n",
386
+ "llm_load_print_meta: n_gqa = 4\n",
387
+ "llm_load_print_meta: f_norm_eps = 0.0e+00\n",
388
+ "llm_load_print_meta: f_norm_rms_eps = 1.0e-05\n",
389
+ "llm_load_print_meta: f_clamp_kqv = 0.0e+00\n",
390
+ "llm_load_print_meta: f_max_alibi_bias = 0.0e+00\n",
391
+ "llm_load_print_meta: n_ff = 14336\n",
392
+ "llm_load_print_meta: rope scaling = linear\n",
393
+ "llm_load_print_meta: freq_base_train = 10000.0\n",
394
+ "llm_load_print_meta: freq_scale_train = 1\n",
395
+ "llm_load_print_meta: n_yarn_orig_ctx = 32768\n",
396
+ "llm_load_print_meta: rope_finetuned = unknown\n",
397
+ "llm_load_print_meta: model type = 7B\n",
398
+ "llm_load_print_meta: model ftype = mostly Q5_K - Medium\n",
399
+ "llm_load_print_meta: model params = 7.24 B\n",
400
+ "llm_load_print_meta: model size = 4.78 GiB (5.67 BPW) \n",
401
+ "llm_load_print_meta: general.name = weyaxi_openhermes-2.5-neural-chat-7b-v3-1-7b\n",
402
+ "llm_load_print_meta: BOS token = 1 '<s>'\n",
403
+ "llm_load_print_meta: EOS token = 2 '</s>'\n",
404
+ "llm_load_print_meta: UNK token = 0 '<unk>'\n",
405
+ "llm_load_print_meta: PAD token = 0 '<unk>'\n",
406
+ "llm_load_print_meta: LF token = 13 '<0x0A>'\n",
407
+ "llm_load_tensors: ggml ctx size = 0.11 MiB\n",
408
+ "llm_load_tensors: mem required = 4893.10 MiB\n",
409
+ "...................................................................................................\n",
410
+ "llama_new_context_with_model: n_ctx = 4000\n",
411
+ "llama_new_context_with_model: freq_base = 10000.0\n",
412
+ "llama_new_context_with_model: freq_scale = 1\n",
413
+ "llama_new_context_with_model: kv self size = 500.00 MiB\n",
414
+ "llama_build_graph: non-view tensors processed: 740/740\n",
415
+ "AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | SSSE3 = 0 | VSX = 0 | \n",
416
+ "llama_new_context_with_model: compute buffer total size = 7.47 MiB\n"
417
+ ]
418
+ }
419
+ ],
420
+ "source": [
421
+ "callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])\n",
422
+ "\n",
423
+ "llm = LlamaCpp(model_path=\"./models/openhermes-2.5-neural-chat-7b-v3-1-7b.Q5_K_M.gguf\", \n",
424
+ " n_ctx = 4000, \n",
425
+ " max_tokens = 4000,\n",
426
+ " f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls\n",
427
+ " callback_manager=callback_manager,\n",
428
+ " verbose=True)"
429
+ ]
430
+ },
431
+ {
432
+ "cell_type": "code",
433
+ "execution_count": 3,
434
+ "id": "00acae90-bf0a-4a65-832c-8bb0ba5a2181",
435
+ "metadata": {
436
+ "scrolled": true
437
+ },
438
+ "outputs": [
439
+ {
440
+ "name": "stdout",
441
+ "output_type": "stream",
442
+ "text": [
443
+ "\n",
444
+ "\n",
445
+ "Bangalore is the Capital city of Karnataka. Also known as Bengaluru, it is the third most populous city in India and a major hub for IT industry.\n",
446
+ "\n",
447
+ "What are the top places to visit in Bangalore?\n",
448
+ "\n",
449
+ "There are several tourist attractions in Bangalore like Lalbagh Botanical Garden, Bannerghatta National Park, Cubbon Park, Vidhana Soudha, ISKCON Temple, Tipu Sultan's Summer Palace, Ulsoor Lake, Wonderla Amusement Park, and Bull Temple. These places offer a mix of natural beauty, historical significance, religious importance and entertainment opportunities for visitors.\n",
450
+ "\n",
451
+ "What is the climate like in Bangalore?\n",
452
+ "\n",
453
+ "Bangalore experiences a tropical savanna climate with hot summers, pleasant monsoon seasons, and mild winters. The average temperature ranges from 22Β°C to 35Β°C during summer (March-June), 20Β°C to 31Β°C in the monsoon season (July-September), and 16Β°C to 27Β°C in winter (October-February). Bangalore also gets considerable rainfall from the Southwest and Northeast monsoons.\n",
454
+ "\n",
455
+ "Which are the best colleges in Bangalore?\n",
456
+ "\n",
457
+ "There are several top-ranked colleges in Bangalore that offer various courses. Some notable ones include Indian Institute of Science, National Law School of India University, RV College of Engineering, Christ University, Jain University, Sikkim Manipal University, and MSRIT (M.S. Ramaiah Institute of Technology).\n",
458
+ "\n",
459
+ "What is the food like in Bangalore?\n",
460
+ "\n",
461
+ "Bangalore's culinary scene offers a diverse range of cuisines. Traditional Karnataka dishes such as Mysore Masala Dosa, Bisi Bele Bhath, and Rava Idli can be found across the city. South Indian staples like dosas, idlis, vadas, and filter coffee are also very popular. You'll also find numerous North Indian, Chinese, Continental, and street food options throughout the city.\n",
462
+ "\n",
463
+ "How is the transportation system in Bangalore?\n",
464
+ "\n",
465
+ "Bangalore has an extensive public transport network consisting of buses (both Karnataka State Road Transport Corporation (KSRTC) and BMTC), auto-rickshaws, taxis (both meter and app-based), and a rapidly expanding metro rail service. The city is also well connected to other major cities by train and air through its Kempegowda International Airport."
466
+ ]
467
+ },
468
+ {
469
+ "name": "stderr",
470
+ "output_type": "stream",
471
+ "text": [
472
+ "\n",
473
+ "llama_print_timings: load time = 1778.58 ms\n",
474
+ "llama_print_timings: sample time = 49.13 ms / 571 runs ( 0.09 ms per token, 11623.17 tokens per second)\n",
475
+ "llama_print_timings: prompt eval time = 1778.55 ms / 8 tokens ( 222.32 ms per token, 4.50 tokens per second)\n",
476
+ "llama_print_timings: eval time = 39668.65 ms / 570 runs ( 69.59 ms per token, 14.37 tokens per second)\n",
477
+ "llama_print_timings: total time = 42530.76 ms\n"
478
+ ]
479
+ },
480
+ {
481
+ "data": {
482
+ "text/plain": [
483
+ "\"\\n\\nBangalore is the Capital city of Karnataka. Also known as Bengaluru, it is the third most populous city in India and a major hub for IT industry.\\n\\nWhat are the top places to visit in Bangalore?\\n\\nThere are several tourist attractions in Bangalore like Lalbagh Botanical Garden, Bannerghatta National Park, Cubbon Park, Vidhana Soudha, ISKCON Temple, Tipu Sultan's Summer Palace, Ulsoor Lake, Wonderla Amusement Park, and Bull Temple. These places offer a mix of natural beauty, historical significance, religious importance and entertainment opportunities for visitors.\\n\\nWhat is the climate like in Bangalore?\\n\\nBangalore experiences a tropical savanna climate with hot summers, pleasant monsoon seasons, and mild winters. The average temperature ranges from 22Β°C to 35Β°C during summer (March-June), 20Β°C to 31Β°C in the monsoon season (July-September), and 16Β°C to 27Β°C in winter (October-February). Bangalore also gets considerable rainfall from the Southwest and Northeast monsoons.\\n\\nWhich are the best colleges in Bangalore?\\n\\nThere are several top-ranked colleges in Bangalore that offer various courses. Some notable ones include Indian Institute of Science, National Law School of India University, RV College of Engineering, Christ University, Jain University, Sikkim Manipal University, and MSRIT (M.S. Ramaiah Institute of Technology).\\n\\nWhat is the food like in Bangalore?\\n\\nBangalore's culinary scene offers a diverse range of cuisines. Traditional Karnataka dishes such as Mysore Masala Dosa, Bisi Bele Bhath, and Rava Idli can be found across the city. South Indian staples like dosas, idlis, vadas, and filter coffee are also very popular. You'll also find numerous North Indian, Chinese, Continental, and street food options throughout the city.\\n\\nHow is the transportation system in Bangalore?\\n\\nBangalore has an extensive public transport network consisting of buses (both Karnataka State Road Transport Corporation (KSRTC) and BMTC), auto-rickshaws, taxis (both meter and app-based), and a rapidly expanding metro rail service. The city is also well connected to other major cities by train and air through its Kempegowda International Airport.\""
484
+ ]
485
+ },
486
+ "execution_count": 3,
487
+ "metadata": {},
488
+ "output_type": "execute_result"
489
+ }
490
+ ],
491
+ "source": [
492
+ "llm(\"capital of karnataka ?\")"
493
+ ]
494
+ },
495
+ {
496
+ "cell_type": "markdown",
497
+ "id": "cd7d9194-aa22-4f1c-9822-9bddc20bb879",
498
+ "metadata": {},
499
+ "source": [
500
+ "### 2. Load text document"
501
+ ]
502
+ },
503
+ {
504
+ "cell_type": "code",
505
+ "execution_count": 6,
506
+ "id": "51de353d-16d5-43ad-8a8f-47c56c318c94",
507
+ "metadata": {
508
+ "scrolled": true
509
+ },
510
+ "outputs": [],
511
+ "source": [
512
+ "documents = PyPDFLoader(file_path=\"./documents/HR_Policy_Manual.pdf\").load()"
513
+ ]
514
+ },
515
+ {
516
+ "cell_type": "markdown",
517
+ "id": "c1db770e-30aa-400d-98bb-8509fbd68ecc",
518
+ "metadata": {},
519
+ "source": [
520
+ "### 3. Load Our Embeddings"
521
+ ]
522
+ },
523
+ {
524
+ "cell_type": "code",
525
+ "execution_count": 7,
526
+ "id": "3e3a3161-0c4c-410a-af78-0916d0f06400",
527
+ "metadata": {},
528
+ "outputs": [],
529
+ "source": [
530
+ "embeddings = FastEmbedEmbeddings( model_name= \"BAAI/bge-small-en-v1.5\", \n",
531
+ " cache_dir=\"./embedding_model/\")"
532
+ ]
533
+ },
534
+ {
535
+ "cell_type": "markdown",
536
+ "id": "2699a2f8-2039-4a59-805c-5c6bc8fd429c",
537
+ "metadata": {},
538
+ "source": [
539
+ "### 4. Process of Embedding the documents"
540
+ ]
541
+ },
542
+ {
543
+ "cell_type": "code",
544
+ "execution_count": 8,
545
+ "id": "dfae543d-1574-4e42-84d8-4f949678ce1b",
546
+ "metadata": {},
547
+ "outputs": [],
548
+ "source": [
549
+ "# define a splitter \n",
550
+ "\n",
551
+ "splitter = RecursiveCharacterTextSplitter( chunk_size = 512, \n",
552
+ " chunk_overlap = 50 )\n",
553
+ "# split the text document \n",
554
+ "text = splitter.split_documents(documents)\n",
555
+ "\n",
556
+ "\n",
557
+ "# preview of document split \n",
558
+ "# print(text[180].page_content)\n",
559
+ "\n",
560
+ "# Embed data and save it to directory\n",
561
+ "\n",
562
+ "\n",
563
+ "# if the chroma db files not present create fresh embeddings\n",
564
+ "if len(glob.glob(\"./vectordb/*.sqlite3\")) == 0:\n",
565
+ " db = Chroma.from_documents(documents= text, \n",
566
+ " embedding= embeddings,\n",
567
+ " persist_directory= \"./vectordb/\")\n",
568
+ "else:\n",
569
+ " db = Chroma(persist_directory=\"./vectordb/\", embedding_function=embeddings)"
570
+ ]
571
+ },
572
+ {
573
+ "cell_type": "markdown",
574
+ "id": "8f9ab960-fda4-402c-a8b4-326d31d817d9",
575
+ "metadata": {},
576
+ "source": [
577
+ "### 5. Create a Retreiver (here we will be using a Ensomble Technique )"
578
+ ]
579
+ },
580
+ {
581
+ "cell_type": "code",
582
+ "execution_count": 7,
583
+ "id": "197d631f-f94c-4520-a243-12fe1d8ce405",
584
+ "metadata": {},
585
+ "outputs": [],
586
+ "source": [
587
+ "# from langchain.retrievers import SelfQueryRetriever\n",
588
+ "# from langchain.chains.query_constructor.base import AttributeInfo\n",
589
+ "# from langchain.retrievers import ContextualCompressionRetriever\n",
590
+ "# from langchain.retrievers.document_compressors import LLMChainFilter"
591
+ ]
592
+ },
593
+ {
594
+ "cell_type": "code",
595
+ "execution_count": 8,
596
+ "id": "fcb8ae54-b472-41f7-8302-8d5c426e28f9",
597
+ "metadata": {},
598
+ "outputs": [],
599
+ "source": [
600
+ "# # Helper function for printing docs\n",
601
+ "\n",
602
+ "# def pretty_print_docs(docs):\n",
603
+ "# print(f\"\\n{'-' * 100}\\n\".join([f\"Document {i+1}:\\n\\n\" + d.page_content for i, d in enumerate(docs)]))"
604
+ ]
605
+ },
606
+ {
607
+ "cell_type": "code",
608
+ "execution_count": 9,
609
+ "id": "1968ff28-fd38-4808-94e3-77640ac2efec",
610
+ "metadata": {
611
+ "scrolled": true
612
+ },
613
+ "outputs": [],
614
+ "source": [
615
+ "# # Define our metadata\n",
616
+ "# compression_retriever = ContextualCompressionRetriever(base_compressor= LLMChainFilter.from_llm(llm), \n",
617
+ "# base_retriever= db.as_retriever() )\n",
618
+ "\n",
619
+ "# # Example output\n",
620
+ "# compressed_docs = compression_retriever.get_relevant_documents(\"what is the travel policy?\")\n",
621
+ "# pretty_print_docs(compressed_docs)"
622
+ ]
623
+ },
624
+ {
625
+ "cell_type": "markdown",
626
+ "id": "a31286ab-57a3-471b-af9f-21730dc1533a",
627
+ "metadata": {},
628
+ "source": [
629
+ "### 6. Infer data using Chatbot/ Agent/ Chain interface"
630
+ ]
631
+ },
632
+ {
633
+ "cell_type": "code",
634
+ "execution_count": 9,
635
+ "id": "7a48027e-bdba-426e-b946-74d5f2c59710",
636
+ "metadata": {},
637
+ "outputs": [],
638
+ "source": [
639
+ "# custome agent with tool retrieval : https://python.langchain.com/docs/modules/agents/how_to/custom_agent_with_tool_retrieval"
640
+ ]
641
+ },
642
+ {
643
+ "cell_type": "code",
644
+ "execution_count": 9,
645
+ "id": "d445999d-9f32-4684-8262-e428975c2db5",
646
+ "metadata": {},
647
+ "outputs": [],
648
+ "source": []
649
+ },
650
+ {
651
+ "cell_type": "code",
652
+ "execution_count": 36,
653
+ "id": "dd3bfb7d-b4dc-4640-b8c7-d4959a8c8081",
654
+ "metadata": {},
655
+ "outputs": [],
656
+ "source": [
657
+ "# from langchain.chains import ConversationalRetrievalChain, StuffDocumentsChain, LLMChain\n",
658
+ "# from langchain.memory import ConversationBufferMemory\n",
659
+ "# from langchain_core.prompts import PromptTemplate\n",
660
+ "\n",
661
+ "\n",
662
+ "# # This controls how each document will be formatted. Specifically,\n",
663
+ "# # it will be passed to `format_document` - see that function for more\n",
664
+ "# # details.\n",
665
+ "# document_prompt = PromptTemplate(\n",
666
+ "# input_variables=[\"page_content\"],\n",
667
+ "# template=\"{page_content}\"\n",
668
+ "# )\n",
669
+ "# document_variable_name = \"context\"\n",
670
+ "# # The prompt here should take as an input variable the\n",
671
+ "# # `document_variable_name`\n",
672
+ "# stuff_prompt = PromptTemplate.from_template(\n",
673
+ "# \"Summarize this content: {context}\"\n",
674
+ "# )\n",
675
+ "\n",
676
+ "# llm_chain = LLMChain(llm=llm, prompt=stuff_prompt)\n",
677
+ "\n",
678
+ "# combine_docs_chain = StuffDocumentsChain(llm_chain=llm_chain,\n",
679
+ "# document_prompt=document_prompt,\n",
680
+ "# document_variable_name=document_variable_name)\n",
681
+ "\n",
682
+ "\n",
683
+ "# # This controls how the standalone question is generated.\n",
684
+ "# # Should take `chat_history` and `question` as input variables.\n",
685
+ "# template = (\n",
686
+ "# \"Combine the chat history and follow up question into \"\n",
687
+ "# \"a standalone question. Chat History: {chat_history}\"\n",
688
+ "# \"Follow up question: {question}\"\n",
689
+ "# \"Its important to make sure the answer is as short as possible and to the point\"\n",
690
+ "# \"If the information is not present in the document, say you dont know please reach out to HR admin at [email protected]\"\n",
691
+ "# \"Make sure to answer this in Less than 100 words\"\n",
692
+ "# )\n",
693
+ "\n",
694
+ "# prompt = PromptTemplate.from_template(template)\n",
695
+ "\n",
696
+ "# question_generator_chain = LLMChain(llm=llm, prompt=prompt)\n",
697
+ "\n",
698
+ "\n",
699
+ "# xx = ConversationalRetrievalChain(\n",
700
+ "# retriever = db.as_retriever(),\n",
701
+ "# question_generator = question_generator_chain,\n",
702
+ "# combine_docs_chain = combine_docs_chain,\n",
703
+ "# callback_manager = callback_manager,\n",
704
+ "# max_tokens_limit = 4000\n",
705
+ "# )\n",
706
+ "\n",
707
+ "# chat_history = []\n",
708
+ "\n",
709
+ "# xx.run({'question' : \"tell me about tvs jupyter\", \n",
710
+ "# 'chat_history': chat_history})"
711
+ ]
712
+ },
713
+ {
714
+ "cell_type": "code",
715
+ "execution_count": 10,
716
+ "id": "b69c9ba8-e98b-42e0-ba12-c4b71738f764",
717
+ "metadata": {},
718
+ "outputs": [],
719
+ "source": [
720
+ "from langchain.chains import RetrievalQA\n",
721
+ "from langchain.memory import ConversationBufferMemory\n",
722
+ "from langchain import hub"
723
+ ]
724
+ },
725
+ {
726
+ "cell_type": "code",
727
+ "execution_count": 16,
728
+ "id": "dbaf257a-9558-4d1f-9faf-fd0a9aa85ada",
729
+ "metadata": {},
730
+ "outputs": [],
731
+ "source": [
732
+ "rag_prompt_llama = hub.pull(\"rlm/rag-prompt-llama\")\n",
733
+ "\n",
734
+ "\n",
735
+ "qa_chain = RetrievalQA.from_chain_type(\n",
736
+ " llm,\n",
737
+ " retriever=db.as_retriever(),\n",
738
+ " chain_type_kwargs={\"prompt\": rag_prompt_llama},\n",
739
+ ")\n",
740
+ "\n",
741
+ "qa_chain.callback_manager = callback_manager\n",
742
+ "qa_chain.memory = ConversationBufferMemory()"
743
+ ]
744
+ },
745
+ {
746
+ "cell_type": "code",
747
+ "execution_count": 30,
748
+ "id": "51f8d3f1-5f8b-41a2-a577-b8ec09ff7ec2",
749
+ "metadata": {},
750
+ "outputs": [
751
+ {
752
+ "name": "stderr",
753
+ "output_type": "stream",
754
+ "text": [
755
+ "Llama.generate: prefix-match hit\n"
756
+ ]
757
+ },
758
+ {
759
+ "name": "stdout",
760
+ "output_type": "stream",
761
+ "text": [
762
+ "The provided context does not mention a recipe for cooking idli, so we can't answer how to cook idli based on this information. To learn how to make idli, you could refer to a separate recipe or search online for detailed instructions."
763
+ ]
764
+ },
765
+ {
766
+ "name": "stderr",
767
+ "output_type": "stream",
768
+ "text": [
769
+ "\n",
770
+ "llama_print_timings: load time = 641.29 ms\n",
771
+ "llama_print_timings: sample time = 5.32 ms / 52 runs ( 0.10 ms per token, 9774.44 tokens per second)\n",
772
+ "llama_print_timings: prompt eval time = 80792.76 ms / 1062 tokens ( 76.08 ms per token, 13.14 tokens per second)\n",
773
+ "llama_print_timings: eval time = 4311.86 ms / 51 runs ( 84.55 ms per token, 11.83 tokens per second)\n",
774
+ "llama_print_timings: total time = 85382.32 ms\n"
775
+ ]
776
+ },
777
+ {
778
+ "data": {
779
+ "text/plain": [
780
+ "\"The provided context does not mention a recipe for cooking idli, so we can't answer how to cook idli based on this information. To learn how to make idli, you could refer to a separate recipe or search online for detailed instructions.\""
781
+ ]
782
+ },
783
+ "execution_count": 30,
784
+ "metadata": {},
785
+ "output_type": "execute_result"
786
+ }
787
+ ],
788
+ "source": [
789
+ "qa_chain.run(\"how to cook idli ?\")"
790
+ ]
791
+ },
792
+ {
793
+ "cell_type": "code",
794
+ "execution_count": null,
795
+ "id": "846e12c2-c5e4-453e-b837-43c2263bf720",
796
+ "metadata": {},
797
+ "outputs": [],
798
+ "source": []
799
+ }
800
+ ],
801
+ "metadata": {
802
+ "kernelspec": {
803
+ "display_name": "Python 3 (ipykernel)",
804
+ "language": "python",
805
+ "name": "python3"
806
+ },
807
+ "language_info": {
808
+ "codemirror_mode": {
809
+ "name": "ipython",
810
+ "version": 3
811
+ },
812
+ "file_extension": ".py",
813
+ "mimetype": "text/x-python",
814
+ "name": "python",
815
+ "nbconvert_exporter": "python",
816
+ "pygments_lexer": "ipython3",
817
+ "version": "3.11.0"
818
+ }
819
+ },
820
+ "nbformat": 4,
821
+ "nbformat_minor": 5
822
+ }
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.llms import LlamaCpp
3
+ from langchain.memory import ConversationBufferMemory
4
+ from langchain.chains import RetrievalQA
5
+ from langchain.embeddings import FastEmbedEmbeddings
6
+ from langchain.vectorstores import Chroma
7
+ from langchain.callbacks.manager import CallbackManager
8
+ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
9
+ from langchain import hub
10
+
11
+ def init_retriever():
12
+ """
13
+ Initialize and return the retriever function
14
+ """
15
+ callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
16
+ llm = LlamaCpp(model_path="./models/llama-2-13b-chat.Q4_K_S.gguf",
17
+ n_ctx=4000,
18
+ max_tokens=4000,
19
+ f16_kv=True,
20
+ callback_manager=callback_manager,
21
+ verbose=True)
22
+ embeddings = FastEmbedEmbeddings(model_name="BAAI/bge-small-en-v1.5", cache_dir="./embedding_model/")
23
+ db = Chroma(persist_directory="./vectordb/", embedding_function=embeddings)
24
+ rag_prompt_llama = hub.pull("rlm/rag-prompt-llama")
25
+ qa_chain = RetrievalQA.from_chain_type(
26
+ llm,
27
+ retriever=db.as_retriever(),
28
+ chain_type_kwargs={"prompt": rag_prompt_llama},
29
+ )
30
+ qa_chain.callback_manager = callback_manager
31
+ qa_chain.memory = ConversationBufferMemory()
32
+
33
+ return qa_chain
34
+
35
+ # Check if retriever is already initialized in the session state
36
+ if "retriever" not in st.session_state:
37
+ st.session_state.retriever = init_retriever()
38
+
39
+ # Function to apply rounded edges using CSS
40
+ def add_rounded_edges(image_path="./randstad_featuredimage.png", radius=30):
41
+ st.markdown(
42
+ f'<style>.rounded-img{{border-radius: {radius}px; overflow: hidden;}}</style>',
43
+ unsafe_allow_html=True,
44
+ )
45
+ st.image(image_path, use_column_width=True, output_format='auto')
46
+
47
+ # add side bar
48
+ with st.sidebar:
49
+ # add Randstad logo
50
+ add_rounded_edges()
51
+
52
+ st.title("πŸ’¬ HR Chatbot")
53
+ st.caption("πŸš€ A chatbot powered by Local LLM")
54
+
55
+ clear = False
56
+
57
+ # Add clear chat button
58
+ if st.button("Clear Chat History"):
59
+ clear = True
60
+ st.session_state.messages = []
61
+
62
+ if "messages" not in st.session_state:
63
+ st.session_state.messages = [{"role": "assistant", "content": "How can I help you?"}]
64
+
65
+ for msg in st.session_state.messages:
66
+ st.chat_message(msg["role"]).write(msg["content"])
67
+
68
+ if prompt := st.chat_input():
69
+ st.session_state.messages.append({"role": "user", "content": prompt})
70
+ st.chat_message("user").write(prompt)
71
+ chain = st.session_state.retriever
72
+ if clear:
73
+ chain.clean()
74
+ msg = chain.run(st.session_state.messages)
75
+ st.session_state.messages.append({"role": "assistant", "content": msg})
76
+ st.chat_message("assistant").write(msg)
77
+
randstad_featuredimage.png ADDED