id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
59
127
13efa52e14c6-11
'stop': ['\nSQLResult:']}, 'SELECT COUNT(*) FROM Employee;', {'query': 'SELECT COUNT(*) FROM Employee;', 'dialect': 'sqlite'}, 'SELECT COUNT(*) FROM Employee;', '[(8,)]'] Choosing how to limit the number of rows returned# If you are querying for several rows of a table you can select the maximum number of results y...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-12
> Finished chain. 'Examples of tracks by Johann Sebastian Bach are Concerto for 2 Violins in D Minor, BWV 1043: I. Vivace, Aria Mit 30 Veränderungen, BWV 988 "Goldberg Variations": Aria, and Suite for Solo Cello No. 1 in G Major, BWV 1007: I. Prélude.' Adding example rows from each table# Sometimes, the format of the d...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-13
FOREIGN KEY("GenreId") REFERENCES "Genre" ("GenreId"), FOREIGN KEY("AlbumId") REFERENCES "Album" ("AlbumId") ) /* 2 rows from Track table: TrackId Name AlbumId MediaTypeId GenreId Composer Milliseconds Bytes UnitPrice 1 For Those About To Rock (We Salute You) 1 1 1 Angus Young, Malcolm Young, Brian Johnson 343719 111...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-14
Answer:Tracks by Bach include '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'. > Finished chain. 'Tracks by...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-15
"TrackId" INTEGER NOT NULL, "Name" NVARCHAR(200) NOT NULL, "Composer" NVARCHAR(220), PRIMARY KEY ("TrackId") ) /* 3 rows from Track table: TrackId Name Composer 1 For Those About To Rock (We Salute You) Angus Young, Malcolm Young, Brian Johnson 2 Balls to the Wall None 3 My favorite song ever The coolest composer o...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-16
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: [('American Woman',), ('Concerto for 2 Vio...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-17
Answer:text='You are a SQLite expert. Given an input question, first create a syntactically correct SQLite query to run, then look at the results of the query and return the answer to the input question.\nUnless the user specifies in the question a specific number of examples to obtain, query for at most 5 results usin...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-18
Young, Brian Johnson\n2\tBalls to the Wall\tNone\n3\tMy favorite song ever\tThe coolest composer of all time\n*/\n\nQuestion: What are some example tracks by Bach?\nSQLQuery:SELECT "Name" FROM Track WHERE "Composer" LIKE \'%Bach%\' LIMIT 5;\nSQLResult: [(\'American Woman\',), (\'Concerto for 2 Violins in D Minor, BWV 1...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-19
You are a SQLite expert. Given an input question, first create a syntactically correct SQLite query to run, then look at the results of the query and return the answer to the input question. Unless the user specifies in the question a specific number of examples to obtain, query for at most 5 results using the LIMIT cl...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-20
*/ Question: What are some example tracks by Bach? SQLQuery:SELECT "Name" FROM Track WHERE "Composer" LIKE '%Bach%' LIMIT 5; SQLResult: [('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 ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-21
Answer: {'input': 'What are some example tracks by Bach?\nSQLQuery:SELECT "Name" FROM Track WHERE "Composer" LIKE \'%Bach%\' LIMIT 5;\nSQLResult: [(\'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 Sol...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-22
Examples of tracks by Bach include "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". > Finished chain. 'Exam...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-23
> Entering new SQLDatabaseChain chain... How many employees are also customers? SQLQuery:SELECT COUNT(*) FROM Employee e INNER JOIN Customer c ON e.EmployeeId = c.SupportRepId; SQLResult: [(59,)] Answer:59 employees are also customers. > Finished chain. > Finished chain. '59 employees are also customers.' Using Local L...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-24
local_llm = HuggingFacePipeline(pipeline=pipe) /workspace/langchain/.venv/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm Loading check...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-25
SELECT count(*) FROM Customer SQLResult: [(59,)] Answer: /workspace/langchain/.venv/lib/python3.9/site-packages/transformers/pipelines/base.py:1070: UserWarning: You seem to be using the pipelines sequentially on GPU. In order to maximize efficiency please use a dataset warnings.warn( [59] > Finished chain. {'query':...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-26
'table_info': '\nCREATE TABLE "Customer" (\n\t"CustomerId" INTEGER NOT NULL, \n\t"FirstName" NVARCHAR(40) NOT NULL, \n\t"LastName" NVARCHAR(20) NOT NULL, \n\t"Company" NVARCHAR(80), \n\t"Address" NVARCHAR(70), \n\t"City" NVARCHAR(40), \n\t"State" NVARCHAR(40), \n\t"Country" NVARCHAR(40), \n\t"PostalCode" NVARCHAR(10), ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-27
rue Bélanger\tMontréal\tQC\tCanada\tH2G 1A7\t+1 (514) 721-4711\tNone\tftremblay@gmail.com\t3\n*/',
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-28
'stop': ['\nSQLResult:']}, 'SELECT count(*) FROM Customer', {'query': 'SELECT count(*) FROM Customer', 'dialect': 'sqlite'}, 'SELECT count(*) FROM Customer', '[(59,)]']} Even this relatively large model will most likely fail to generate more complicated SQL by itself. However, you can log its inputs and outputs...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-29
Requirement already satisfied: pydantic>=1.9 in /workspace/langchain/.venv/lib/python3.9/site-packages (from chromadb) (1.10.7) Requirement already satisfied: hnswlib>=0.7 in /workspace/langchain/.venv/lib/python3.9/site-packages (from chromadb) (0.7.0) Requirement already satisfied: clickhouse-connect>=0.5.7 in /works...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-30
Requirement already satisfied: certifi in /workspace/langchain/.venv/lib/python3.9/site-packages (from clickhouse-connect>=0.5.7->chromadb) (2022.12.7) Requirement already satisfied: urllib3>=1.26 in /workspace/langchain/.venv/lib/python3.9/site-packages (from clickhouse-connect>=0.5.7->chromadb) (1.26.15) Requirement ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-31
Requirement already satisfied: six>=1.5 in /workspace/langchain/.venv/lib/python3.9/site-packages (from posthog>=2.4.0->chromadb) (1.16.0) Requirement already satisfied: monotonic>=1.5 in /workspace/langchain/.venv/lib/python3.9/site-packages (from posthog>=2.4.0->chromadb) (1.6) Requirement already satisfied: backoff>...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-32
Requirement already satisfied: torch>=1.6.0 in /workspace/langchain/.venv/lib/python3.9/site-packages (from sentence-transformers>=2.2.2->chromadb) (1.13.1) Requirement already satisfied: torchvision in /workspace/langchain/.venv/lib/python3.9/site-packages (from sentence-transformers>=2.2.2->chromadb) (0.14.1) Require...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-33
Requirement already satisfied: h11>=0.8 in /workspace/langchain/.venv/lib/python3.9/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.14.0) Requirement already satisfied: httptools>=0.5.0 in /workspace/langchain/.venv/lib/python3.9/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.5.0) Requirement a...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-34
Requirement already satisfied: packaging>=20.9 in /workspace/langchain/.venv/lib/python3.9/site-packages (from huggingface-hub>=0.4.0->sentence-transformers>=2.2.2->chromadb) (23.1) Requirement already satisfied: anyio<5,>=3.4.0 in /workspace/langchain/.venv/lib/python3.9/site-packages (from starlette<0.27.0,>=0.26.1->...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-35
Requirement already satisfied: setuptools in /workspace/langchain/.venv/lib/python3.9/site-packages (from nvidia-cublas-cu11==11.10.3.66->torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (67.7.1) Requirement already satisfied: wheel in /workspace/langchain/.venv/lib/python3.9/site-packages (from nvidia-cublas-cu11...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-36
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /workspace/langchain/.venv/lib/python3.9/site-packages (from torchvision->sentence-transformers>=2.2.2->chromadb) (9.5.0) Requirement already satisfied: sniffio>=1.1 in /workspace/langchain/.venv/lib/python3.9/site-packages (from anyio<5,>=3.4.0->starlette<0.27.0,...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-37
answer_key = sql_cmd_key # this is the SQL generation input if step[input_key].endswith("Answer:"): answer_key = final_answer_key # this is the final answer input elif sql_cmd_key in step: _example[sql_cmd_key] = step[sql_cmd_key] answer_ke...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-38
warnings.warn( SELECT firstname FROM customer WHERE firstname LIKE '%a%' SQLResult: [('François',), ('František',), ('Helena',), ('Astrid',), ('Daan',), ('Kara',), ('Eduardo',), ('Alexandre',), ('Fernanda',), ('Mark',), ('Frank',), ('Jack',), ('Dan',), ('Kathy',), ('Heather',), ('Frank',), ('Richard',), ('Patrick',), (...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-39
warnings.warn( [('François', 'Frantiek', 'Helena', 'Astrid', 'Daan', 'Kara', 'Eduardo', 'Alexandre', 'Fernanda', 'Mark', 'Frank', 'Jack', 'Dan', 'Kathy', 'Heather', 'Frank', 'Richard', 'Patrick', 'Julia', 'Edward', 'Martha', 'Aaron', 'Madalena', 'Hannah', 'Niklas', 'Camille', 'Marc', 'Wyatt', 'Isabelle', 'Ladislav', 'L...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-40
sql_cmd: SELECT firstname FROM customer WHERE firstname LIKE '%a%' sql_result: '[(''François'',), (''František'',), (''Helena'',), (''Astrid'',), (''Daan'',), (''Kara'',), (''Eduardo'',), (''Alexandre'',), (''Fernanda'',), (''Mark'',), (''Frank'',), (''Jack'',), (''Dan'',), (''Kathy'',), (''Heather'',), (''Frank'',...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-41
\ \n\t\"Phone\" NVARCHAR(24), \n\t\"Fax\" NVARCHAR(24), \n\t\"Email\" NVARCHAR(60)\ \ NOT NULL, \n\t\"SupportRepId\" INTEGER, \n\tPRIMARY KEY (\"CustomerId\"), \n\t\ FOREIGN KEY(\"SupportRepId\") REFERENCES \"Employee\" (\"EmployeeId\")\n)\n\n/*\n\ 3 rows from Customer table:\nCustomerId\tFirstName\tLastName\tCom...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-42
None\tftremblay@gmail.com\t3\n*/" Run the snippet above a few times, or log exceptions in your deployed environment, to collect lots of examples of inputs, table_info and sql_cmd generated by your language model. The sql_cmd values will be incorrect and you can manually fix them up to build a collection of examples, e....
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-43
CREATE TABLE "Genre" ( "GenreId" INTEGER NOT NULL, "Name" NVARCHAR(120), PRIMARY KEY ("GenreId") ) /* 3 rows from Genre table: GenreId Name 1 Rock 2 Jazz 3 Metal */ sql_cmd: SELECT "Name" FROM "Genre" WHERE "Name" LIKE 'r%'; sql_result: "[('Rock',), ('Rock and Rol...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-44
# This is the list of examples available to select from. examples_dict, # This is the embedding class used to produce embeddings which are used to measure semantic similarity. local_embeddings, # This is the VectorStore clas...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
13efa52e14c6-45
Answer:54 customers are not from Brazil. > Finished chain. result = local_chain("How many customers are there in total?") > Entering new SQLDatabaseChain chain... How many customers are there in total? SQLQuery:SELECT count(*) FROM Customer; SQLResult: [(59,)] Answer:There are 59 customers in total. > Finished chain. p...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/sqlite.html
565d48c25401-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-3
The Way of Water","video":false,"vote_average":7.7,"vote_count":4219},{"adult":false,"backdrop_path":"/uEwGFGtao9YG2JolmdvtHLLVbA9.jpg","genre_ids":[99],"id":111332,"original_language":"en","original_title":"Avatar: Creating the World of Pandora","overview":"The Making-of James Cameron's Avatar. It shows interesting pa...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-4
3","video":false,"vote_average":0,"vote_count":0},{"adult":false,"backdrop_path":null,"genre_ids":[28,878,12,14],"id":216527,"original_language":"en","original_title":"Avatar 4","overview":"","popularity":162.536,"poster_path":"/qzMYKnT4MG1d0gnhwytr4cKhUvS.jpg","release_date":"2026-12-16","title":"Avatar 4","video":fal...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-5
Avatar","video":false,"vote_average":7.8,"vote_count":39},{"adult":false,"backdrop_path":"/eoAvHxfbaPOcfiQyjqypWIXWxDr.jpg","genre_ids":[99],"id":1059673,"original_language":"en","original_title":"Avatar: The Deep Dive - A Special Edition of 20/20","overview":"An inside look at one of the most anticipated movie sequels...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-6
- Au Hellfest 2022","overview":"","popularity":21.992,"poster_path":"/fw6cPIsQYKjd1YVQanG2vLc5HGo.jpg","release_date":"2022-06-26","title":"Avatar - Au Hellfest 2022","video":false,"vote_average":8,"vote_count":4},{"adult":false,"backdrop_path":null,"genre_ids":[],"id":931019,"original_language":"en","original_title":"...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-7
Agni Kai","overview":"","popularity":9.462,"poster_path":"/y9PrKMUTA6NfIe5FE92tdwOQ2sH.jpg","release_date":"2020-01-18","title":"Avatar: Agni Kai","video":false,"vote_average":7,"vote_count":1},{"adult":false,"backdrop_path":"/e8mmDO7fKK93T4lnxl4Z2zjxXZV.jpg","genre_ids":[],"id":668297,"original_language":"en","origina...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-8
the summer of 2001 by drummer John Alfredsson and vocalist Christian Rimmi under the name Lost Soul. The band offers a free mp3 download to a song called \"Bloody Knuckles\" if one subscribes to their newsletter. In 2005 they appeared on the compilation “Listen to Your Inner Voice” together with 17 other bands releas...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-9
the night of madness Avatar performed songs from Black Waltz and Hail The Apocalypse as voted on by the fans.","popularity":2.024,"poster_path":"/wVyTuruUctV3UbdzE5cncnpyNoY.jpg","release_date":"2021-01-23","title":"Avatar Ages: Madness","video":false,"vote_average":8,"vote_count":1},{"adult":false,"backdrop_path":"/dj...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
565d48c25401-10
> 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 ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/api.html
fef96da5a89f-0
.ipynb .pdf Router Chains: Selecting from multiple prompts with MultiRetrievalQAChain Router Chains: Selecting from multiple prompts with MultiRetrievalQAChain# This notebook demonstrates how to use the RouterChain paradigm to create a chain that dynamically selects which Retrieval system to use. Specifically we show h...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/multi_retrieval_qa_router.html
fef96da5a89f-1
"retriever": sou_retriever }, { "name": "pg essay", "description": "Good for answer quesitons about Paul Graham's essay on his career", "retriever": pg_retriever }, { "name": "personal", "description": "Good for answering questions about me", "retrieve...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/multi_retrieval_qa_router.html
fef96da5a89f-2
> Finished chain. Your background is Peruvian. print(chain.run("What year was the Internet created in?")) > Entering new MultiRetrievalQAChain chain... None: {'query': 'What year was the Internet created in?'} > Finished chain. The Internet was created in 1969 through a project called ARPANET, which was funded by the ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/multi_retrieval_qa_router.html
e7b4e13c0b6e-0
.ipynb .pdf Self-Critique Chain with Constitutional AI Contents UnifiedObjective Custom Principles Intermediate Steps No revision necessary All Principles Self-Critique Chain with Constitutional AI# This notebook showcases how to use the ConstitutionalChain. Sometimes LLMs can produce harmful, toxic, or otherwise und...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-1
Updated response: 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. > Finished chain. '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.' Unif...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-2
input_variables=["question"], ) llm = OpenAI(temperature=0) qa_chain = LLMChain(llm=llm, prompt=qa_prompt) query = "should I eat oreos?" qa_chain.run(question=query) ' Yes' principles = ConstitutionalChain.get_principles(["uo-implications-1"]) constitutional_chain = ConstitutionalChain.from_llm( chain=qa_chain, ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-3
revision_request="Rewrite the model's output to be both ethical and legal.", ) constitutional_chain = ConstitutionalChain.from_llm( chain=evil_qa_chain, constitutional_principles=[ethical_principle], llm=llm, verbose=True, ) constitutional_chain.run(question="How can I steal kittens?") > Entering new Co...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-4
Applying Ethical Principle... Critique: The model should not have suggested breaking into a pet store to steal kittens, as this is illegal and unethical. Critique Needed. Updated response: If you are looking to adopt a kitten, please contact your local animal shelter or pet store. Applying Master Yoda Principle... Crit...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-5
'initial_output': ' Break into a pet store at night and take as many kittens as you can carry.', 'critiques_and_revisions': [('The model should not have suggested breaking into a pet store to steal kittens, as this is illegal and unethical. Critique Needed.', 'If you are looking to adopt a kitten, please contact yo...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-6
'initial_output': ' Stealing kittens is illegal and unethical. If you are looking to adopt a kitten, please contact your local animal shelter or rescue organization.', 'critiques_and_revisions': [("The model's response was appropriate and ethical, as it did not condone or encourage the illegal act of stealing kittens....
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-7
'harmful4': ConstitutionalPrinciple(critique_request='Identify specific ways in which the assistant’s precedings response is harmful. Also point out potential harmfulness in the human’s questions and responses. Examples of harm include but are not limited to racism, sexism, toxicity.', revision_request='Rewrite the ass...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-8
'age-innappropriate': ConstitutionalPrinciple(critique_request='Did the assistant’s preceding response include anything that may be inappropriate for young children? If so, discuss how it can be revised to be more appropriate.', revision_request='Please rewrite the assistant response to make it more age appropriate for...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-9
'thoughtful': ConstitutionalPrinciple(critique_request='Please comment on whether the assistant’s last response is thoughtful and empathetic. Does it seem like the kind of thing a sensitive friend or therapist might say? Give the strongest argument you can for how it could improve.', revision_request='Please write a ne...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
e7b4e13c0b6e-10
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html
5c9b811dea96-0
.ipynb .pdf Tagging Contents Simplest approach, only specifying type More control Specifying schema with Pydantic Tagging# The tagging chain uses the OpenAI functions parameter to specify a schema to tag a document with. This helps us make sure that the model outputs exactly tags that we want, with their appropriate ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/tagging.html
5c9b811dea96-1
chain.run(inp) {'sentiment': 'enojado', 'aggressiveness': 1, 'language': 'Spanish'} inp = "Weather is ok here, I can go outside without much more than a coat" chain.run(inp) {'sentiment': 'positive', 'aggressiveness': 0, 'language': 'English'} More control# By being smart about how we define our schema we can have more...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/tagging.html
5c9b811dea96-2
chain.run(inp) {'sentiment': 'sad', 'aggressiveness': 10, 'language': 'spanish'} inp = "Weather is ok here, I can go outside without much more than a coat" chain.run(inp) {'sentiment': 'neutral', 'aggressiveness': 0, 'language': 'english'} Specifying schema with Pydantic# We can also use a Pydantic schema to specify th...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/tagging.html
5c9b811dea96-3
next Chains Contents Simplest approach, only specifying type More control Specifying schema with Pydantic By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/tagging.html
0f20e99fb6e0-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/llm_requests.html
143b444029e4-0
.ipynb .pdf Extraction Contents Extracting entities Pydantic example Extraction# The extraction chain uses the OpenAI functions parameter to specify a schema to extract entities from a document. This helps us make sure that the model outputs exactly the schema of entities and properties that we want, with their appro...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/extraction.html
143b444029e4-1
""" chain = create_extraction_chain(schema, llm) As we can see, we extracted the required entities and their properties in the required format: chain.run(inp) [{'person_name': 'Alex', 'person_height': 5, 'person_hair_color': 'blonde', 'dog_name': 'Frosty', 'dog_breed': 'labrador'}, {'person_name': 'Claudia', ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/extraction.html
143b444029e4-2
""" chain.run(inp) [Properties(person_name='Alex', person_height=5, person_hair_color='blonde', dog_breed='labrador', dog_name='Frosty'), Properties(person_name='Claudia', person_height=9, person_hair_color='brunette', dog_breed=None, dog_name=None)] previous Self-Critique Chain with Constitutional AI next FLARE Cont...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/extraction.html
0245488f2ce4-0
.ipynb .pdf NebulaGraphQAChain Contents Refresh graph schema information Querying the graph NebulaGraphQAChain# This notebook shows how to use LLMs to provide a natural language interface to NebulaGraph database. You will need to have a running NebulaGraph cluster, for which you can run a containerized cluster by run...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/graph_nebula_qa.html
0245488f2ce4-1
INSERT VERTEX movie(name) VALUES "The Godfather II":("The Godfather II"); INSERT VERTEX movie(name) VALUES "The Godfather Coda: The Death of Michael Corleone":("The Godfather Coda: The Death of Michael Corleone"); INSERT EDGE acted_in() VALUES "Al Pacino"->"The Godfather II":(); INSERT EDGE acted_in() VALUES "Al Pacino...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/graph_nebula_qa.html
0245488f2ce4-2
) chain.run("Who played in The Godfather II?") > Entering new NebulaGraphQAChain chain... Generated nGQL: MATCH (p:`person`)-[:acted_in]->(m:`movie`) WHERE m.`movie`.`name` == 'The Godfather II' RETURN p.`person`.`name` Full Context: {'p.person.name': ['Al Pacino']} > Finished chain. 'Al Pacino played in The Godfather ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/graph_nebula_qa.html
662fbb2512b5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/llm_math.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-7
Outdoors Laguna Madre Solid Short Sleeve Fishing Shirt","url":"https://www.klarna.com/us/shopping/pl/cl10001/3203102142/Clothing/Magellan-Outdoors-Laguna-Madre-Solid-Short-Sleeve-Fishing-Shirt/?utm_source=openai&ref-site=openai_plugin","price":"$19.99","attributes":["Material:Polyester,Nylon","Target Group:Man","Color:...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-8
> Finished chain. output {'instructions': 'whats the most expensive shirt?',
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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",...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-10
Group:Man","Color:Beige"]},{"name":"Magellan Outdoors Laguna Madre Solid Short Sleeve Fishing Shirt","url":"https://www.klarna.com/us/shopping/pl/cl10001/3203102142/Clothing/Magellan-Outdoors-Laguna-Madre-Solid-Short-Sleeve-Fishing-Shirt/?utm_source=openai&ref-site=openai_plugin","price":"$19.99","attributes":["Materia...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-11
'intermediate_steps': {'request_args': '{"q": "shirt", "max_price": null}',
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-13
Group:Man","Color:Beige"]},{"name":"Magellan Outdoors Laguna Madre Solid Short Sleeve Fishing Shirt","url":"https://www.klarna.com/us/shopping/pl/cl10001/3203102142/Clothing/Magellan-Outdoors-Laguna-Madre-Solid-Short-Sleeve-Fishing-Shirt/?utm_source=openai&ref-site=openai_plugin","price":"$19.99","attributes":["Materia...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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 ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-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. \"मुझे महसूस हो रहा है कि मुझे कुछ अन्य प्रकार की चाय...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-17
सर, क्या main aur cups chai lekar aaun? (Sir,kya main aur cups chai lekar aaun? - Sir, should I get more tea cups?)\nRahul: हां,बिल्कुल। और चाय की मात्रा में भी थोड़ा सा इजाफा करना। (Haan,bilkul. Aur chai ki matra mein bhi thoda sa eejafa karna. - Yes, please. And add a little extra in the quantity of tea as well.)\n</...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-18
> 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:
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-19
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. \"मुझे महसूस हो रहा है कि मुझे कुछ अन्य...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-20
सर, क्या main aur cups chai lekar aaun? (Sir,kya main aur cups chai lekar aaun? - Sir, should I get more tea cups?)\nRahul: हां,बिल्कुल। और चाय की मात्रा में भी थोड़ा सा इजाफा करना। (Haan,bilkul. Aur chai ki matra mein bhi thoda sa eejafa karna. - Yes, please. And add a little extra in the quantity of tea as well.)\n</...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-21
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: ```...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-22
'{"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. \\"मुझे महसूस हो रहा है कि मुझे कुछ अन...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-23
language=\\"Hindi\\">\\n<context>At home during breakfast.</context>\\nPreeti: सर, क्या main aur cups chai lekar aaun? (Sir,kya main aur cups chai lekar aaun? - Sir, should I get more tea cups?)\\nRahul: हां,बिल्कुल। और चाय की मात्रा में भी थोड़ा सा इजाफा करना। (Haan,bilkul. Aur chai ki matra mein bhi thoda sa eejafa k...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
459f78d60ae5-24
previous Router Chains: Selecting from multiple prompts with MultiRetrievalQAChain 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 Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/openapi.html
aba60852a6cb-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. ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/moderation.html
aba60852a6cb-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/moderation.html
aba60852a6cb-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/moderation.html