id
stringlengths
14
16
text
stringlengths
29
2.73k
source
stringlengths
49
115
f75e4162db06-0
.ipynb .pdf LLMRequestsChain LLMRequestsChain# Using the request library to get HTML results from a URL and then an LLM to parse results from langchain.llms import OpenAI from langchain.chains import LLMRequestsChain, LLMChain from langchain.prompts import PromptTemplate template = """Between >>> and <<< are the raw se...
https://python.langchain.com/en/latest/modules/chains/examples/llm_requests.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
3f5fef2395d5-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://python.langchain.com/en/latest/modules/chains/examples/api.html
883bc7c20772-0
.ipynb .pdf OpenAPI Chain Contents Load the spec Select the Operation Construct the chain Return raw response Example POST message OpenAPI Chain# This notebook shows an example of using an OpenAPI chain to call an endpoint in natural language, and get back a response in natural language. from langchain.tools import O...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-1
llm, requests=Requests(), verbose=True, return_intermediate_steps=True # Return request and response text ) output = chain("whats the most expensive shirt?") > Entering new OpenAPIEndpointChain chain... > Entering new APIRequesterChain chain... Prompt after formatting: You are a helpful AI Assistant. Plea...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-2
ARGS: ```json {valid json conforming to API_SCHEMA} ``` Example ----- ARGS: ```json {"foo": "bar", "baz": {"qux": "quux"}} ``` The block must be no more than 1 line long, and all arguments must be valid JSON. All string arguments must be wrapped in double quotes. You MUST strictly comply to the types indicated by the p...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-3
You attempted to call an API, which resulted in: API_RESPONSE: {"products":[{"name":"Burberry Check Poplin Shirt","url":"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin","price":"$360.00","attributes":["Material:Cotton","Target Grou...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-4
'response_text': '{"products":[{"name":"Burberry Check Poplin Shirt","url":"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin","price":"$360.00","attributes":["Material:Cotton","Target Group:Man","Color:Gray,Blue,Beige","Properties:Po...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-5
q: string, /* number of products returned */ size?: number, /* (Optional) Minimum price in local currency for the product searched for. Either explicitly stated by the user or implicitly inferred from a combination of the user's request and the kind of product searched for. */ min_price?: number, /* (Optional) Maxi...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-6
{"products":[{"name":"Burberry Check Poplin Shirt","url":"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin","price":"$360.00","attributes":["Material:Cotton","Target Group:Man","Color:Gray,Blue,Beige","Properties:Pockets","Pattern:Ch...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-7
Somerton Check Shirt - Camel","url":"https://www.klarna.com/us/shopping/pl/cl10001/3201112728/Clothing/Burberry-Somerton-Check-Shirt-Camel/?utm_source=openai&ref-site=openai_plugin","price":"$450.00","attributes":["Material:Elastane/Lycra/Spandex,Cotton","Target Group:Man","Color:Beige"]},{"name":"Magellan Outdoors Lag...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-8
> Finished chain. output {'instructions': 'whats the most expensive shirt?',
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-9
'output': '{"products":[{"name":"Burberry Check Poplin Shirt","url":"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin","price":"$360.00","attributes":["Material:Cotton","Target Group:Man","Color:Gray,Blue,Beige","Properties:Pockets",...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-10
Somerton Check Shirt - Camel","url":"https://www.klarna.com/us/shopping/pl/cl10001/3201112728/Clothing/Burberry-Somerton-Check-Shirt-Camel/?utm_source=openai&ref-site=openai_plugin","price":"$450.00","attributes":["Material:Elastane/Lycra/Spandex,Cotton","Target Group:Man","Color:Beige"]},{"name":"Magellan Outdoors Lag...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-11
'intermediate_steps': {'request_args': '{"q": "shirt", "max_price": null}',
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-12
'response_text': '{"products":[{"name":"Burberry Check Poplin Shirt","url":"https://www.klarna.com/us/shopping/pl/cl10001/3201810981/Clothing/Burberry-Check-Poplin-Shirt/?utm_source=openai&ref-site=openai_plugin","price":"$360.00","attributes":["Material:Cotton","Target Group:Man","Color:Gray,Blue,Beige","Properties:Po...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-13
Somerton Check Shirt - Camel","url":"https://www.klarna.com/us/shopping/pl/cl10001/3201112728/Clothing/Burberry-Somerton-Check-Shirt-Camel/?utm_source=openai&ref-site=openai_plugin","price":"$450.00","attributes":["Material:Elastane/Lycra/Spandex,Cotton","Target Group:Man","Color:Beige"]},{"name":"Magellan Outdoors Lag...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-14
Example POST message# For this demo, we will interact with the speak API. spec = OpenAPISpec.from_url("https://api.speak.com/openapi.yaml") Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support. Attempting to load an OpenAPI 3.0.1 ...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-15
learning_language?: string, /* The user's native language. Infer this value from the language the user asked their question in. Always use the full name of the language (e.g. Spanish, French). */ native_language?: string, /* A description of any additional context in the user's question that could affect the explanat...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-16
{"explanation":"<what-to-say language=\"Hindi\" context=\"None\">\nऔर चाय लाओ। (Aur chai lao.) \n</what-to-say>\n\n<alternatives context=\"None\">\n1. \"चाय थोड़ी ज्यादा मिल सकती है?\" *(Chai thodi zyada mil sakti hai? - Polite, asking if more tea is available)*\n2. \"मुझे महसूस हो रहा है कि मुझे कुछ अन्य प्रकार की चाय...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-17
tone, asking for an extra serving of milk or tea powder)*\n</alternatives>\n\n<usage-notes>\nIn India and Indian culture, serving guests with food and beverages holds great importance in hospitality. You will find people always offering drinks like water or tea to their guests as soon as they arrive at their house or o...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-18
an issue or leave feedback](https://speak.com/chatgpt?rid=d4mcapbkopo164pqpbk321oc})*","extra_response_instructions":"Use all information in the API response and fully render all Markdown.\nAlways end your response with a link to report an issue or leave feedback on the plugin."}
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-19
> Entering new APIResponderChain chain... Prompt after formatting: You are a helpful AI assistant trained to answer user queries from API responses. You attempted to call an API, which resulted in:
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-20
API_RESPONSE: {"explanation":"<what-to-say language=\"Hindi\" context=\"None\">\nऔर चाय लाओ। (Aur chai lao.) \n</what-to-say>\n\n<alternatives context=\"None\">\n1. \"चाय थोड़ी ज्यादा मिल सकती है?\" *(Chai thodi zyada mil sakti hai? - Polite, asking if more tea is available)*\n2. \"मुझे महसूस हो रहा है कि मुझे कुछ अन्य...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-21
tone, asking for an extra serving of milk or tea powder)*\n</alternatives>\n\n<usage-notes>\nIn India and Indian culture, serving guests with food and beverages holds great importance in hospitality. You will find people always offering drinks like water or tea to their guests as soon as they arrive at their house or o...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-22
an issue or leave feedback](https://speak.com/chatgpt?rid=d4mcapbkopo164pqpbk321oc})*","extra_response_instructions":"Use all information in the API response and fully render all Markdown.\nAlways end your response with a link to report an issue or leave feedback on the plugin."}
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-23
USER_COMMENT: "How would ask for more tea in Delhi?" If the API_RESPONSE can answer the USER_COMMENT respond with the following markdown json block: Response: ```json {"response": "Concise response to USER_COMMENT based on API_RESPONSE."} ``` Otherwise respond with the following markdown json block: Response Error: ```...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-24
'{"explanation":"<what-to-say language=\\"Hindi\\" context=\\"None\\">\\nऔर चाय लाओ। (Aur chai lao.) \\n</what-to-say>\\n\\n<alternatives context=\\"None\\">\\n1. \\"चाय थोड़ी ज्यादा मिल सकती है?\\" *(Chai thodi zyada mil sakti hai? - Polite, asking if more tea is available)*\\n2. \\"मुझे महसूस हो रहा है कि मुझे कुछ अन...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-25
- Very informal/casual tone, asking for an extra serving of milk or tea powder)*\\n</alternatives>\\n\\n<usage-notes>\\nIn India and Indian culture, serving guests with food and beverages holds great importance in hospitality. You will find people always offering drinks like water or tea to their guests as soon as they...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-26
add a little extra in the quantity of tea as well.)\\n</example-convo>\\n\\n*[Report an issue or leave feedback](https://speak.com/chatgpt?rid=d4mcapbkopo164pqpbk321oc})*","extra_response_instructions":"Use all information in the API response and fully render all Markdown.\\nAlways end your response with a link to repo...
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
883bc7c20772-27
previous Moderation next PAL Contents Load the spec Select the Operation Construct the chain Return raw response Example POST message By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https://python.langchain.com/en/latest/modules/chains/examples/openapi.html
f0ffb5232a92-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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-6
• Exoplanets were first discovered in 1992. - True • The JWST has allowed us to see exoplanets in greater detail. - Undetermined. The JWST has not yet been launched, so it is not yet known how much detail it will be able to provide. """ Original Summary: """ Your 9-year old might like these recent discoveries made by ...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-7
""" Result: False === 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 Telesco...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-8
• Exoplanets, which are planets outside of our own solar system, were first discovered in 1992. The JWST will allow us to see them in greater detail when it is launched in 2023. These discoveries can spark a child's imagination about the infinite wonders of the universe. > Finished chain. 'Your 9-year old might like th...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-9
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 one of five oceans in the world, alongside the Pacific Ocean, Atlantic Ocean, Indian Ocean, and the Southern Ocean. It is the smalle...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-10
> 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 Greenland Sea is an outlying portion of the Arctic Ocean located between Icel...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-11
- 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, Indian Ocean, and the Southern Ocean. False - The Greenland Sea is not an ocean, it is an arm of the Arctic Ocean. - It is the smallest of the five oceans. False - The Greenland Sea is no...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-12
Below are some assertions that have been fact checked and are labeled as true or 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: """ - The sky is red: False - Water is made of lava: False - The sun is a star: Tr...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-13
""" 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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-14
- It has an area of 465,000 square miles. - It is an arm of the Arctic Ocean. - It is covered almost entirely by water, some of which is frozen in the form of glaciers and icebergs. - It is named after the island of Greenland. - It is the Arctic Ocean's main outlet to the Atlantic. - It is often frozen over so navigati...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-15
""" 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 glacier...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-16
- It has an area of 465,000 square miles. True - It is an arm of the Arctic Ocean. True - It is covered almost entirely by water, some of which is frozen in the form of glaciers and icebergs. True - It is named after the island of Greenland. False - It is named after the country of Greenland. - It is the Arctic Ocean's...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-17
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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-18
> 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 loca...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-19
> Finished chain. > Entering new LLMChain chain... Prompt after formatting: Below are some assertions that have been fact checked and are labeled as true or 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://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-20
""" 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 covered almost entirely by water, some of which is frozen in the form of glaciers and iceber...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-21
Format your output as a bulleted list. Text: """ Mammals can lay eggs, birds can lay eggs, therefore birds are mammals. """ Facts: > 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 s...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-22
Below are some assertions that have been fact checked and are labeled as true or 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: """ - The sky is red: False - Water is made of lava: False - The sun is a star: Tr...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-23
> 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: """ - Birds and mammals are both capable of laying eggs. - Birds are not mammals. - Bir...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
f0ffb5232a92-24
Here are some examples: === Checked Assertions: """ - The sky is red: False - Water is made of lava: False - The sun is a star: True """ Result: False === 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 ...
https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html
72e9fcdbe94c-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://python.langchain.com/en/latest/modules/chains/examples/moderation.html
72e9fcdbe94c-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://python.langchain.com/en/latest/modules/chains/examples/moderation.html
72e9fcdbe94c-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://python.langchain.com/en/latest/modules/chains/examples/moderation.html
72e9fcdbe94c-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://python.langchain.com/en/latest/modules/chains/examples/moderation.html
72e9fcdbe94c-4
chain(inputs, return_only_outputs=True) {'sanitized_text': "Text was found that violates OpenAI's content policy."} previous LLMSummarizationCheckerChain next OpenAPI Chain Contents How to use the moderation chain How to append a Moderation chain to an LLMChain By Harrison Chase © Copyright 2023, Harriso...
https://python.langchain.com/en/latest/modules/chains/examples/moderation.html
26893ddc5d2a-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.from_llm(llm, verbose=True) ch...
https://python.langchain.com/en/latest/modules/chains/examples/llm_checker.html
5b698e595549-0
.ipynb .pdf PAL Contents Math Prompt Colored Objects Intermediate Steps PAL# Implements Program-Aided Language Models, as in https://arxiv.org/pdf/2211.10435.pdf. from langchain.chains import PALChain from langchain import OpenAI llm = OpenAI(temperature=0, max_tokens=512) Math Prompt# pal_chain = PALChain.from_math_...
https://python.langchain.com/en/latest/modules/chains/examples/pal.html
5b698e595549-1
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 object[1] == 'purple']) answer = num_purple > Finishe...
https://python.langchain.com/en/latest/modules/chains/examples/pal.html
5b698e595549-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://python.langchain.com/en/latest/modules/chains/examples/pal.html
53e7edb1589a-0
.ipynb .pdf SQL Chain example Contents Customize Prompt Return Intermediate Steps Choosing how to limit the number of rows returned Adding example rows from each table Custom Table Info SQLDatabaseSequentialChain SQL Chain example# This example demonstrates the use of the SQLDatabaseChain for answering questions over...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-1
How many employees are there? SQLQuery: /Users/harrisonchase/workplace/langchain/langchain/sql_database.py:120: SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal n...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-2
SQLQuery: SELECT COUNT(*) FROM Employee; SQLResult: [(8,)] Answer: There are 8 employees in the foobar table. > Finished chain. ' There are 8 employees in the foobar table.' Return Intermediate Steps# You can also return the intermediate steps of the SQLDatabaseChain. This allows you to access the SQL statement that wa...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-3
SQLResult: [('Concerto for 2 Violins in D Minor, BWV 1043: I. Vivace', 'Johann Sebastian Bach'), ('Aria Mit 30 Veränderungen, BWV 988 "Goldberg Variations": Aria', 'Johann Sebastian Bach'), ('Suite for Solo Cello No. 1 in G Major, BWV 1007: I. Prélude', 'Johann Sebastian Bach')] Answer: Some example tracks by composer ...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-4
include_tables=['Track'], # we include only one table to save tokens in the prompt :) sample_rows_in_table_info=2) The sample rows are added to the prompt after each corresponding table’s column information: print(db.table_info) CREATE TABLE "Track" ( "TrackId" INTEGER NOT NULL, "Name" NVARCHAR(200) NOT NULL, ...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-5
sample_rows = connection.execute(command) db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True) db_chain.run("What are some example tracks by Bach?") > Entering new SQLDatabaseChain chain... What are some example tracks by Bach? SQLQuery: SELECT Name FROM Track WHERE Composer LIKE '%Bach%' LIMIT 5; SQLResult: [(...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-6
> Finished chain. ' Some example tracks by Bach are \'American Woman\', \'Concerto for 2 Violins in D Minor, BWV 1043: I. Vivace\', \'Aria Mit 30 Veränderungen, BWV 988 "Goldberg Variations": Aria\', \'Suite for Solo Cello No. 1 in G Major, BWV 1007: I. Prélude\', and \'Toccata and Fugue in D Minor, BWV 565: I. Toccata...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-7
*/""" } db = SQLDatabase.from_uri( "sqlite:///../../../../notebooks/Chinook.db", include_tables=['Track', 'Playlist'], sample_rows_in_table_info=2, custom_table_info=custom_table_info) print(db.table_info) CREATE TABLE "Playlist" ( "PlaylistId" INTEGER NOT NULL, "Name" NVARCHAR(120), PRIMARY KEY ("...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-8
SQLQuery: SELECT Name, Composer FROM Track WHERE Composer LIKE '%Bach%' LIMIT 5; SQLResult: [('American Woman', 'B. Cummings/G. Peterson/M.J. Kale/R. Bachman'), ('Concerto for 2 Violins in D Minor, BWV 1043: I. Vivace', 'Johann Sebastian Bach'), ('Aria Mit 30 Veränderungen, BWV 988 "Goldberg Variations": Aria', 'Johann...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
53e7edb1589a-9
SQLDatabaseSequentialChain# Chain for querying SQL database that is a sequential chain. The chain is as follows: 1. Based on the query, determine which tables to use. 2. Based on those tables, call the normal SQL database chain. This is useful in cases where the number of tables in the database is large. from langchain...
https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html
0b1ae01c4dad-0
.ipynb .pdf LLM Math LLM Math# This notebook showcases using LLMs and Python REPLs to do complex word math problems. from langchain import OpenAI, LLMMathChain llm = OpenAI(temperature=0) llm_math = LLMMathChain.from_llm(llm, verbose=True) llm_math.run("What is 13 raised to the .3432 power?") > Entering new LLMMathChai...
https://python.langchain.com/en/latest/modules/chains/examples/llm_math.html
20a6aca8ea30-0
.ipynb .pdf Self-Critique Chain with Constitutional AI Contents Intermediate Steps No revision necessary 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...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
20a6aca8ea30-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, and should not be condoned. Updated response: It is illegal and unethical to steal kittens. If ...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
20a6aca8ea30-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://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
20a6aca8ea30-3
'It is illegal and unethical to steal kittens. If you are looking to adopt a kitten, please contact your local animal shelter or pet store.')]} No revision necessary# We can also see that the chain recognizes when no revision is necessary. good_qa_prompt = PromptTemplate( template="""You are good and must only give...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
20a6aca8ea30-4
'critiques_and_revisions': [('No critique needed.', '')]} previous API Chains next BashChain Contents Intermediate Steps No revision necessary By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
e3a438758264-0
.ipynb .pdf BashChain Contents Customize Prompt Persistent Terminal BashChain# This notebook showcases using LLMs and a bash process to 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 pr...
https://python.langchain.com/en/latest/modules/chains/examples/llm_bash.html
e3a438758264-1
Do not use 'echo' when writing the script. That is the format. Begin! Question: {question}""" PROMPT = PromptTemplate(input_variables=["question"], template=_PROMPT_TEMPLATE, output_parser=BashOutputParser()) bash_chain = LLMBashChain.from_llm(llm, prompt=PROMPT, verbose=True) text = "Please write a bash script that pr...
https://python.langchain.com/en/latest/modules/chains/examples/llm_bash.html
e3a438758264-2
llm_requests.ipynb sqlite.ipynb > Finished chain. 'api.ipynb\t\t\tllm_summarization_checker.ipynb\r\nconstitutional_chain.ipynb\tmoderation.ipynb\r\nllm_bash.ipynb\t\t\topenai_openapi.yaml\r\nllm_checker.ipynb\t\topenapi.ipynb\r\nllm_math.ipynb\t\t\tpal.ipynb\r\nllm_requests.ipynb\t\tsqlite.ipynb' # Run the same comma...
https://python.langchain.com/en/latest/modules/chains/examples/llm_bash.html
d564fca063c0-0
.ipynb .pdf Summarization Contents Prepare Data Quickstart The stuff Chain The map_reduce Chain The refine Chain Summarization# This notebook walks through how to use LangChain for summarization over a list of documents. It covers three different chain types: stuff, map_reduce, and refine. For a more in depth explana...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
d564fca063c0-1
chain.run(docs) ' In response to Russian aggression in Ukraine, the United States and its allies are taking action to hold Putin accountable, including economic sanctions, asset seizures, and military assistance. The US is also providing economic and humanitarian aid to Ukraine, and has passed the American Rescue Plan ...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
d564fca063c0-2
chain.run(docs) "\n\nIn questa serata, il Presidente degli Stati Uniti ha annunciato una serie di misure per affrontare la crisi in Ucraina, causata dall'aggressione di Putin. Ha anche annunciato l'invio di aiuti economici, militari e umanitari all'Ucraina. Ha anche annunciato che gli Stati Uniti e i loro alleati stann...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
d564fca063c0-3
chain = load_summarize_chain(OpenAI(temperature=0), chain_type="map_reduce", return_intermediate_steps=True) chain({"input_documents": docs}, return_only_outputs=True) {'map_steps': [" In response to Russia's aggression in Ukraine, the United States has united with other freedom-loving nations to impose economic sancti...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
d564fca063c0-4
prompt_template = """Write a concise summary of the following: {text} CONCISE SUMMARY IN ITALIAN:""" PROMPT = PromptTemplate(template=prompt_template, input_variables=["text"]) chain = load_summarize_chain(OpenAI(temperature=0), chain_type="map_reduce", return_intermediate_steps=True, map_prompt=PROMPT, combine_prompt=...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html