omarsol commited on
Commit
1fb6cc9
·
1 Parent(s): 292e4e7

Add Python Primer source to available sources and UI configuration

Browse files
Files changed (2) hide show
  1. scripts/main.py +3 -32
  2. scripts/setup.py +5 -75
scripts/main.py CHANGED
@@ -15,7 +15,7 @@ from llama_index.core.vector_stores import (
15
  )
16
  from llama_index.llms.openai import OpenAI
17
  from prompts import system_message_openai_agent
18
- from setup import ( # custom_retriever_langchain,; custom_retriever_llama_index,; custom_retriever_openai_cookbooks,; custom_retriever_peft,; custom_retriever_transformers,; custom_retriever_trl,
19
  AVAILABLE_SOURCES,
20
  AVAILABLE_SOURCES_UI,
21
  CONCURRENCY_COUNT,
@@ -26,36 +26,6 @@ from setup import ( # custom_retriever_langchain,; custom_retriever_llama_index
26
  def update_query_engine_tools(selected_sources) -> list[RetrieverTool]:
27
  tools = []
28
  source_mapping: dict[str, tuple[CustomRetriever, str, str]] = {
29
- # "Transformers Docs": (
30
- # custom_retriever_transformers,
31
- # "Transformers_information",
32
- # """Useful for general questions asking about the artificial intelligence (AI) field. Employ this tool to fetch information on topics such as language models (LLMs) models such as Llama3 and theory (transformer architectures), tips on prompting, quantization, etc.""",
33
- # ),
34
- # "PEFT Docs": (
35
- # custom_retriever_peft,
36
- # "PEFT_information",
37
- # """Useful for questions asking about efficient LLM fine-tuning. Employ this tool to fetch information on topics such as LoRA, QLoRA, etc.""",
38
- # ),
39
- # "TRL Docs": (
40
- # custom_retriever_trl,
41
- # "TRL_information",
42
- # """Useful for questions asking about fine-tuning LLMs with reinforcement learning (RLHF). Includes information about the Supervised Fine-tuning step (SFT), Reward Modeling step (RM), and the Proximal Policy Optimization (PPO) step.""",
43
- # ),
44
- # "LlamaIndex Docs": (
45
- # custom_retriever_llama_index,
46
- # "LlamaIndex_information",
47
- # """Useful for questions asking about retrieval augmented generation (RAG) with LLMs and embedding models. It is the documentation of a framework, includes info about fine-tuning embedding models, building chatbots, and agents with llms, using vector databases, embeddings, information retrieval with cosine similarity or bm25, etc.""",
48
- # ),
49
- # "OpenAI Cookbooks": (
50
- # custom_retriever_openai_cookbooks,
51
- # "openai_cookbooks_info",
52
- # """Useful for questions asking about accomplishing common tasks with the OpenAI API. Returns example code and guides stored in Jupyter notebooks, including info about ChatGPT GPT actions, OpenAI Assistants API, and How to fine-tune OpenAI's GPT-4o and GPT-4o-mini models with the OpenAI API.""",
53
- # ),
54
- # "LangChain Docs": (
55
- # custom_retriever_langchain,
56
- # "langchain_info",
57
- # """Useful for questions asking about the LangChain framework. It is the documentation of the LangChain framework, includes info about building chains, agents, and tools, using memory, prompts, callbacks, etc.""",
58
- # ),
59
  "All Sources": (
60
  custom_retriever_all_sources,
61
  "all_sources_info",
@@ -130,6 +100,7 @@ def generate_completion(
130
  "Towards AI Blog": "tai_blog",
131
  "8 Hour Primer": "8-hour_primer",
132
  "Advanced LLM Developer": "llm_developer",
 
133
  }
134
 
135
  for source in sources:
@@ -247,7 +218,7 @@ sources = gr.CheckboxGroup(
247
  "Towards AI Blog",
248
  "8 Hour Primer",
249
  "Advanced LLM Developer",
250
- # "All Sources",
251
  ],
252
  interactive=True,
253
  )
 
15
  )
16
  from llama_index.llms.openai import OpenAI
17
  from prompts import system_message_openai_agent
18
+ from setup import (
19
  AVAILABLE_SOURCES,
20
  AVAILABLE_SOURCES_UI,
21
  CONCURRENCY_COUNT,
 
26
  def update_query_engine_tools(selected_sources) -> list[RetrieverTool]:
27
  tools = []
28
  source_mapping: dict[str, tuple[CustomRetriever, str, str]] = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  "All Sources": (
30
  custom_retriever_all_sources,
31
  "all_sources_info",
 
100
  "Towards AI Blog": "tai_blog",
101
  "8 Hour Primer": "8-hour_primer",
102
  "Advanced LLM Developer": "llm_developer",
103
+ "Python Primer": "python_primer",
104
  }
105
 
106
  for source in sources:
 
218
  "Towards AI Blog",
219
  "8 Hour Primer",
220
  "Advanced LLM Developer",
221
+ "Python Primer",
222
  ],
223
  interactive=True,
224
  )
scripts/setup.py CHANGED
@@ -8,16 +8,10 @@ import chromadb
8
  import logfire
9
  from custom_retriever import CustomRetriever
10
  from dotenv import load_dotenv
11
- from llama_index.core import Document, SimpleKeywordTableIndex, VectorStoreIndex
12
- from llama_index.core.ingestion import IngestionPipeline
13
  from llama_index.core.node_parser import SentenceSplitter
14
- from llama_index.core.retrievers import (
15
- KeywordTableSimpleRetriever,
16
- VectorIndexRetriever,
17
- )
18
- from llama_index.core.schema import NodeWithScore, QueryBundle
19
  from llama_index.embeddings.cohere import CohereEmbedding
20
- from llama_index.embeddings.openai import OpenAIEmbedding
21
  from llama_index.vector_stores.chroma import ChromaVectorStore
22
  from utils import init_mongo_db
23
 
@@ -99,73 +93,15 @@ def setup_database(db_collection, dict_file_name) -> CustomRetriever:
99
  with open(f"data/{db_collection}/{dict_file_name}", "rb") as f:
100
  document_dict = pickle.load(f)
101
 
102
- # with open("data/keyword_retriever_sync.pkl", "rb") as f:
103
- # keyword_retriever: KeywordTableSimpleRetriever = pickle.load(f)
104
-
105
- # keyword_retriever.num_chunks_per_query = 15
106
-
107
- # # Creating the keyword index and retriever
108
- # logfire.info("Creating nodes from documents")
109
- # documents = create_docs("data/all_sources_data.jsonl")
110
- # pipeline = IngestionPipeline(
111
- # transformations=[SentenceSplitter(chunk_size=800, chunk_overlap=0)]
112
- # )
113
- # all_nodes = pipeline.run(documents=documents, show_progress=True)
114
- # # with open("data/all_nodes.pkl", "wb") as f:
115
- # # pickle.dump(all_nodes, f)
116
-
117
- # all_nodes = pickle.load(open("data/nodes_with_added_context.pkl", "rb"))
118
- # logfire.info(f"Number of nodes: {len(all_nodes)}")
119
-
120
- # keyword_index = SimpleKeywordTableIndex(
121
- # nodes=all_nodes, max_keywords_per_chunk=10, show_progress=True, use_async=False
122
- # )
123
- # # with open("data/keyword_index.pkl", "wb") as f:
124
- # # pickle.dump(keyword_index, f)
125
-
126
- # # keyword_index = pickle.load(open("data/keyword_index.pkl", "rb"))
127
-
128
- # logfire.info("Creating keyword retriever")
129
- # keyword_retriever = KeywordTableSimpleRetriever(index=keyword_index)
130
-
131
- # with open("data/keyword_retriever_sync.pkl", "wb") as f:
132
- # pickle.dump(keyword_retriever, f)
133
-
134
- # 'OR' Means both the vector nodes and the keyword nodes
135
- # return CustomRetriever(vector_retriever, document_dict, keyword_retriever, "OR")
136
  return CustomRetriever(vector_retriever, document_dict)
137
 
138
 
139
- # Setup retrievers
140
- # custom_retriever_transformers: CustomRetriever = setup_database(
141
- # "chroma-db-transformers",
142
- # "document_dict_transformers.pkl",
143
- # )
144
- # custom_retriever_peft: CustomRetriever = setup_database(
145
- # "chroma-db-peft", "document_dict_peft.pkl"
146
- # )
147
- # custom_retriever_trl: CustomRetriever = setup_database(
148
- # "chroma-db-trl", "document_dict_trl.pkl"
149
- # )
150
- # custom_retriever_llama_index: CustomRetriever = setup_database(
151
- # "chroma-db-llama_index",
152
- # "document_dict_llama_index.pkl",
153
- # )
154
- # custom_retriever_openai_cookbooks: CustomRetriever = setup_database(
155
- # "chroma-db-openai_cookbooks",
156
- # "document_dict_openai_cookbooks.pkl",
157
- # )
158
- # custom_retriever_langchain: CustomRetriever = setup_database(
159
- # "chroma-db-langchain",
160
- # "document_dict_langchain.pkl",
161
- # )
162
-
163
  custom_retriever_all_sources: CustomRetriever = setup_database(
164
  "chroma-db-all_sources",
165
  "document_dict_all_sources.pkl",
166
  )
167
 
168
- # Constants
169
  CONCURRENCY_COUNT = int(os.getenv("CONCURRENCY_COUNT", 64))
170
  MONGODB_URI = os.getenv("MONGODB_URI")
171
 
@@ -179,7 +115,7 @@ AVAILABLE_SOURCES_UI = [
179
  "Towards AI Blog",
180
  "8 Hour Primer",
181
  "Advanced LLM Developer",
182
- # "All Sources",
183
  ]
184
 
185
  AVAILABLE_SOURCES = [
@@ -192,7 +128,7 @@ AVAILABLE_SOURCES = [
192
  "tai_blog",
193
  "8-hour_primer",
194
  "llm_developer",
195
- # "all_sources",
196
  ]
197
 
198
  mongo_db = (
@@ -202,12 +138,6 @@ mongo_db = (
202
  )
203
 
204
  __all__ = [
205
- # "custom_retriever_transformers",
206
- # "custom_retriever_peft",
207
- # "custom_retriever_trl",
208
- # "custom_retriever_llama_index",
209
- # "custom_retriever_openai_cookbooks",
210
- # "custom_retriever_langchain",
211
  "custom_retriever_all_sources",
212
  "mongo_db",
213
  "CONCURRENCY_COUNT",
 
8
  import logfire
9
  from custom_retriever import CustomRetriever
10
  from dotenv import load_dotenv
11
+ from llama_index.core import Document, VectorStoreIndex
 
12
  from llama_index.core.node_parser import SentenceSplitter
13
+ from llama_index.core.retrievers import VectorIndexRetriever
 
 
 
 
14
  from llama_index.embeddings.cohere import CohereEmbedding
 
15
  from llama_index.vector_stores.chroma import ChromaVectorStore
16
  from utils import init_mongo_db
17
 
 
93
  with open(f"data/{db_collection}/{dict_file_name}", "rb") as f:
94
  document_dict = pickle.load(f)
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  return CustomRetriever(vector_retriever, document_dict)
97
 
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  custom_retriever_all_sources: CustomRetriever = setup_database(
100
  "chroma-db-all_sources",
101
  "document_dict_all_sources.pkl",
102
  )
103
 
104
+
105
  CONCURRENCY_COUNT = int(os.getenv("CONCURRENCY_COUNT", 64))
106
  MONGODB_URI = os.getenv("MONGODB_URI")
107
 
 
115
  "Towards AI Blog",
116
  "8 Hour Primer",
117
  "Advanced LLM Developer",
118
+ "Python Primer",
119
  ]
120
 
121
  AVAILABLE_SOURCES = [
 
128
  "tai_blog",
129
  "8-hour_primer",
130
  "llm_developer",
131
+ "python_primer",
132
  ]
133
 
134
  mongo_db = (
 
138
  )
139
 
140
  __all__ = [
 
 
 
 
 
 
141
  "custom_retriever_all_sources",
142
  "mongo_db",
143
  "CONCURRENCY_COUNT",