id stringlengths 14 16 | source stringlengths 49 117 | text stringlengths 16 2.73k |
|---|---|---|
265f7c50c38e-12 | https://python.langchain.com/en/latest/modules/chains/examples/flare.html | LangChain is an intuitive framework created to assist in developing applications driven by a language model, such as OpenAI or Hugging Face. Missing: decentralized | Must include:decentralized. LangChain, created by Harrison Chase, is a Python library that provides out-of-the-box support to build NLP applications using... |
265f7c50c38e-13 | https://python.langchain.com/en/latest/modules/chains/examples/flare.html | LangChain is a powerful tool that can be used to work with Large Language ... If an API key has been provided, create an OpenAI language model instance At its core, LangChain is a framework built around LLMs. We can use it for chatbots, Generative Question-Answering (GQA), summarization, and much more. A tutorial of th... |
265f7c50c38e-14 | https://python.langchain.com/en/latest/modules/chains/examples/flare.html | At its core, LangChain is a framework built around LLMs. We can use it for chatbots, Generative Question-Answering (GQA), summarization, and much more. The core idea of the library is that we can “chain” together different components to create more advanced use cases around LLMs.
>>> USER INPUT: explain in great detail... |
265f7c50c38e-15 | https://python.langchain.com/en/latest/modules/chains/examples/flare.html | '\n\nThe Langchain framework and Baby AGI are both artificial intelligence (AI) frameworks that are used to create intelligent agents. The Langchain framework is a supervised learning system that is based on the concept of “language chains”. It uses a set of rules to map natural language inputs to specific outputs. It ... |
265f7c50c38e-16 | https://python.langchain.com/en/latest/modules/chains/examples/flare.html | >>> EXISTING PARTIAL RESPONSE:
Langchain and Bitcoin have very different origin stories. Bitcoin was created by the mysterious Satoshi Nakamoto in 2008 as a decentralized digital currency. Langchain, on the other hand, was created in 2020 by a team of developers as a platform for creating and managing decentralized l... |
265f7c50c38e-17 | https://python.langchain.com/en/latest/modules/chains/examples/flare.html | > Finished chain.
Generated Questions: ['How would you describe the origin stories of Langchain and Bitcoin in terms of their similarities or differences?', 'When was Langchain created and by whom?', 'What was the purpose of creating Langchain?']
> Entering new _OpenAIResponseChain chain...
Prompt after formatting:
Res... |
265f7c50c38e-18 | https://python.langchain.com/en/latest/modules/chains/examples/flare.html | >>> CONTEXT: Bitcoin and Ethereum have many similarities but different long-term visions and limitations. Ethereum changed from proof of work to proof of ... Bitcoin will be around for many years and examining its white paper origins is a great exercise in understanding why. Satoshi Nakamoto's blueprint describes ... B... |
265f7c50c38e-19 | https://python.langchain.com/en/latest/modules/chains/examples/flare.html | At its core, LangChain is a framework built around LLMs. We can use it for chatbots, Generative Question-Answering (GQA), summarization, and much more. The core idea of the library is that we can “chain” together different components to create more advanced use cases around LLMs.
>>> USER INPUT: how are the origin stor... |
999513486d4a-0 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | .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... |
999513486d4a-1 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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. Please provide JSON arguments to agentFunc() based on the ... |
999513486d4a-2 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | {"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 provided schema, including all required args.
If you don't have sufficient informatio... |
999513486d4a-3 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | USER_COMMENT: "whats the most expensive shirt?"
If the API_RESPONSE can answer the USER_COMMENT respond with the following markdown json block:
Response: ```json
{"response": "Human-understandable synthesis of the API_RESPONSE"}
```
Otherwise respond with the following markdown json block:
Response Error: ```json
{"res... |
999513486d4a-4 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | raw_response=True # Return raw response
)
output = chain("whats the most expensive shirt?")
> Entering new OpenAPIEndpointChain chain...
> Entering new APIRequesterChain chain...
Prompt after formatting:
You are a helpful AI Assistant. Please provide JSON arguments to agentFunc() based on the user's instructions.
API_S... |
999513486d4a-5 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | {"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 provided schema, including all required args.
If you don't have sufficient informatio... |
999513486d4a-6 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | {"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... |
999513486d4a-7 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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:Red,Pink,White,Blue,Purple,Beige,Black,Gr... |
999513486d4a-8 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | > Finished chain.
output
{'instructions': 'whats the most expensive shirt?', |
999513486d4a-9 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | '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",... |
999513486d4a-10 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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:Red,Pink,White,Blue,Pu... |
999513486d4a-11 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 'intermediate_steps': {'request_args': '{"q": "shirt", "max_price": null}', |
999513486d4a-12 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | '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... |
999513486d4a-13 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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:Red,Pink,White,B... |
999513486d4a-14 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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 ... |
999513486d4a-15 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | /* 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 explanation - e.g. setting, scenario... |
999513486d4a-16 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | {"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. \"मुझे महसूस हो रहा है कि मुझे कुछ अन्य प्रकार की चाय... |
999513486d4a-17 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | (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</example-convo>\n\n*[Report an issue or l... |
999513486d4a-18 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | > 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: |
999513486d4a-19 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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. \"मुझे महसूस हो रहा है कि मुझे कुछ अन्य... |
999513486d4a-20 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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</example-convo>\n\n*[Report an issu... |
999513486d4a-21 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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: ```... |
999513486d4a-22 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | '{"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. \\"मुझे महसूस हो रहा है कि मुझे कुछ अन... |
999513486d4a-23 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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 karna. - Yes, please. And add a little extra in t... |
999513486d4a-24 | https://python.langchain.com/en/latest/modules/chains/examples/openapi.html | 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 04, 2023. |
6efd6af922c6-0 | https://python.langchain.com/en/latest/modules/chains/examples/llm_requests.html | .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... |
8fe7835a8b68-0 | https://python.langchain.com/en/latest/modules/chains/examples/llm_math.html | .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... |
aff88949b4e9-0 | https://python.langchain.com/en/latest/modules/chains/examples/multi_retrieval_qa_router.html | .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... |
aff88949b4e9-1 | https://python.langchain.com/en/latest/modules/chains/examples/multi_retrieval_qa_router.html | "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",
"retriever": personal_retriever
}
]
chain = MultiRetr... |
aff88949b4e9-2 | https://python.langchain.com/en/latest/modules/chains/examples/multi_retrieval_qa_router.html | > 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 United States Department of Defense. However, the World Wide Web, which is often confused with the Internet... |
69af26548d6e-0 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | .ipynb
.pdf
SQL Chain example
Contents
Use Query Checker
Customize Prompt
Return Intermediate Steps
Choosing how to limit the number of rows returned
Adding example rows from each table
Custom Table Info
SQLDatabaseSequentialChain
Using Local Language Models
SQL Chain example#
This example demonstrates the use of the... |
69af26548d6e-1 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | > Entering new SQLDatabaseChain chain...
How many employees are there?
SQLQuery:
/workspace/langchain/langchain/sql_database.py:191: 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 consid... |
69af26548d6e-2 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | SQLResult: "Result of the SQLQuery"
Answer: "Final answer here"
Only use the following tables:
{table_info}
If someone asks for the table foobar, they really mean the employee table.
Question: {input}"""
PROMPT = PromptTemplate(
input_variables=["input", "table_info", "dialect"], template=_DEFAULT_TEMPLATE
)
db_cha... |
69af26548d6e-3 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 'top_k': '5',
'dialect': 'sqlite', |
69af26548d6e-4 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 'table_info': '\nCREATE TABLE "Artist" (\n\t"ArtistId" INTEGER NOT NULL, \n\t"Name" NVARCHAR(120), \n\tPRIMARY KEY ("ArtistId")\n)\n\n/*\n3 rows from Artist table:\nArtistId\tName\n1\tAC/DC\n2\tAccept\n3\tAerosmith\n*/\n\n\nCREATE TABLE "Employee" (\n\t"EmployeeId" INTEGER NOT NULL, \n\t"LastName" NVARCHAR(20) NOT NULL... |
69af26548d6e-5 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 428-9482\t+1 (780) 428-3457\tandrew@chinookcorp.com\n2\tEdwards\tNancy\tSales Manager\t1\t1958-12-08 00:00:00\t2002-05-01 00:00:00\t825 8 Ave SW\tCalgary\tAB\tCanada\tT2P 2T3\t+1 (403) 262-3443\t+1 (403) 262-3322\tnancy@chinookcorp.com\n3\tPeacock\tJane\tSales Support Agent\t2\t1973-08-29 00:00:00\t2002-04-01 00:00:00\... |
69af26548d6e-6 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | KEY ("PlaylistId")\n)\n\n/*\n3 rows from Playlist table:\nPlaylistId\tName\n1\tMusic\n2\tMovies\n3\tTV Shows\n*/\n\n\nCREATE TABLE "Album" (\n\t"AlbumId" INTEGER NOT NULL, \n\t"Title" NVARCHAR(160) NOT NULL, \n\t"ArtistId" INTEGER NOT NULL, \n\tPRIMARY KEY ("AlbumId"), \n\tFOREIGN KEY("ArtistId") REFERENCES "Artist" ("... |
69af26548d6e-7 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | table:\nCustomerId\tFirstName\tLastName\tCompany\tAddress\tCity\tState\tCountry\tPostalCode\tPhone\tFax\tEmail\tSupportRepId\n1\tLuís\tGonçalves\tEmbraer - Empresa Brasileira de Aeronáutica S.A.\tAv. Brigadeiro Faria Lima, 2170\tSão José dos Campos\tSP\tBrazil\t12227-000\t+55 (12) 3923-5555\t+55 (12) 3923-5566\tluisg@e... |
69af26548d6e-8 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | table:\nInvoiceId\tCustomerId\tInvoiceDate\tBillingAddress\tBillingCity\tBillingState\tBillingCountry\tBillingPostalCode\tTotal\n1\t2\t2009-01-01 00:00:00\tTheodor-Heuss-Straße 34\tStuttgart\tNone\tGermany\t70174\t1.98\n2\t4\t2009-01-02 00:00:00\tUllevålsveien 14\tOslo\tNone\tNorway\t0171\t3.96\n3\t8\t2009-01-03 00:00:... |
69af26548d6e-9 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | Johnson\t343719\t11170334\t0.99\n2\tBalls to the Wall\t2\t2\t1\tNone\t342562\t5510424\t0.99\n3\tFast As a Shark\t3\t2\t1\tF. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman\t230619\t3990994\t0.99\n*/\n\n\nCREATE TABLE "InvoiceLine" (\n\t"InvoiceLineId" INTEGER NOT NULL, \n\t"InvoiceId" INTEGER NOT NULL, \n\t"TrackId" ... |
69af26548d6e-10 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | '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... |
69af26548d6e-11 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | '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 data is not obvious... |
69af26548d6e-12 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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 11170334 0.99
2 Balls to the Wall 2 2 1 None 342562 5510424 ... |
69af26548d6e-13 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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... |
69af26548d6e-14 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | "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 of all time
*/"""
}
db = SQLDat... |
69af26548d6e-15 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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 Violins in D Minor, BWV 1043: I. Vivace',), ('Aria Mit 30 Verän... |
69af26548d6e-16 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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... |
69af26548d6e-17 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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 1043: I. Vivace\',), (\'Aria Mit 30 Veränderungen, BWV 988 "Goldberg Va... |
69af26548d6e-18 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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... |
69af26548d6e-19 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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 G Major, BWV 1007: I. Prélude',), ('Toccata and Fug... |
69af26548d6e-20 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | {'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 Solo Cello ... |
69af26548d6e-21 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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... |
69af26548d6e-22 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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 Language Models#
Sometimes you may not have the luxury of using OpenAI or other s... |
69af26548d6e-23 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | /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 checkpoint shards: 100%|██████████| 8/8 [00:32<00:00... |
69af26548d6e-24 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | warnings.warn(
[59]
> Finished chain.
{'query': 'How many customers are there?',
'result': '[59]',
'intermediate_steps': [{'input': 'How many customers are there?\nSQLQuery:SELECT count(*) FROM Customer\nSQLResult: [(59,)]\nAnswer:',
'top_k': '5',
'dialect': 'sqlite', |
69af26548d6e-25 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | '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), ... |
69af26548d6e-26 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | Bélanger\tMontréal\tQC\tCanada\tH2G 1A7\t+1 (514) 721-4711\tNone\tftremblay@gmail.com\t3\n*/', |
69af26548d6e-27 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | '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... |
69af26548d6e-28 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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... |
69af26548d6e-29 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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 ... |
69af26548d6e-30 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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>... |
69af26548d6e-31 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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... |
69af26548d6e-32 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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... |
69af26548d6e-33 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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->... |
69af26548d6e-34 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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... |
69af26548d6e-35 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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,... |
69af26548d6e-36 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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_key = sql_result_key # this is SQL execution input
elif isinstance(ste... |
69af26548d6e-37 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | SQLResult: [('François',), ('František',), ('Helena',), ('Astrid',), ('Daan',), ('Kara',), ('Eduardo',), ('Alexandre',), ('Fernanda',), ('Mark',), ('Frank',), ('Jack',), ('Dan',), ('Kathy',), ('Heather',), ('Frank',), ('Richard',), ('Patrick',), ('Julia',), ('Edward',), ('Martha',), ('Aaron',), ('Madalena',), ('Hannah'... |
69af26548d6e-38 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | [('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', 'Lucas', 'Johanne... |
69af26548d6e-39 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | (''Kara'',), (''Eduardo'',), (''Alexandre'',), (''Fernanda'',), (''Mark'',), (''Frank'',),
(''Jack'',), (''Dan'',), (''Kathy'',), (''Heather'',), (''Frank'',), (''Richard'',),
(''Patrick'',), (''Julia'',), (''Edward'',), (''Martha'',), (''Aaron'',), (''Madalena'',),
(''Hannah'',), (''Niklas'',), (''Camille'',), (... |
69af26548d6e-40 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | \ 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\tCompany\tAddress\t\
City\tState\tCountry\tPostalCode\tPhone\tFax\tEmail\tSupportRepId\n... |
69af26548d6e-41 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | 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.g. here we are using YAML to keep ... |
69af26548d6e-42 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | )
/*
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 Roll',), ('Reggae',), ('R&B/Soul',)]"
answer: The genres that start with 'r' are Rock, Rock and Roll, Reggae and R&B/Soul.... |
69af26548d6e-43 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | Chroma, # type: ignore
# This is the number of examples to produce and include per prompt
k=min(3, len(examples_dict)),
)
few_shot_prompt = FewShotPromptTemplate(
example_selector=example_selector,
example_prompt=example_prompt,
prefix=_sq... |
69af26548d6e-44 | https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html | Chains
Contents
Use Query Checker
Customize Prompt
Return Intermediate Steps
Choosing how to limit the number of rows returned
Adding example rows from each table
Custom Table Info
SQLDatabaseSequentialChain
Using Local Language Models
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last upd... |
fff746b44bb6-0 | https://python.langchain.com/en/latest/modules/chains/examples/pal.html | .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_... |
fff746b44bb6-1 | https://python.langchain.com/en/latest/modules/chains/examples/pal.html | 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
> Finished PALChain chain.
'2'
Intermediate Step... |
fff746b44bb6-2 | https://python.langchain.com/en/latest/modules/chains/examples/pal.html | "# 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 objects if object[0] != 'sunglasses']\n\n# Count number of purple obje... |
66f934f97478-0 | https://python.langchain.com/en/latest/modules/chains/examples/moderation.html | .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. ... |
66f934f97478-1 | https://python.langchain.com/en/latest/modules/chains/examples/moderation.html | "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.run("I will kill you")
----------------------------------... |
66f934f97478-2 | https://python.langchain.com/en/latest/modules/chains/examples/moderation.html | ---> 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 = "Text was found that violates OpenAI's content policy."
72 if self.error:
-... |
66f934f97478-3 | https://python.langchain.com/en/latest/modules/chains/examples/moderation.html | 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
Person 2:"""
llm_chain.run(text)
' I will kill you'
chain = SimpleSequen... |
66f934f97478-4 | https://python.langchain.com/en/latest/modules/chains/examples/moderation.html | {'sanitized_text': "Text was found that violates OpenAI's content policy."}
previous
LLMSummarizationCheckerChain
next
Router Chains: Selecting from multiple prompts with MultiPromptChain
Contents
How to use the moderation chain
How to append a Moderation chain to an LLMChain
By Harrison Chase
© Copyrigh... |
d563167d7f33-0 | https://python.langchain.com/en/latest/modules/chains/examples/multi_prompt_router.html | .ipynb
.pdf
Router Chains: Selecting from multiple prompts with MultiPromptChain
Router Chains: Selecting from multiple prompts with MultiPromptChain#
This notebook demonstrates how to use the RouterChain paradigm to create a chain that dynamically selects the prompt to use for a given input. Specifically we show how t... |
d563167d7f33-1 | https://python.langchain.com/en/latest/modules/chains/examples/multi_prompt_router.html | Black body radiation is the emission of electromagnetic radiation from a body due to its temperature. It is a type of thermal radiation that is emitted from the surface of all objects that are at a temperature above absolute zero. It is a spectrum of radiation that is influenced by the temperature of the body and is in... |
d563167d7f33-2 | https://python.langchain.com/en/latest/modules/chains/examples/multi_prompt_router.html | The type of cloud that typically produces rain is called a cumulonimbus cloud. This type of cloud is characterized by its large vertical extent and can produce thunderstorms and heavy precipitation. Is there anything else you'd like to know?
previous
Moderation
next
Router Chains: Selecting from multiple prompts with M... |
a23bc227a3a0-0 | https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html | .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 assumptions to the format of the input text (or summary)... |
a23bc227a3a0-1 | https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html | These discoveries can spark a child's imagination about the infinite wonders of the universe."""
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 th... |
a23bc227a3a0-2 | https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html | 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, explain why.
> Finished chain.
> Entering new LLMChain chain...
Prompt after formatting:
Below are some assertions that have been fact ch... |
a23bc227a3a0-3 | https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html | > 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: """
- ... |
a23bc227a3a0-4 | https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html | • 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 years to reach us.
• JWST has provided us with the first images of exoplanets, which are planets outside of our own solar system. These distant worlds were... |
a23bc227a3a0-5 | https://python.langchain.com/en/latest/modules/chains/examples/llm_summarization_checker.html | • The James Webb Space Telescope (JWST) spotted a number of galaxies nicknamed "green peas."
• The light from these galaxies has been traveling for over 13 billion years to reach us.
• JWST has provided us with the first images of exoplanets, which are planets outside of our own solar system.
• Exoplanets were first di... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.