mirror of
https://github.com/run-llama/llama-hub.git
synced 2025-11-25 22:47:02 +00:00
update readme example (#140)
This commit is contained in:
parent
b944a50276
commit
f29c41c8de
23
README.md
23
README.md
@ -30,31 +30,22 @@ Note: Make sure you change the description of the `Tool` to match your use-case.
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
from llama_index import GPTSimpleVectorIndex, download_loader
|
from llama_index import GPTSimpleVectorIndex, download_loader
|
||||||
from langchain.agents import initialize_agent, Tool
|
|
||||||
from langchain.llms import OpenAI
|
from langchain.llms import OpenAI
|
||||||
from langchain.chains.conversation.memory import ConversationBufferMemory
|
from langchain.chains.question_answering import load_qa_chain
|
||||||
|
|
||||||
|
# load documents
|
||||||
GoogleDocsReader = download_loader('GoogleDocsReader')
|
GoogleDocsReader = download_loader('GoogleDocsReader')
|
||||||
|
|
||||||
gdoc_ids = ['1wf-y2pd9C878Oh-FmLH7Q_BQkljdm6TQal-c1pUfrec']
|
gdoc_ids = ['1wf-y2pd9C878Oh-FmLH7Q_BQkljdm6TQal-c1pUfrec']
|
||||||
loader = GoogleDocsReader()
|
loader = GoogleDocsReader()
|
||||||
documents = loader.load_data(document_ids=gdoc_ids)
|
documents = loader.load_data(document_ids=gdoc_ids)
|
||||||
index = GPTSimpleVectorIndex(documents)
|
langchain_documents = [d.to_langchain_format() for d in documents]
|
||||||
|
|
||||||
tools = [
|
# initialize sample QA chain
|
||||||
Tool(
|
|
||||||
name="Google Doc Index",
|
|
||||||
func=lambda q: index.query(q),
|
|
||||||
description=f"Useful when you want answer questions about the Google Documents.",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
llm = OpenAI(temperature=0)
|
llm = OpenAI(temperature=0)
|
||||||
memory = ConversationBufferMemory(memory_key="chat_history")
|
qa_chain = load_qa_chain(llm)
|
||||||
agent_chain = initialize_agent(
|
question="<query here>"
|
||||||
tools, llm, agent="zero-shot-react-description", memory=memory
|
answer = chain.run(input_documents=langchain_documents, question=question)
|
||||||
)
|
|
||||||
|
|
||||||
output = agent_chain.run(input="Where did the author go to school?")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## How to add a loader
|
## How to add a loader
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user