Browse Source

add langchain examples

Jeffrey Morgan 1 năm trước cách đây
mục cha
commit
55aa4aaf0f

+ 1 - 1
examples/README.md

@@ -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 - 0
examples/langchain-document/README.md

@@ -0,0 +1,15 @@
+# LangChain Web Summarization
+
+This example summarizes a website
+
+## Setup
+
+```
+pip install -r requirements.txt
+```
+
+## Run
+
+```
+python main.py
+```

+ 12 - 0
examples/langchain-document/main.py

@@ -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 - 0
examples/langchain-document/requirements.txt

@@ -0,0 +1,2 @@
+langchain==0.0.259
+bs4==0.0.1

+ 15 - 0
examples/langchain-web-summary/README.md

@@ -0,0 +1,15 @@
+# LangChain Web Summarization
+
+This example summarizes a website
+
+## Setup
+
+```
+pip install -r requirements.txt
+```
+
+## Run
+
+```
+python main.py
+```

+ 12 - 0
examples/langchain-web-summary/main.py

@@ -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 - 0
examples/langchain-web-summary/requirements.txt

@@ -0,0 +1,2 @@
+langchain==0.0.259
+bs4==0.0.1

+ 15 - 0
examples/langchain/README.md

@@ -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 - 0
examples/langchain/main.py

@@ -0,0 +1,4 @@
+from langchain.llms import Ollama
+llm = Ollama(model="llama2")
+res = llm.predict("hi!")
+print (res)

+ 1 - 0
examples/langchain/requirements.txt

@@ -0,0 +1 @@
+langchain==0.0.259