Spaces:
Runtime error
Runtime error
Add Python Primer source to available sources and UI configuration
Browse filesFiles changed (2)
- scripts/main.py+3-32
- scripts/setup.py+5-75
14 unmodified lines151617181920214 unmodified lines26272829303132333435363738394041424344454647484950515253545556575859606168 unmodified lines130131132133134135111 unmodified lines24724824925025125225314 unmodified lines)from llama_index.llms.openai import OpenAIfrom prompts import system_message_openai_agentfrom setup import ( # custom_retriever_langchain,; custom_retriever_llama_index,; custom_retriever_openai_cookbooks,; custom_retriever_peft,; custom_retriever_transformers,; custom_retriever_trl,AVAILABLE_SOURCES,AVAILABLE_SOURCES_UI,CONCURRENCY_COUNT,4 unmodified linesdef update_query_engine_tools(selected_sources) -> list[RetrieverTool]:tools = []source_mapping: dict[str, tuple[CustomRetriever, str, str]] = {# "Transformers Docs": (# custom_retriever_transformers,# "Transformers_information",# """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.""",# ),# "PEFT Docs": (# custom_retriever_peft,# "PEFT_information",# """Useful for questions asking about efficient LLM fine-tuning. Employ this tool to fetch information on topics such as LoRA, QLoRA, etc.""",# ),# "TRL Docs": (# custom_retriever_trl,# "TRL_information",# """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.""",# ),# "LlamaIndex Docs": (# custom_retriever_llama_index,# "LlamaIndex_information",# """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.""",# ),# "OpenAI Cookbooks": (# custom_retriever_openai_cookbooks,# "openai_cookbooks_info",# """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.""",# ),# "LangChain Docs": (# custom_retriever_langchain,# "langchain_info",# """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.""",# ),"All Sources": (custom_retriever_all_sources,"all_sources_info",68 unmodified lines"Towards AI Blog": "tai_blog","8 Hour Primer": "8-hour_primer","Advanced LLM Developer": "llm_developer",}for source in sources:111 unmodified lines"Towards AI Blog","8 Hour Primer","Advanced LLM Developer",# "All Sources",],interactive=True,)14 unmodified lines151617181920214 unmodified lines26272829303168 unmodified lines100101102103104105106111 unmodified lines21821922022122222322414 unmodified lines)from llama_index.llms.openai import OpenAIfrom prompts import system_message_openai_agentfrom setup import (AVAILABLE_SOURCES,AVAILABLE_SOURCES_UI,CONCURRENCY_COUNT,4 unmodified linesdef update_query_engine_tools(selected_sources) -> list[RetrieverTool]:tools = []source_mapping: dict[str, tuple[CustomRetriever, str, str]] = {"All Sources": (custom_retriever_all_sources,"all_sources_info",68 unmodified lines"Towards AI Blog": "tai_blog","8 Hour Primer": "8-hour_primer","Advanced LLM Developer": "llm_developer","Python Primer": "python_primer",}for source in sources:111 unmodified lines"Towards AI Blog","8 Hour Primer","Advanced LLM Developer","Python Primer",],interactive=True,)
7 unmodified lines89101112131415161718192021222375 unmodified lines991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701717 unmodified lines1791801811821831841856 unmodified lines1921931941951961971983 unmodified lines2022032042052062072082092102112122137 unmodified linesimport logfirefrom custom_retriever import CustomRetrieverfrom dotenv import load_dotenvfrom llama_index.core import Document, SimpleKeywordTableIndex, VectorStoreIndexfrom llama_index.core.ingestion import IngestionPipelinefrom llama_index.core.node_parser import SentenceSplitterfrom llama_index.core.retrievers import (KeywordTableSimpleRetriever,VectorIndexRetriever,)from llama_index.core.schema import NodeWithScore, QueryBundlefrom llama_index.embeddings.cohere import CohereEmbeddingfrom llama_index.embeddings.openai import OpenAIEmbeddingfrom llama_index.vector_stores.chroma import ChromaVectorStorefrom utils import init_mongo_db75 unmodified lineswith open(f"data/{db_collection}/{dict_file_name}", "rb") as f:document_dict = pickle.load(f)# with open("data/keyword_retriever_sync.pkl", "rb") as f:# keyword_retriever: KeywordTableSimpleRetriever = pickle.load(f)# keyword_retriever.num_chunks_per_query = 15# # Creating the keyword index and retriever# logfire.info("Creating nodes from documents")# documents = create_docs("data/all_sources_data.jsonl")# pipeline = IngestionPipeline(# transformations=[SentenceSplitter(chunk_size=800, chunk_overlap=0)]# )# all_nodes = pipeline.run(documents=documents, show_progress=True)# # with open("data/all_nodes.pkl", "wb") as f:# # pickle.dump(all_nodes, f)# all_nodes = pickle.load(open("data/nodes_with_added_context.pkl", "rb"))# logfire.info(f"Number of nodes: {len(all_nodes)}")# keyword_index = SimpleKeywordTableIndex(# nodes=all_nodes, max_keywords_per_chunk=10, show_progress=True, use_async=False# )# # with open("data/keyword_index.pkl", "wb") as f:# # pickle.dump(keyword_index, f)# # keyword_index = pickle.load(open("data/keyword_index.pkl", "rb"))# logfire.info("Creating keyword retriever")# keyword_retriever = KeywordTableSimpleRetriever(index=keyword_index)# with open("data/keyword_retriever_sync.pkl", "wb") as f:# pickle.dump(keyword_retriever, f)# 'OR' Means both the vector nodes and the keyword nodes# return CustomRetriever(vector_retriever, document_dict, keyword_retriever, "OR")return CustomRetriever(vector_retriever, document_dict)# Setup retrievers# custom_retriever_transformers: CustomRetriever = setup_database(# "chroma-db-transformers",# "document_dict_transformers.pkl",# )# custom_retriever_peft: CustomRetriever = setup_database(# "chroma-db-peft", "document_dict_peft.pkl"# )# custom_retriever_trl: CustomRetriever = setup_database(# "chroma-db-trl", "document_dict_trl.pkl"# )# custom_retriever_llama_index: CustomRetriever = setup_database(# "chroma-db-llama_index",# "document_dict_llama_index.pkl",# )# custom_retriever_openai_cookbooks: CustomRetriever = setup_database(# "chroma-db-openai_cookbooks",# "document_dict_openai_cookbooks.pkl",# )# custom_retriever_langchain: CustomRetriever = setup_database(# "chroma-db-langchain",# "document_dict_langchain.pkl",# )custom_retriever_all_sources: CustomRetriever = setup_database("chroma-db-all_sources","document_dict_all_sources.pkl",)# ConstantsCONCURRENCY_COUNT = int(os.getenv("CONCURRENCY_COUNT", 64))MONGODB_URI = os.getenv("MONGODB_URI")7 unmodified lines"Towards AI Blog","8 Hour Primer","Advanced LLM Developer",# "All Sources",]AVAILABLE_SOURCES = [6 unmodified lines"tai_blog","8-hour_primer","llm_developer",# "all_sources",]mongo_db = (3 unmodified lines)__all__ = [# "custom_retriever_transformers",# "custom_retriever_peft",# "custom_retriever_trl",# "custom_retriever_llama_index",# "custom_retriever_openai_cookbooks",# "custom_retriever_langchain","custom_retriever_all_sources","mongo_db","CONCURRENCY_COUNT",7 unmodified lines89101112131415161775 unmodified lines939495969798991001011021031041051061077 unmodified lines1151161171181191201216 unmodified lines1281291301311321331343 unmodified lines1381391401411421437 unmodified linesimport logfirefrom custom_retriever import CustomRetrieverfrom dotenv import load_dotenvfrom llama_index.core import Document, VectorStoreIndexfrom llama_index.core.node_parser import SentenceSplitterfrom llama_index.core.retrievers import VectorIndexRetrieverfrom llama_index.embeddings.cohere import CohereEmbeddingfrom llama_index.vector_stores.chroma import ChromaVectorStorefrom utils import init_mongo_db75 unmodified lineswith open(f"data/{db_collection}/{dict_file_name}", "rb") as f:document_dict = pickle.load(f)return CustomRetriever(vector_retriever, document_dict)custom_retriever_all_sources: CustomRetriever = setup_database("chroma-db-all_sources","document_dict_all_sources.pkl",)CONCURRENCY_COUNT = int(os.getenv("CONCURRENCY_COUNT", 64))MONGODB_URI = os.getenv("MONGODB_URI")7 unmodified lines"Towards AI Blog","8 Hour Primer","Advanced LLM Developer","Python Primer",]AVAILABLE_SOURCES = [6 unmodified lines"tai_blog","8-hour_primer","llm_developer","python_primer",]mongo_db = (3 unmodified lines)__all__ = ["custom_retriever_all_sources","mongo_db","CONCURRENCY_COUNT",
scripts/main.py+3-32
scripts/setup.py+5-75