Spaces:
Configuration error
Configuration error
oremaz commited on
Commit ·
36bdc91
1
Parent(s): 6066d4f
Update agent.py
Browse files40 unmodified lines41424344454647488 unmodified lines5758596061626364656667686935 unmodified lines105106107108109110193 unmodified lines30430530630730830931031139 unmodified lines35135235335435535635735835936036136236336436536636736840 unmodified linesPDFReader,DocxReader,CSVReader,PandasExcelReader,)from typing import List, Unionfrom llama_index.core import VectorStoreIndex, Document, Settingsfrom llama_index.core.tools import QueryEngineTool8 unmodified linesimport weaveweave.init("gaia-llamaindex-agents")# Keep only the debug handlerllama_debug = LlamaDebugHandler(print_trace_on_end=True)callback_manager = CallbackManager([llama_debug])logging.basicConfig(level=logging.INFO)logging.getLogger("llama_index.core.agent").setLevel(logging.DEBUG)logging.getLogger("llama_index.llms").setLevel(logging.DEBUG)def get_max_memory_config(max_memory_per_gpu):"""Generate max_memory config for available GPUs"""35 unmodified lines"low_cpu_mem_usage": True, # Still get memory optimization})Settings.llm = proj_llmSettings.embed_model = embed_model193 unmodified lineshybrid_reranker = HybridReranker()query_engine = index.as_query_engine(similarity_top_k=10,node_postprocessors=[hybrid_reranker],)self.query_engine_tool = QueryEngineTool.from_defaults(39 unmodified linestry:# Check if it's a YouTube URLif "youtube" in urlparse(url).netloc:loader = YoutubeTranscriptReader()documents = loader.load_data(youtubelinks=[url])else:loader = TrafilaturaWebReader()documents = loader.load_data(urls=[url])except Exception as e:# Handle any exceptions that occur during content extractionreturn [Document(text=f"Error extracting content from URL: {str(e)}")]return documentsdef enhanced_web_search_and_update(query: str) -> str:"""Performs web search, extracts content, and adds it to the dynamic query engine.40 unmodified lines414243444546478 unmodified lines56575859606135 unmodified lines979899100101102103104105106107108193 unmodified lines30230330430530630730830931039 unmodified lines35035135235335435535635735835936036136236336436536636736836940 unmodified linesPDFReader,DocxReader,CSVReader,PandasExcelReader)from typing import List, Unionfrom llama_index.core import VectorStoreIndex, Document, Settingsfrom llama_index.core.tools import QueryEngineTool8 unmodified linesimport weaveweave.init("gaia-llamaindex-agents")def get_max_memory_config(max_memory_per_gpu):"""Generate max_memory config for available GPUs"""35 unmodified lines"low_cpu_mem_usage": True, # Still get memory optimization})llama_debug = LlamaDebugHandler(print_trace_on_end=True)callback_manager = CallbackManager([llama_debug])logging.basicConfig(level=logging.INFO)logging.getLogger("llama_index.core.agent").setLevel(logging.DEBUG)logging.getLogger("llama_index.llms").setLevel(logging.DEBUG)Settings.llm = proj_llmSettings.embed_model = embed_model193 unmodified lineshybrid_reranker = HybridReranker()query_engine = index.as_query_engine(similarity_top_k=20,node_postprocessors=[hybrid_reranker],response_mode="tree_summarize")self.query_engine_tool = QueryEngineTool.from_defaults(39 unmodified linestry:# Check if it's a YouTube URLif "youtube" in urlparse(url).netloc or "youtu.be" in urlparse(url).netloc:loader = YoutubeTranscriptReader()documents = loader.load_data(youtubelinks=[url])else:loader = TrafilaturaWebReader()documents = loader.load_data(urls=[url])for doc in documents:doc.metadata["source"] = urldoc.metadata["type"] = "web_text"return documentsexcept Exception as e:# Handle any exceptions that occur during content extractionreturn [Document(text=f"Error extracting content from URL: {str(e)}")]def enhanced_web_search_and_update(query: str) -> str:"""Performs web search, extracts content, and adds it to the dynamic query engine.
agent.py+14-13