-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3e8389
commit 9d2b6e5
Showing
5 changed files
with
72 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
## Web Wanderer | ||
|
||
This is a lightweight app for the LangChain [Web Research Retriever](https://github.com/langchain-ai/langchain/pull/8102). | ||
This is a lightweight app using the [Web Research Retriever](https://github.com/langchain-ai/langchain/pull/8102). | ||
|
||
You only need to supply a few thiings. | ||
|
||
In `settings()` function, supply: | ||
|
||
### Search | ||
Supply search functionality e.g., Google - | ||
``` | ||
export GOOGLE_CSE_ID=xxx | ||
export GOOGLE_API_KEY=xxx | ||
search = GoogleSearchAPIWrapper() | ||
``` | ||
Select the search tool you want to use (e.g., GoogleSearchAPIWrapper). | ||
|
||
### Public API | ||
Supply API key(s) e.g., OpenAI - | ||
``` | ||
export OPENAI_API_KEY=sk-xxx | ||
``` | ||
### Vectorstore | ||
Select the vectorstore you want to use (e.g., Chroma). | ||
|
||
### LLM | ||
Select the vectorstore you want to use (e.g., ChatOpenAI). | ||
|
||
### Private | ||
Follow [setup](https://python.langchain.com/docs/use_cases/question_answering/local_retrieval_qa) for local LLMs and supply path. | ||
Then, run: | ||
|
||
### Run | ||
streamlit run web_wanderer.py | ||
``` | ||
streamlit run web_explorer.py | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import streamlit as st | ||
from langchain.chains import RetrievalQAWithSourcesChain | ||
from langchain.retrievers.web_research import WebResearchRetriever | ||
|
||
@st.cache_resource | ||
def settings(): | ||
|
||
# Vectorstore | ||
from langchain.vectorstores import Chroma | ||
from langchain.embeddings.openai import OpenAIEmbeddings | ||
vectorstore_public = Chroma(embedding_function=OpenAIEmbeddings()) | ||
|
||
# LLM | ||
from langchain.chat_models import ChatOpenAI | ||
llm = ChatOpenAI(temperature=0) | ||
|
||
# Search | ||
from langchain.utilities import GoogleSearchAPIWrapper | ||
os.environ["GOOGLE_CSE_ID"] = "xxx" | ||
os.environ["GOOGLE_API_KEY"] = "xxx" | ||
search = GoogleSearchAPIWrapper() | ||
|
||
# Initialize | ||
web_retriever = WebResearchRetriever.from_llm( | ||
vectorstore=vectorstore_public, | ||
llm=llm, | ||
search=search, | ||
) | ||
|
||
return web_retriever, llm | ||
|
||
st.sidebar.image("img/ai.png") | ||
st.header("`Interweb Explorer`") | ||
st.info("`I am an AI that can answer questions by exploring, reading, and summarizing web pages." | ||
"I can be configured to use different moddes: public API or private (no data sharing).`") | ||
|
||
# Make retriever and llm | ||
web_retriever, llm = settings() | ||
|
||
# User input | ||
question = st.text_input("`Ask a question:`") | ||
|
||
if question: | ||
|
||
# Generate answer (w/ citations) | ||
import logging | ||
logging.basicConfig() | ||
logging.getLogger("langchain.retrievers.web_research").setLevel(logging.INFO) | ||
qa_chain = RetrievalQAWithSourcesChain.from_chain_type(llm, | ||
retriever=web_retriever) | ||
|
||
# Write answer and sources | ||
result = qa_chain({"question": question}) | ||
st.info('`Answer:`') | ||
st.info(result['answer']) | ||
st.info('`Source:`') | ||
st.info(result['sources']) | ||
|
This file was deleted.
Oops, something went wrong.