add langchain examples
This commit is contained in:
parent
820f95c4c4
commit
55aa4aaf0f
10 changed files with 79 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
# Examples
|
||||
|
||||
This directory contains examples that can be created and run with `ollama`.
|
||||
This directory contains different examples of using Ollama
|
||||
|
||||
To create a model:
|
||||
|
||||
|
|
15
examples/langchain-document/README.md
Normal file
15
examples/langchain-document/README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# LangChain Web Summarization
|
||||
|
||||
This example summarizes a website
|
||||
|
||||
## Setup
|
||||
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
```
|
||||
python main.py
|
||||
```
|
12
examples/langchain-document/main.py
Normal file
12
examples/langchain-document/main.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from langchain.llms import Ollama
|
||||
from langchain.document_loaders import WebBaseLoader
|
||||
from langchain.chains.summarize import load_summarize_chain
|
||||
|
||||
loader = WebBaseLoader("https://ollama.ai/blog/run-llama2-uncensored-locally")
|
||||
docs = loader.load()
|
||||
|
||||
llm = Ollama(model="llama2")
|
||||
chain = load_summarize_chain(llm, chain_type="stuff")
|
||||
|
||||
result = chain.run(docs)
|
||||
print(result)
|
2
examples/langchain-document/requirements.txt
Normal file
2
examples/langchain-document/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
langchain==0.0.259
|
||||
bs4==0.0.1
|
15
examples/langchain-web-summary/README.md
Normal file
15
examples/langchain-web-summary/README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# LangChain Web Summarization
|
||||
|
||||
This example summarizes a website
|
||||
|
||||
## Setup
|
||||
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
```
|
||||
python main.py
|
||||
```
|
12
examples/langchain-web-summary/main.py
Normal file
12
examples/langchain-web-summary/main.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from langchain.llms import Ollama
|
||||
from langchain.document_loaders import WebBaseLoader
|
||||
from langchain.chains.summarize import load_summarize_chain
|
||||
|
||||
loader = WebBaseLoader("https://ollama.ai/blog/run-llama2-uncensored-locally")
|
||||
docs = loader.load()
|
||||
|
||||
llm = Ollama(model="llama2")
|
||||
chain = load_summarize_chain(llm, chain_type="stuff")
|
||||
|
||||
result = chain.run(docs)
|
||||
print(result)
|
2
examples/langchain-web-summary/requirements.txt
Normal file
2
examples/langchain-web-summary/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
langchain==0.0.259
|
||||
bs4==0.0.1
|
15
examples/langchain/README.md
Normal file
15
examples/langchain/README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# LangChain
|
||||
|
||||
This example is a basic "hello world" of using LangChain with Ollama.
|
||||
|
||||
## Setup
|
||||
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
```
|
||||
python main.py
|
||||
```
|
4
examples/langchain/main.py
Normal file
4
examples/langchain/main.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from langchain.llms import Ollama
|
||||
llm = Ollama(model="llama2")
|
||||
res = llm.predict("hi!")
|
||||
print (res)
|
1
examples/langchain/requirements.txt
Normal file
1
examples/langchain/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
langchain==0.0.259
|
Loading…
Reference in a new issue