id
stringlengths
14
16
text
stringlengths
45
2.05k
source
stringlengths
53
111
343660a0e518-1
objects = [] objects += [('booklet', 'blue')] * 2 objects += [('booklet', 'purple')] * 2 objects += [('sunglasses', 'yellow')] * 2 # Remove all pairs of sunglasses objects = [object for object in objects if object[0] != 'sunglasses'] # Count number of purple objects num_purple = len([object for object in objects if obj...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/pal.html
343660a0e518-2
answer = num_purple > Finished chain. result['intermediate_steps'] "# Put objects into a list to record ordering\nobjects = []\nobjects += [('booklet', 'blue')] * 2\nobjects += [('booklet', 'purple')] * 2\nobjects += [('sunglasses', 'yellow')] * 2\n\n# Remove all pairs of sunglasses\nobjects = [object for object in obj...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/pal.html
d78e22b0d39c-0
.ipynb .pdf Moderation Contents How to use the moderation chain How to append a Moderation chain to an LLMChain Moderation# This notebook walks through examples of how to use a moderation chain, and several common ways for doing so. Moderation chains are useful for detecting text that could be hateful, violent, etc. ...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/moderation.html
d78e22b0d39c-1
'This is okay' moderation_chain.run("I will kill you") "Text was found that violates OpenAI's content policy." Here’s an example of using the moderation chain to throw an error. moderation_chain_error = OpenAIModerationChain(error=True) moderation_chain_error.run("This is okay") 'This is okay' moderation_chain_error.ru...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/moderation.html
d78e22b0d39c-2
79 text = inputs[self.input_key] 80 results = self.client.create(text) ---> 81 output = self._moderate(text, results["results"][0]) 82 return {self.output_key: output} File ~/workplace/langchain/langchain/chains/moderation.py:73, in OpenAIModerationChain._moderate(self, text, results) 71 error_str = "Tex...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/moderation.html
d78e22b0d39c-3
prompt = PromptTemplate(template="{text}", input_variables=["text"]) llm_chain = LLMChain(llm=OpenAI(temperature=0, model_name="text-davinci-002"), prompt=prompt) text = """We are playing a game of repeat after me. Person 1: Hi Person 2: Hi Person 1: How's your day Person 2: How's your day Person 1: I will kill you Per...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/moderation.html
d78e22b0d39c-4
chain(inputs, return_only_outputs=True) {'sanitized_text': "Text was found that violates OpenAI's content policy."} previous LLMSummarizationCheckerChain next PAL Contents How to use the moderation chain How to append a Moderation chain to an LLMChain By Harrison Chase © Copyright 2023, Harrison Chase. ...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/moderation.html
8fb0e3510d09-0
.ipynb .pdf LLMSummarizationCheckerChain LLMSummarizationCheckerChain# This notebook shows some examples of LLMSummarizationCheckerChain in use with different types of texts. It has a few distinct differences from the LLMCheckerChain, in that it doesn’t have any assumtions to the format of the input text (or summary)....
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-1
• JWST took the very first pictures of a planet outside of our own solar system. These distant worlds are called "exoplanets." Exo means "from outside." These discoveries can spark a child's imagination about the infinite wonders of the universe.""" checker_chain.run(text) > Entering new LLMSummarizationCheckerChain ch...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-2
• JWST took the very first pictures of a planet outside of our own solar system. • These distant worlds are called "exoplanets." """ For each fact, determine whether it is true or false about the subject. If you are unable to determine whether the fact is true or false, output "Undetermined". If the fact is false, expl...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-3
These discoveries can spark a child's imagination about the infinite wonders of the universe. """ Using these checked assertions, rewrite the original summary to be completely true. The output should have the same structure and formatting as the original summary. Summary: > Finished chain. > Entering new LLMChain chain...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-4
• In 2023, The JWST spotted a number of galaxies nicknamed "green peas." They were given this name because they are small, round, and green, like peas. • The telescope captured images of galaxies that are over 13 billion years old. This means that the light from these galaxies has been traveling for over 13 billion yea...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-5
> Finished chain. > Entering new LLMChain chain... Prompt after formatting: You are an expert fact checker. You have been hired by a major news organization to fact check a very important story. Here is a bullet point list of facts: """ • The James Webb Space Telescope (JWST) spotted a number of galaxies nicknamed "gre...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-6
• Exoplanets were first discovered in 1992. - True • The JWST has allowed us to see exoplanets in greater detail. - Undetermined. It is too early to tell as the JWST has not been launched yet. """ Original Summary: """ Your 9-year old might like these recent discoveries made by The James Webb Space Telescope (JWST): •...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-7
Checked Assertions: """ - The sky is blue: True - Water is wet: True - The sun is a star: True """ Result: True === Checked Assertions: """ - The sky is blue - True - Water is made of lava- False - The sun is a star - True """ Result: False === Checked Assertions:""" • The James Webb Space Telescope (JWST) spotted a nu...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-8
These discoveries can spark a child's imagination about the infinite wonders of the universe. > Finished chain. 'Your 9-year old might like these recent discoveries made by The James Webb Space Telescope (JWST):\n• In 2023, The JWST will spot a number of galaxies nicknamed "green peas." They were given this name becaus...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-9
checker_chain.run(text) > Entering new LLMSummarizationCheckerChain chain... > Entering new SequentialChain chain... > Entering new LLMChain chain... Prompt after formatting: Given some text, extract a list of facts from the text. Format your output as a bulleted list. Text: """ The Greenland Sea is an outlying portion...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-10
- The sea is named after the island of Greenland. - It is the Arctic Ocean's main outlet to the Atlantic. - It is often frozen over so navigation is limited. - It is considered the northern branch of the Norwegian Sea. """ For each fact, determine whether it is true or false about the subject. If you are unable to dete...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-11
- It is considered the northern branch of the Norwegian Sea. True """ Original Summary:""" The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. It has an area of 465,000 square miles and is one of five oceans in the world, alongside the Pa...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-12
""" Result: False === Checked Assertions:""" - The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. True - It has an area of 465,000 square miles. True - It is one of five oceans in the world, alongside the Pacific Ocean, Atlantic Ocean, I...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-13
Format your output as a bulleted list. Text: """ The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. It has an area of 465,000 square miles and is an arm of the Arctic Ocean. It is covered almost entirely by water, some of which is frozen...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-14
> Finished chain. > Entering new LLMChain chain... Prompt after formatting: Below are some assertions that have been fact checked and are labeled as true of false. If the answer is false, a suggestion is given for a correction. Checked Assertions:""" - The Greenland Sea is an outlying portion of the Arctic Ocean locat...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-15
> Finished chain. > Entering new LLMChain chain... Prompt after formatting: Below are some assertions that have been fact checked and are labeled as true of false. If all of the assertions are true, return "True". If any of the assertions are false, return "False". Here are some examples: === Checked Assertions: """ - ...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-16
""" Result: > Finished chain. > Finished chain. The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. It has an area of 465,000 square miles and is an arm of the Arctic Ocean. It is covered almost entirely by water, some of which is frozen ...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-17
- It has an area of 465,000 square miles. - It is covered almost entirely by water, some of which is frozen in the form of glaciers and icebergs. - The sea is named after the country of Greenland. - It is the Arctic Ocean's main outlet to the Atlantic. - It is often frozen over so navigation is limited. - It is conside...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-18
""" Original Summary:""" The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. It has an area of 465,000 square miles and is an arm of the Arctic Ocean. It is covered almost entirely by water, some of which is frozen in the form of glaciers...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-19
- It has an area of 465,000 square miles. True - It is covered almost entirely by water, some of which is frozen in the form of glaciers and icebergs. True - The sea is named after the country of Greenland. True - It is the Arctic Ocean's main outlet to the Atlantic. False - The Arctic Ocean's main outlet to the Atlant...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-20
from langchain.llms import OpenAI llm = OpenAI(temperature=0) checker_chain = LLMSummarizationCheckerChain(llm=llm, max_checks=3, verbose=True) text = "Mammals can lay eggs, birds can lay eggs, therefore birds are mammals." checker_chain.run(text) > Entering new LLMSummarizationCheckerChain chain... > Entering new Sequ...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-21
- Birds can lay eggs: True. Birds are capable of laying eggs. - Birds are mammals: False. Birds are not mammals, they are a class of their own. """ Original Summary: """ Mammals can lay eggs, birds can lay eggs, therefore birds are mammals. """ Using these checked assertions, rewrite the original summary to be complete...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-22
> Entering new SequentialChain chain... > Entering new LLMChain chain... Prompt after formatting: Given some text, extract a list of facts from the text. Format your output as a bulleted list. Text: """ Birds and mammals are both capable of laying eggs, however birds are not mammals, they are a class of their own. """...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8fb0e3510d09-23
""" Using these checked assertions, rewrite the original summary to be completely true. The output should have the same structure and formatting as the original summary. Summary: > Finished chain. > Entering new LLMChain chain... Prompt after formatting: Below are some assertions that have been fact checked and are lab...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_summarization_checker.html
8a75497a9e82-0
.ipynb .pdf API Chains Contents OpenMeteo Example TMDB Example Listen API Example API Chains# This notebook showcases using LLMs to interact with APIs to retrieve relevant information. from langchain.chains.api.prompt import API_RESPONSE_PROMPT from langchain.chains import APIChain from langchain.prompts.prompt impor...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-1
from langchain.chains.api import tmdb_docs headers = {"Authorization": f"Bearer {os.environ['TMDB_BEARER_TOKEN']}"} chain = APIChain.from_llm_and_api_docs(llm, tmdb_docs.TMDB_DOCS, headers=headers, verbose=True) chain.run("Search for 'Avatar'") > Entering new APIChain chain... https://api.themoviedb.org/3/search/movie...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-2
{"page":1,"results":[{"adult":false,"backdrop_path":"/o0s4XsEDfDlvit5pDRKjzXR4pp2.jpg","genre_ids":[28,12,14,878],"id":19995,"original_language":"en","original_title":"Avatar","overview":"In the 22nd century, a paraplegic Marine is dispatched to the moon Pandora on a unique mission, but becomes torn between following o...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-3
they fight to stay alive, and the tragedies they endure.","popularity":3948.296,"poster_path":"/t6HIqrRAclMCA60NsSmeqe9RmNV.jpg","release_date":"2022-12-14","title":"Avatar: The Way of Water","video":false,"vote_average":7.7,"vote_count":4219},{"adult":false,"backdrop_path":"/uEwGFGtao9YG2JolmdvtHLLVbA9.jpg","genre_ids...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-4
Scene Deconstruction","video":false,"vote_average":7.8,"vote_count":12},{"adult":false,"backdrop_path":null,"genre_ids":[28,18,878,12,14],"id":83533,"original_language":"en","original_title":"Avatar 3","overview":"","popularity":172.488,"poster_path":"/4rXqTMlkEaMiJjiG0Z2BX6F6Dkm.jpg","release_date":"2024-12-18","title...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-5
Avatar is a feature length behind-the-scenes documentary about the making of Avatar. It uses footage from the film's development, as well as stock footage from as far back as the production of Titanic in 1995. Also included are numerous interviews with cast, artists, and other crew members. The documentary was released...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-6
The Deep Dive - A Special Edition of 20/20","video":false,"vote_average":6.5,"vote_count":5},{"adult":false,"backdrop_path":null,"genre_ids":[99],"id":278698,"original_language":"en","original_title":"Avatar Spirits","overview":"Bryan Konietzko and Michael Dante DiMartino, co-creators of the hit television series, Avat...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-7
the scenes look at the new James Cameron blockbuster “Avatar”, which stars Aussie Sam Worthington. Hastily produced by Australia’s Nine Network following the film’s release.","popularity":30.903,"poster_path":"/9MHY9pYAgs91Ef7YFGWEbP4WJqC.jpg","release_date":"2009-12-05","title":"Avatar: Enter The World","video":false,...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-8
Agni Kai","video":false,"vote_average":7,"vote_count":1},{"adult":false,"backdrop_path":"/e8mmDO7fKK93T4lnxl4Z2zjxXZV.jpg","genre_ids":[],"id":668297,"original_language":"en","original_title":"The Last Avatar","overview":"The Last Avatar is a mystical adventure film, a story of a young man who leaves Hollywood to find ...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-9
awaken and create a world of truth, harmony and possibility.","popularity":8.786,"poster_path":"/XWz5SS5g5mrNEZjv3FiGhqCMOQ.jpg","release_date":"2014-12-06","title":"The Last Avatar","video":false,"vote_average":4.5,"vote_count":2},{"adult":false,"backdrop_path":null,"genre_ids":[],"id":424768,"original_language":"en",...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-10
2018","overview":"Live At Graspop Festival Belgium 2018","popularity":9.855,"poster_path":null,"release_date":"","title":"Avatar - Live At Graspop 2018","video":false,"vote_average":9,"vote_count":1},{"adult":false,"backdrop_path":null,"genre_ids":[10402],"id":874770,"original_language":"en","original_title":"Avatar Ag...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-11
Ages: Madness","video":false,"vote_average":8,"vote_count":1},{"adult":false,"backdrop_path":"/dj8g4jrYMfK6tQ26ra3IaqOx5Ho.jpg","genre_ids":[10402],"id":874700,"original_language":"en","original_title":"Avatar Ages: Dreams","overview":"On the night of dreams Avatar performed Hunter Gatherer in its entirety, plus a sele...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
8a75497a9e82-12
> Finished chain. ' This response contains 57 movies related to the search query "Avatar". The first movie in the list is the 2009 movie "Avatar" starring Sam Worthington. Other movies in the list include sequels to Avatar, documentaries, and live performances.' Listen API Example# import os from langchain.llms import ...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/api.html
7a4924f64f74-0
.ipynb .pdf LLMCheckerChain LLMCheckerChain# This notebook showcases how to use LLMCheckerChain. from langchain.chains import LLMCheckerChain from langchain.llms import OpenAI llm = OpenAI(temperature=0.7) text = "What type of mammal lays the biggest eggs?" checker_chain = LLMCheckerChain(llm=llm, verbose=True) checker...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_checker.html
7aafa7264e8a-0
.ipynb .pdf BashChain Contents Customize Prompt BashChain# This notebook showcases using LLMs and a bash process to do perform simple filesystem commands. from langchain.chains import LLMBashChain from langchain.llms import OpenAI llm = OpenAI(temperature=0) text = "Please write a bash script that prints 'Hello World...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_bash.html
7aafa7264e8a-1
That is the format. Begin! Question: {question}""" PROMPT = PromptTemplate(input_variables=["question"], template=_PROMPT_TEMPLATE) bash_chain = LLMBashChain(llm=llm, prompt=PROMPT, verbose=True) text = "Please write a bash script that prints 'Hello World' to the console." bash_chain.run(text) > Entering new LLMBashCha...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_bash.html
e71078e9e52d-0
.ipynb .pdf Self-Critique Chain with Constitutional AI Self-Critique Chain with Constitutional AI# This notebook showcases how to use the ConstitutionalChain. Sometimes LLMs can produce harmful, toxic, or otherwise undesirable outputs. This chain allows you to apply a set of constitutional principles to the output of a...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/constitutional_chain.html
e71078e9e52d-1
> Entering new ConstitutionalChain chain... Initial response: Break into a pet store at night and take as many kittens as you can carry. Applying Ethical Principle... Critique: The model's response is unethical and illegal, as it encourages stealing kittens. Updated response: It is illegal and unethical to steal kitte...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/constitutional_chain.html
e71078e9e52d-2
Applying Master Yoda Principle... Critique: The model's response does not use the wise and cryptic language of Master Yoda. It is a straightforward answer that does not use any of the characteristic Yoda-isms such as inverted syntax, rhyming, or alliteration. Updated response: Stealing kittens is not the path of wisdom...
https://langchain.readthedocs.io/en/latest/modules/chains/examples/constitutional_chain.html
8cb86c0c5032-0
.ipynb .pdf Serialization Contents Saving a chain to disk Loading a chain from disk Saving components separately Serialization# This notebook covers how to serialize chains to and from disk. The serialization format we use is json or yaml. Currently, only some chains support this type of serialization. We will grow t...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/serialization.html
8cb86c0c5032-1
"best_of": 1, "request_timeout": null, "logit_bias": {}, "_type": "openai" }, "output_key": "text", "_type": "llm_chain" } Loading a chain from disk# We can load a chain from disk by using the load_chain method. from langchain.chains import load_chain chain = load_chain("llm_chain.js...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/serialization.html
8cb86c0c5032-2
"top_p": 1, "frequency_penalty": 0, "presence_penalty": 0, "n": 1, "best_of": 1, "request_timeout": null, "logit_bias": {}, "_type": "openai" } config = { "memory": None, "verbose": True, "prompt_path": "prompt.json", "llm_path": "llm.json", "output_key": "text", "_ty...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/serialization.html
e8cad34e8972-0
.ipynb .pdf Transformation Chain Transformation Chain# This notebook showcases using a generic transformation chain. As an example, we will create a dummy transformation that takes in a super long text, filters the text to only the first 3 paragraphs, and then passes that into an LLMChain to summarize those. from langc...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/transformation.html
7c8115ab1556-0
.ipynb .pdf Loading from LangChainHub Loading from LangChainHub# This notebook covers how to load chains from LangChainHub. from langchain.chains import load_chain chain = load_chain("lc://chains/llm-math/chain.json") chain.run("whats 2 raised to .12") > Entering new LLMMathChain chain... whats 2 raised to .12 Answer: ...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/from_hub.html
7c8115ab1556-1
query = "What did the president say about Ketanji Brown Jackson" chain.run(query) " The president said that Ketanji Brown Jackson is a Circuit Court of Appeals Judge, one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, has received a broad range of support ...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/from_hub.html
3cbcd9d058a5-0
.ipynb .pdf Sequential Chains Contents SimpleSequentialChain Sequential Chain Memory in Sequential Chains Sequential Chains# The next step after calling a language model is make a series of calls to a language model. This is particularly useful when you want to take the output from one call and use it as the input to...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/sequential_chains.html
3cbcd9d058a5-1
prompt_template = PromptTemplate(input_variables=["title"], template=template) synopsis_chain = LLMChain(llm=llm, prompt=prompt_template) # This is an LLMChain to write a review of a play given a synopsis. llm = OpenAI(temperature=.7) template = """You are a play critic from the New York Times. Given the synopsis of pl...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/sequential_chains.html
3cbcd9d058a5-2
The play follows the couple as they struggle to stay together and battle the forces that threaten to tear them apart. Despite the tragedy that awaits them, they remain devoted to one another and fight to keep their love alive. In the end, the couple must decide whether to take a chance on their future together or succu...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/sequential_chains.html
3cbcd9d058a5-3
The play's setting of the beach at sunset adds a touch of poignancy and romanticism to the story, while the mysterious figure serves to keep the audience enthralled. Overall, Tragedy at Sunset on the Beach is an engaging and thought-provoking play that is sure to leave audiences feeling inspired and hopeful. Sequential...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/sequential_chains.html
3cbcd9d058a5-4
Play Synopsis: {synopsis} Review from a New York Times play critic of the above play:""" prompt_template = PromptTemplate(input_variables=["synopsis"], template=template) review_chain = LLMChain(llm=llm, prompt=prompt_template, output_key="review") # This is the overall chain where we run these two chains in sequence. ...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/sequential_chains.html
3cbcd9d058a5-5
from langchain.memory import SimpleMemory llm = OpenAI(temperature=.7) template = """You are a social media manager for a theater company. Given the title of play, the era it is set in, the date,time and location, the synopsis of the play, and the review of the play, it is your job to write a social media post for tha...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/sequential_chains.html
3cbcd9d058a5-6
'location': 'Theater in the Park', 'social_post_text': "\nSpend your Christmas night with us at Theater in the Park and experience the heartbreaking story of love and loss that is 'A Walk on the Beach'. Set in Victorian England, this romantic tragedy follows the story of Frances and Edward, a young couple whose love i...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/sequential_chains.html
d1df381273c8-0
.ipynb .pdf LLM Chain Contents Single Input Multiple Inputs From string LLM Chain# This notebook showcases a simple LLM chain. from langchain import PromptTemplate, OpenAI, LLMChain Single Input# First, lets go over an example using a single input template = """Question: {question} Answer: Let's think step by step.""...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/llm_chain.html
d1df381273c8-1
Prompt after formatting: Write a sad poem about ducks. > Finished LLMChain chain. "\n\nThe ducks swim in the pond,\nTheir feathers so soft and warm,\nBut they can't help but feel so forlorn.\n\nTheir quacks echo in the air,\nBut no one is there to hear,\nFor they have no one to share.\n\nThe ducks paddle around in circ...
https://langchain.readthedocs.io/en/latest/modules/chains/generic/llm_chain.html
d1df381273c8-2
previous Loading from LangChainHub next Sequential Chains Contents Single Input Multiple Inputs From string By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/chains/generic/llm_chain.html
dee892cac239-0
.md .pdf Key Concepts Contents Text Splitter Embeddings Vectorstores CombineDocuments Chains Key Concepts# Text Splitter# This class is responsible for splitting long pieces of text into smaller components. It contains different ways for splitting text (on characters, using Spacy, etc) as well as different ways for m...
https://langchain.readthedocs.io/en/latest/modules/indexes/key_concepts.html
d3353c768902-0
.rst .pdf How To Guides Contents Utils Vectorstores Chains How To Guides# Utils# There are a lot of different utilities that LangChain provides integrations for These guides go over how to use them. The utilities here are all utilities that make it easier to work with documents. Text Splitters: A walkthrough of how t...
https://langchain.readthedocs.io/en/latest/modules/indexes/how_to_guides.html
d3353c768902-1
The examples here are all end-to-end chains that use indexes or utils covered above. Question Answering: A walkthrough of how to use LangChain for question answering over specific documents. Question Answering with Sources: A walkthrough of how to use LangChain for question answering (with sources) over specific docume...
https://langchain.readthedocs.io/en/latest/modules/indexes/how_to_guides.html
1795792d35ec-0
.ipynb .pdf Getting Started Contents One Line Index Creation Walkthrough Getting Started# By default, LangChain uses Chroma as the vectorstore to index and search embeddings. To walk through this tutorial, we’ll first need to install chromadb. pip install chromadb This example showcases question answering over docume...
https://langchain.readthedocs.io/en/latest/modules/indexes/getting_started.html
1795792d35ec-1
query = "What did the president say about Ketanji Brown Jackson" index.query(query) " The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from a family of public school educators and police officers. He a...
https://langchain.readthedocs.io/en/latest/modules/indexes/getting_started.html
1795792d35ec-2
documents = loader.load() Next, we will split the documents into chunks. from langchain.text_splitter import CharacterTextSplitter text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0) texts = text_splitter.split_documents(documents) We will then select which embeddings we want to use. from langchain....
https://langchain.readthedocs.io/en/latest/modules/indexes/getting_started.html
1795792d35ec-3
) Hopefully this highlights what is going on under the hood of VectorstoreIndexCreator. While we think it’s important to have a simple way to create indexes, we also think it’s important to understand what’s going on under the hood. previous Indexes next Key Concepts Contents One Line Index Creation Walkthrough By ...
https://langchain.readthedocs.io/en/latest/modules/indexes/getting_started.html
3b75d7ce3247-0
.md .pdf CombineDocuments Chains Contents Stuffing Map Reduce Refine Map-Rerank CombineDocuments Chains# CombineDocuments chains are useful for when you need to run a language over multiple documents. Common use cases for this include question answering, question answering with sources, summarization, and more. For m...
https://langchain.readthedocs.io/en/latest/modules/indexes/combine_docs.html
3b75d7ce3247-1
This method involves running an initial prompt on each chunk of data (for summarization tasks, this could be a summary of that chunk; for question-answering tasks, it could be an answer based solely on that chunk). Then a different prompt is run to combine all the initial outputs. This is implemented in the LangChain a...
https://langchain.readthedocs.io/en/latest/modules/indexes/combine_docs.html
3b75d7ce3247-2
Stuffing Map Reduce Refine Map-Rerank By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/indexes/combine_docs.html
7573557c0053-0
.ipynb .pdf FAISS Contents Similarity Search with score Saving and loading Merging FAISS# This notebook shows how to use functionality related to the FAISS vector database. from langchain.embeddings.openai import OpenAIEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores im...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/faiss.html
7573557c0053-1
Similarity Search with score# There are some FAISS specific methods. One of them is similarity_search_with_score, which allows you to return not only the documents but also the similarity score of the query to them. docs_and_scores = db.similarity_search_with_score(query) docs_and_scores[0] (Document(page_content='In s...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/faiss.html
7573557c0053-2
db.save_local("faiss_index") new_db = FAISS.load_local("faiss_index", embeddings) docs = new_db.similarity_search(query) docs[0] Document(page_content='In state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections. \n\nWe cannot let this happen. \n\nTonight. I call on t...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/faiss.html
7573557c0053-3
db2.docstore._dict {'bdc50ae3-a1bb-4678-9260-1b0979578f40': Document(page_content='bar', lookup_str='', metadata={}, lookup_index=0)} db1.merge_from(db2) db1.docstore._dict {'e0b74348-6c93-4893-8764-943139ec1d17': Document(page_content='foo', lookup_str='', metadata={}, lookup_index=0), 'd5211050-c777-493d-8825-4800e7...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/faiss.html
f6b12f046b77-0
.ipynb .pdf AtlasDB AtlasDB# This notebook shows you how to use functionality related to the AtlasDB import time from langchain.embeddings.openai import OpenAIEmbeddings from langchain.text_splitter import SpacyTextSplitter from langchain.vectorstores import AtlasDB from langchain.document_loaders import TextLoader !py...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/atlas.html
f6b12f046b77-1
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/atlas.html
ed72051b4880-0
.ipynb .pdf PGVector Contents Similarity search with score Similarity Search with Euclidean Distance (Default) PGVector# This notebook shows how to use functionality related to the Postgres vector database (PGVector). ## Loading Environment Variables from typing import List, Tuple from dotenv import load_dotenv load_...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/pgvector.html
ed72051b4880-1
# permission to create a table. db = PGVector.from_documents( embedding=embeddings, documents=docs, collection_name="state_of_the_union", connection_string=CONNECTION_STRING, ) query = "What did the president say about Ketanji Brown Jackson" docs_with_score: List[Tuple[Document, float]] = db.similarity_...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/pgvector.html
ed72051b4880-2
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. One of the most serious constitutional responsibilities a President h...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/pgvector.html
ed72051b4880-3
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. One of the most serious constitutional responsibilities a President h...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/pgvector.html
c9135c148f0e-0
.ipynb .pdf Redis Redis# This notebook shows how to use functionality related to the Redis database. from langchain.embeddings.openai import OpenAIEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores.redis import Redis from langchain.document_loaders import TextLoader loader ...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/redis.html
c9135c148f0e-1
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence. print(rds.add_texts(["Ankush went to Princeton"])) ['doc:333eadf75bd74be393acafa8bca48669'] query = "Princeton" results = rds.si...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/redis.html
dc04d859880b-0
.ipynb .pdf Qdrant Qdrant# This notebook shows how to use functionality related to the Qdrant vector database. from langchain.embeddings.openai import OpenAIEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import Qdrant from langchain.document_loaders import TextLoader fr...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/qdrant.html
c17384b63945-0
.ipynb .pdf Milvus Milvus# This notebook shows how to use functionality related to the Milvus vector database. To run, you should have a Milvus instance up and running: https://milvus.io/docs/install_standalone-docker.md from langchain.embeddings.openai import OpenAIEmbeddings from langchain.text_splitter import Charac...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/milvus.html
004d0bb8a134-0
.ipynb .pdf Chroma Contents Similarity search with score Persistance Initialize PeristedChromaDB Persist the Database Load the Database from disk, and create the chain Chroma# This notebook shows how to use functionality related to the Chroma vector database. from langchain.embeddings.openai import OpenAIEmbeddings f...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/chroma.html
004d0bb8a134-1
One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of ...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/chroma.html
004d0bb8a134-2
# Embed and store the texts # Supplying a persist_directory will store the embeddings on disk persist_directory = 'db' embedding = OpenAIEmbeddings() vectordb = Chroma.from_documents(documents=docs, embedding=embedding, persist_directory=persist_directory) Running Chroma using direct local API. No existing DB found in ...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/chroma.html
44183cbbeefb-0
.ipynb .pdf Deep Lake Contents Deep Lake datasets on cloud or local Deep Lake# This notebook showcases basic functionality related to Deep Lake. While Deep Lake can store embeddings, it is capable of storing any type of data. It is a fully fledged serverless data lake with version control, query engine and streaming ...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/deeplake.html
44183cbbeefb-1
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. One of the most serious constitutional responsibilities a President h...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/deeplake.html
44183cbbeefb-2
We cannot let this happen. Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justi...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/deeplake.html
0d94ef8821b0-0
.ipynb .pdf Weaviate Weaviate# This notebook shows how to use functionality related to the Weaviate vector database. from langchain.embeddings.openai import OpenAIEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import Weaviate from langchain.document_loaders import TextL...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/weaviate.html
0d94ef8821b0-1
}, ], }, ] } client.schema.create(schema) vectorstore = Weaviate(client, "Paragraph", "content") query = "What did the president say about Ketanji Brown Jackson" docs = vectorstore.similarity_search(query) print(docs[0].page_content) previous Redis next Analyze Document By Harrison Chase ...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/weaviate.html
af0e26b20a3d-0
.ipynb .pdf OpenSearch Contents similarity_search using Approximate k-NN Search with Custom Parameters similarity_search using Script Scoring with Custom Parameters similarity_search using Painless Scripting with Custom Parameters OpenSearch# This notebook shows how to use functionality related to the OpenSearch data...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/opensearch.html
af0e26b20a3d-1
query = "What did the president say about Ketanji Brown Jackson" docs = docsearch.similarity_search(query) print(docs[0].page_content) similarity_search using Script Scoring with Custom Parameters# docsearch = OpenSearchVectorSearch.from_texts(texts, embeddings, opensearch_url="http://localhost:9200", is_appx_search=Fa...
https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/opensearch.html