Spaces:
Sleeping
Sleeping
Download graph/nodes/web_search.py from mikail-bitik/CorrectiveRAGProject: direct link, hf CLI and curl.
- Browser
- Download file 723 Bytes
-
https://huggingface.co/spaces/mikail-bitik/CorrectiveRAGProject/resolve/main/graph/nodes/web_search.py
- Command line
-
hf download hf://spaces/mikail-bitik/CorrectiveRAGProject/graph/nodes/web_search.py
-
curl -L -o web_search.py https://huggingface.co/spaces/mikail-bitik/CorrectiveRAGProject/resolve/main/graph/nodes/web_search.py
723 Bytes
| from typing import Dict, Any | |
| from graph.state import GraphState | |
| from langchain_community.tools.tavily_search import TavilySearchResults | |
| from langchain_core.documents import Document | |
| web_search_tool = TavilySearchResults(k=3) | |
| def web_search(state: GraphState) -> Dict[str, Any]: | |
| print("----WEB SEARCH----") | |
| question = state["question"] | |
| documents = state.get("documents",[]) | |
| docs = web_search_tool.invoke({"query":question}) | |
| web_results = "\n".join([d["content"] for d in docs]) | |
| web_results = Document(page_content=web_results) | |
| if documents is not None: | |
| documents.append(web_results) | |
| else: | |
| documents = [web_results] | |
| return {"question":question, "documents":documents} |