Skip to content

Commit

Permalink
Update with simplified app
Browse files Browse the repository at this point in the history
  • Loading branch information
rlancemartin committed Jul 25, 2023
1 parent b3e8389 commit 9d2b6e5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 142 deletions.
29 changes: 13 additions & 16 deletions README.md
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
```
Binary file added img/ai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/bot.png
Binary file not shown.
59 changes: 59 additions & 0 deletions web_explorer.py
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'])

126 changes: 0 additions & 126 deletions web_wanderer.py

This file was deleted.

0 comments on commit 9d2b6e5

Please sign in to comment.