Commit
·
f29b1b5
1
Parent(s):
16429d2
feat: init project
Browse files
app.py
CHANGED
@@ -12,65 +12,49 @@ from llama_index.llms.llama_cpp.llama_utils import (
|
|
12 |
from llama_index.core.memory import ChatMemoryBuffer
|
13 |
import nltk
|
14 |
|
15 |
-
|
16 |
-
def import_documents():
|
17 |
-
urls = [
|
18 |
-
"https://www.zatsit.fr/",
|
19 |
-
"https://www.zatsit.fr/collaborer-avec-zatsit/",
|
20 |
-
"https://fr.linkedin.com/company/zatsit",
|
21 |
-
"https://www.zatsit.fr/contact/",
|
22 |
-
"https://blog.zatsit.fr/blog/green-exploitation-miniere",
|
23 |
-
"https://blog.zatsit.fr/blog/bundlephobia-reduire-javascript",
|
24 |
-
"https://blog.zatsit.fr/blog/gemini-vertex-ai",
|
25 |
-
"https://blog.zatsit.fr/blog/asyncapi-3-is-out",
|
26 |
-
"https://blog.zatsit.fr/blog/redpanda-introduction",
|
27 |
-
]
|
28 |
-
loader = UnstructuredURLLoader(urls=urls)
|
29 |
-
documents = loader.load_data()
|
30 |
-
return documents
|
31 |
-
|
32 |
-
|
33 |
-
def create_embed_model():
|
34 |
-
# create embed model from HuggingFace
|
35 |
-
return HuggingFaceEmbedding(model_name="thenlper/gte-large")
|
36 |
-
|
37 |
-
|
38 |
-
def create_store_index(documents, embed_model):
|
39 |
-
# create vector store index
|
40 |
-
return VectorStoreIndex.from_documents(documents, embed_model=embed_model)
|
41 |
-
|
42 |
-
|
43 |
-
def create_llm():
|
44 |
-
model_url = "https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-code-ft-GGUF/resolve/main/mistral-7b-instruct-v0.2-code-ft.Q2_K.gguf"
|
45 |
-
return LlamaCPP(
|
46 |
-
# You can pass in the URL to a GGML model to download it automatically
|
47 |
-
model_url=model_url,
|
48 |
-
# optionally, you can set the path to a pre-downloaded model instead of model_url
|
49 |
-
model_path=None,
|
50 |
-
temperature=0.1,
|
51 |
-
max_new_tokens=256,
|
52 |
-
# llama2 has a context window of 4096 tokens, but we set it lower to allow for some wiggle room
|
53 |
-
context_window=3900,
|
54 |
-
# kwargs to pass to __call__()
|
55 |
-
generate_kwargs={},
|
56 |
-
# kwargs to pass to __init__()
|
57 |
-
# set to at least 1 to use GPU
|
58 |
-
model_kwargs={"n_gpu_layers": 1},
|
59 |
-
# transform inputs into Llama2 format
|
60 |
-
messages_to_prompt=messages_to_prompt,
|
61 |
-
completion_to_prompt=completion_to_prompt,
|
62 |
-
verbose=True,
|
63 |
-
)
|
64 |
-
|
65 |
-
|
66 |
# download punkt
|
67 |
nltk.download('punkt')
|
68 |
nltk.download('punkt_tab')
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
|
76 |
def querying(query, history):
|
|
|
12 |
from llama_index.core.memory import ChatMemoryBuffer
|
13 |
import nltk
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# download punkt
|
16 |
nltk.download('punkt')
|
17 |
nltk.download('punkt_tab')
|
18 |
|
19 |
+
urls = [
|
20 |
+
"https://www.zatsit.fr/",
|
21 |
+
"https://www.zatsit.fr/collaborer-avec-zatsit/",
|
22 |
+
"https://fr.linkedin.com/company/zatsit",
|
23 |
+
"https://www.zatsit.fr/contact/",
|
24 |
+
"https://blog.zatsit.fr/blog/green-exploitation-miniere",
|
25 |
+
"https://blog.zatsit.fr/blog/bundlephobia-reduire-javascript",
|
26 |
+
"https://blog.zatsit.fr/blog/gemini-vertex-ai",
|
27 |
+
"https://blog.zatsit.fr/blog/asyncapi-3-is-out",
|
28 |
+
"https://blog.zatsit.fr/blog/redpanda-introduction",
|
29 |
+
]
|
30 |
+
loader = UnstructuredURLLoader(urls=urls)
|
31 |
+
documents = loader.load_data()
|
32 |
+
|
33 |
+
embed_model = HuggingFaceEmbedding(model_name="thenlper/gte-large")
|
34 |
+
|
35 |
+
# create vector store index
|
36 |
+
index = VectorStoreIndex.from_documents(documents, embed_model=embed_model)
|
37 |
+
|
38 |
+
model_url = "https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-code-ft-GGUF/resolve/main/mistral-7b-instruct-v0.2-code-ft.Q2_K.gguf"
|
39 |
+
llm = LlamaCPP(
|
40 |
+
# You can pass in the URL to a GGML model to download it automatically
|
41 |
+
model_url=model_url,
|
42 |
+
# optionally, you can set the path to a pre-downloaded model instead of model_url
|
43 |
+
model_path=None,
|
44 |
+
temperature=0.1,
|
45 |
+
max_new_tokens=256,
|
46 |
+
# llama2 has a context window of 4096 tokens, but we set it lower to allow for some wiggle room
|
47 |
+
context_window=3900,
|
48 |
+
# kwargs to pass to __call__()
|
49 |
+
generate_kwargs={},
|
50 |
+
# kwargs to pass to __init__()
|
51 |
+
# set to at least 1 to use GPU
|
52 |
+
model_kwargs={"n_gpu_layers": 1},
|
53 |
+
# transform inputs into Llama2 format
|
54 |
+
messages_to_prompt=messages_to_prompt,
|
55 |
+
completion_to_prompt=completion_to_prompt,
|
56 |
+
verbose=True,
|
57 |
+
)
|
58 |
|
59 |
|
60 |
def querying(query, history):
|