id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
49
117
c09b78917f7e-3
To generate a prompt with few shot examples, you can use the FewShotPromptTemplate. This class takes in a PromptTemplate and a list of few shot examples. It then formats the prompt template with the few shot examples. In this example, we’ll create a prompt to generate word antonyms. from langchain import PromptTemplate...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/getting_started.html
c09b78917f7e-4
input_variables=["input"], # The example_separator is the string we will use to join the prefix, examples, and suffix together with. example_separator="\n", ) # We can now generate a prompt using the `format` method. print(few_shot_prompt.format(input="big")) # -> Give the antonym of every input # -> # -> Word...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/getting_started.html
c09b78917f7e-5
{"word": "windy", "antonym": "calm"}, ] # We'll use the `LengthBasedExampleSelector` to select the examples. example_selector = LengthBasedExampleSelector( # These are the examples is has available to choose from. examples=examples, # This is the PromptTemplate being used to format the examples. exampl...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/getting_started.html
c09b78917f7e-6
# -> Antonym: lethargic # -> # -> Word: sunny # -> Antonym: gloomy # -> # -> Word: windy # -> Antonym: calm # -> # -> Word: big # -> Antonym: In contrast, if we provide a very long input, the LengthBasedExampleSelector will select fewer examples to include in the prompt. long_string = "big and huge and massive and larg...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/getting_started.html
54cf15aa123d-0
.ipynb .pdf How to serialize prompts Contents PromptTemplate Loading from YAML Loading from JSON Loading Template from a File FewShotPromptTemplate Examples Loading from YAML Loading from JSON Examples in the Config Example Prompt from a File PromptTempalte with OutputParser How to serialize prompts# It is often pref...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
54cf15aa123d-1
prompt = load_prompt("simple_prompt.yaml") print(prompt.format(adjective="funny", content="chickens")) Tell me a funny joke about chickens. Loading from JSON# This shows an example of loading a PromptTemplate from JSON. !cat simple_prompt.json { "_type": "prompt", "input_variables": ["adjective", "content"], ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
54cf15aa123d-2
output: sad - input: tall output: short Loading from YAML# This shows an example of loading a few shot example from YAML. !cat few_shot_prompt.yaml _type: few_shot input_variables: ["adjective"] prefix: Write antonyms for the following words. example_prompt: _type: prompt input_variables: ["i...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
54cf15aa123d-3
!cat few_shot_prompt.json { "_type": "few_shot", "input_variables": ["adjective"], "prefix": "Write antonyms for the following words.", "example_prompt": { "_type": "prompt", "input_variables": ["input", "output"], "template": "Input: {input}\nOutput: {output}" }, "exampl...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
54cf15aa123d-4
Output: short Input: funny Output: Example Prompt from a File# This shows an example of loading the PromptTemplate that is used to format the examples from a separate file. Note that the key changes from example_prompt to example_prompt_path. !cat example_prompt.json { "_type": "prompt", "input_variables": ["in...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
54cf15aa123d-5
"_type": "regex_parser" }, "partial_variables": {}, "template": "Given the following question and student answer, provide a correct answer and score the student answer.\nQuestion: {question}\nStudent Answer: {student_answer}\nCorrect Answer:", "template_format": "f-string", "validate_template": true...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
83f18c0d1188-0
.ipynb .pdf How to work with partial Prompt Templates Contents Partial With Strings Partial With Functions How to work with partial Prompt Templates# A prompt template is a class with a .format method which takes in a key-value map and returns a string (a prompt) to pass to the language model. Like other methods, it ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/partial.html
83f18c0d1188-1
print(prompt.format(bar="baz")) foobaz Partial With Functions# The other common use is to partial with a function. The use case for this is when you have a variable you know that you always want to fetch in a common way. A prime example of this is with date or time. Imagine you have a prompt which you always want to ha...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/partial.html
83f18c0d1188-2
Contents Partial With Strings Partial With Functions By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/partial.html
e3e589c4a769-0
.ipynb .pdf How to create a prompt template that uses few shot examples Contents Use Case Using an example set Create the example set Create a formatter for the few shot examples Feed examples and formatter to FewShotPromptTemplate Using an example selector Feed examples into ExampleSelector Feed example selector int...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
e3e589c4a769-1
"answer": """ Are follow up questions needed here: Yes. Follow up: Who was the founder of craigslist? Intermediate answer: Craigslist was founded by Craig Newmark. Follow up: When was Craig Newmark born? Intermediate answer: Craig Newmark was born on December 6, 1952. So the final answer is: December 6, 1952 """ }, ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
e3e589c4a769-2
print(example_prompt.format(**examples[0])) Question: Who lived longer, Muhammad Ali or Alan Turing? Are follow up questions needed here: Yes. Follow up: How old was Muhammad Ali when he died? Intermediate answer: Muhammad Ali was 74 years old when he died. Follow up: How old was Alan Turing when he died? Intermediate ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
e3e589c4a769-3
Are follow up questions needed here: Yes. Follow up: Who was the mother of George Washington? Intermediate answer: The mother of George Washington was Mary Ball Washington. Follow up: Who was the father of Mary Ball Washington? Intermediate answer: The father of Mary Ball Washington was Joseph Ball. So the final answer...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
e3e589c4a769-4
# This is the list of examples available to select from. examples, # This is the embedding class used to produce embeddings which are used to measure semantic similarity. OpenAIEmbeddings(), # This is the VectorStore class that is used to store the embeddings and do a similarity search over. Chroma,...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
e3e589c4a769-5
suffix="Question: {input}", input_variables=["input"] ) print(prompt.format(input="Who was the father of Mary Ball Washington?")) Question: Who was the maternal grandfather of George Washington? Are follow up questions needed here: Yes. Follow up: Who was the mother of George Washington? Intermediate answer: The m...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
1be8bf408bb3-0
.ipynb .pdf Connecting to a Feature Store Contents Feast Load Feast Store Prompts Use in a chain Tecton Prerequisites Define and Load Features Prompts Use in a chain Featureform Initialize Featureform Prompts Use in a chain Connecting to a Feature Store# Feature stores are a concept from traditional machine learning ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
1be8bf408bb3-1
Note that the input to this prompt template is just driver_id, since that is the only user defined piece (all other variables are looked up inside the prompt template). from langchain.prompts import PromptTemplate, StringPromptTemplate template = """Given the driver's up to date stats, write them note relaying those st...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
1be8bf408bb3-2
Here are the drivers stats: Conversation rate: 0.4745151400566101 Acceptance rate: 0.055561766028404236 Average Daily Trips: 936 Your response: Use in a chain# We can now use this in a chain, successfully creating a chain that achieves personalization backed by a feature store from langchain.chat_models import ChatOpen...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
1be8bf408bb3-3
user_transaction_metrics = FeatureService( name = "user_transaction_metrics", features = [user_transaction_counts] ) The above Feature Service is expected to be applied to a live workspace. For this example, we will be using the “prod” workspace. import tecton workspace = tecton.get_workspace("prod") feature_se...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
1be8bf408bb3-4
kwargs["transaction_count_30d"] = feature_vector["user_transaction_counts.transaction_count_30d_1d"] return prompt.format(**kwargs) prompt_template = TectonPromptTemplate(input_variables=["user_id"]) print(prompt_template.format(user_id="user_469998441571")) Given the vendor's up to date transaction stats, writ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
1be8bf408bb3-5
client = ff.Client(host="demo.featureform.com") Prompts# Here we will set up a custom FeatureformPromptTemplate. This prompt template will take in the average amount a user pays per transactions. Note that the input to this prompt template is just avg_transaction, since that is the only user defined piece (all other va...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
1be8bf408bb3-6
Define and Load Features Prompts Use in a chain Featureform Initialize Featureform Prompts Use in a chain By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
6aaae88add4e-0
.ipynb .pdf How to create a custom prompt template Contents Why are custom prompt templates needed? Creating a Custom Prompt Template Use the custom prompt template How to create a custom prompt template# Let’s suppose we want the LLM to generate English language explanations of a function given its name. To achieve ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/custom_prompt_template.html
6aaae88add4e-1
import inspect def get_source_code(function_name): # Get the source code of the function return inspect.getsource(function_name) Next, we’ll create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function. from langchain.prompt...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/custom_prompt_template.html
6aaae88add4e-2
prompt = fn_explainer.format(function_name=get_source_code) print(prompt) Given the function name and source code, generate an English language explanation of the function. Function Name: get_source_code Source Code: def get_source_code(function_name): # Get the source code of the fu...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/custom_prompt_template.html
048cbe0ecdcc-0
.rst .pdf How-To Guides How-To Guides# A chain is made up of links, which can be either primitives or other chains. Primitives can be either prompts, models, arbitrary functions, or other chains. The examples here are broken up into three sections: Generic Functionality Covers both generic chains (that are useful in a ...
https://python.langchain.com/en/latest/modules/chains/how_to_guides.html
e7392becc1d5-0
.ipynb .pdf Getting Started Contents Why do we need chains? Quick start: Using LLMChain Different ways of calling chains Add memory to chains Debug Chain Combine chains with the SequentialChain Create a custom chain with the Chain class Getting Started# In this tutorial, we will learn about creating simple chains in ...
https://python.langchain.com/en/latest/modules/chains/getting_started.html
e7392becc1d5-1
print(chain.run("colorful socks")) Colorful Toes Co. If there are multiple variables, you can input them all at once using a dictionary. prompt = PromptTemplate( input_variables=["company", "product"], template="What is a good name for {company} that makes {product}?", ) chain = LLMChain(llm=llm, prompt=prompt)...
https://python.langchain.com/en/latest/modules/chains/getting_started.html
e7392becc1d5-2
llm_chain(inputs={"adjective":"corny"}) {'adjective': 'corny', 'text': 'Why did the tomato turn red? Because it saw the salad dressing!'} By default, __call__ returns both the input and output key values. You can configure it to only return output key values by setting return_only_outputs to True. llm_chain("corny", r...
https://python.langchain.com/en/latest/modules/chains/getting_started.html
e7392becc1d5-3
from langchain.memory import ConversationBufferMemory conversation = ConversationChain( llm=chat, memory=ConversationBufferMemory() ) conversation.run("Answer briefly. What are the first 3 colors of a rainbow?") # -> The first three colors of a rainbow are red, orange, and yellow. conversation.run("And the next...
https://python.langchain.com/en/latest/modules/chains/getting_started.html
e7392becc1d5-4
Current conversation: Human: What is ChatGPT? AI: > Finished chain. 'ChatGPT is an AI language model developed by OpenAI. It is based on the GPT-3 architecture and is capable of generating human-like responses to text prompts. ChatGPT has been trained on a massive amount of text data and can understand and respond to a...
https://python.langchain.com/en/latest/modules/chains/getting_started.html
e7392becc1d5-5
catchphrase = overall_chain.run("colorful socks") print(catchphrase) > Entering new SimpleSequentialChain chain... Rainbow Socks Co. "Put a little rainbow in your step!" > Finished chain. "Put a little rainbow in your step!" Create a custom chain with the Chain class# LangChain provides many chains out of the box, but ...
https://python.langchain.com/en/latest/modules/chains/getting_started.html
e7392becc1d5-6
prompt_1 = PromptTemplate( input_variables=["product"], template="What is a good name for a company that makes {product}?", ) chain_1 = LLMChain(llm=llm, prompt=prompt_1) prompt_2 = PromptTemplate( input_variables=["product"], template="What is a good slogan for a company that makes {product}?", ) chain...
https://python.langchain.com/en/latest/modules/chains/getting_started.html
9be37f7dd3ec-0
.ipynb .pdf Graph QA Contents Create the graph Querying the graph Save the graph Graph QA# This notebook goes over how to do question answering over a graph data structure. Create the graph# In this section, we construct an example graph. At the moment, this works best for small pieces of text. from langchain.indexes...
https://python.langchain.com/en/latest/modules/chains/index_examples/graph_qa.html
9be37f7dd3ec-1
'is the ground on which')] Querying the graph# We can now use the graph QA chain to ask question of the graph from langchain.chains import GraphQAChain chain = GraphQAChain.from_llm(OpenAI(temperature=0), graph=graph, verbose=True) chain.run("what is Intel going to build?") > Entering new GraphQAChain chain... Entities...
https://python.langchain.com/en/latest/modules/chains/index_examples/graph_qa.html
9be37f7dd3ec-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/chains/index_examples/graph_qa.html
f27b0a3e7767-0
.ipynb .pdf Retrieval Question Answering with Sources Contents Chain Type Retrieval Question Answering with Sources# This notebook goes over how to do question-answering with sources over an Index. It does this by using the RetrievalQAWithSourcesChain, which does the lookup of the documents from an Index. from langch...
https://python.langchain.com/en/latest/modules/chains/index_examples/vector_db_qa_with_sources.html
f27b0a3e7767-1
'sources': '31-pl'} Chain Type# You can easily specify different chain types to load and use in the RetrievalQAWithSourcesChain chain. For a more detailed walkthrough of these types, please see this notebook. There are two ways to load different chain types. First, you can specify the chain type argument in the from_ch...
https://python.langchain.com/en/latest/modules/chains/index_examples/vector_db_qa_with_sources.html
f27b0a3e7767-2
{'answer': ' The president honored Justice Breyer for his service and mentioned his legacy of excellence.\n', 'sources': '31-pl'} previous Retrieval Question/Answering next Vector DB Text Generation Contents Chain Type By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, ...
https://python.langchain.com/en/latest/modules/chains/index_examples/vector_db_qa_with_sources.html
257e9bf963a0-0
.ipynb .pdf Chat Over Documents with Chat History Contents Pass in chat history Return Source Documents ConversationalRetrievalChain with search_distance ConversationalRetrievalChain with map_reduce ConversationalRetrievalChain with Question Answering with sources ConversationalRetrievalChain with streaming to stdout...
https://python.langchain.com/en/latest/modules/chains/index_examples/chat_vector_db.html
257e9bf963a0-1
Using embedded DuckDB without persistence: data will be transient We can now create a memory object, which is neccessary to track the inputs/outputs and hold a conversation. from langchain.memory import ConversationBufferMemory memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True) We now in...
https://python.langchain.com/en/latest/modules/chains/index_examples/chat_vector_db.html
257e9bf963a0-2
result = qa({"question": query, "chat_history": chat_history}) result["answer"] " The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from a family of public school educators and police officers. He also ...
https://python.langchain.com/en/latest/modules/chains/index_examples/chat_vector_db.html
257e9bf963a0-3
result['source_documents'][0] Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n\nTonight, I’d like to honor someone who has dedicated his life ...
https://python.langchain.com/en/latest/modules/chains/index_examples/chat_vector_db.html
257e9bf963a0-4
from langchain.chains.question_answering import load_qa_chain from langchain.chains.conversational_retrieval.prompts import CONDENSE_QUESTION_PROMPT llm = OpenAI(temperature=0) question_generator = LLMChain(llm=llm, prompt=CONDENSE_QUESTION_PROMPT) doc_chain = load_qa_chain(llm, chain_type="map_reduce") chain = Convers...
https://python.langchain.com/en/latest/modules/chains/index_examples/chat_vector_db.html
257e9bf963a0-5
combine_docs_chain=doc_chain, ) chat_history = [] query = "What did the president say about Ketanji Brown Jackson" result = chain({"question": query, "chat_history": chat_history}) result['answer'] " The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private ...
https://python.langchain.com/en/latest/modules/chains/index_examples/chat_vector_db.html
257e9bf963a0-6
chat_history = [] query = "What did the president say about Ketanji Brown Jackson" result = qa({"question": query, "chat_history": chat_history}) The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from ...
https://python.langchain.com/en/latest/modules/chains/index_examples/chat_vector_db.html
257e9bf963a0-7
result = qa({"question": query, "chat_history": chat_history}) result['answer'] " The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from a family of public school educators and police officers. He also ...
https://python.langchain.com/en/latest/modules/chains/index_examples/chat_vector_db.html
136296714b7c-0
.ipynb .pdf Question Answering with Sources Contents Prepare Data Quickstart The stuff Chain The map_reduce Chain The refine Chain The map-rerank Chain Question Answering with Sources# This notebook walks through how to use LangChain for question answering with sources over a list of documents. It covers four differe...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-1
from langchain.chains.qa_with_sources import load_qa_with_sources_chain from langchain.llms import OpenAI Quickstart# If you just want to get started as quickly as possible, this is the recommended way to do it: chain = load_qa_with_sources_chain(OpenAI(temperature=0), chain_type="stuff") query = "What did the presiden...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-2
PROMPT = PromptTemplate(template=template, input_variables=["summaries", "question"]) chain = load_qa_with_sources_chain(OpenAI(temperature=0), chain_type="stuff", prompt=PROMPT) query = "What did the president say about Justice Breyer" chain({"input_documents": docs, "question": query}, return_only_outputs=True) {'out...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-3
' None', ' None', ' None'], 'output_text': ' The president thanked Justice Breyer for his service.\nSOURCES: 30-pl'} Custom Prompts You can also use your own prompts with this chain. In this example, we will respond in Italian. question_prompt_template = """Use the following portion of a long document to see if an...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-4
chain({"input_documents": docs, "question": query}, return_only_outputs=True) {'intermediate_steps': ["\nStasera vorrei onorare qualcuno che ha dedicato la sua vita a servire questo paese: il giustizia Stephen Breyer - un veterano dell'esercito, uno studioso costituzionale e un giustizia in uscita della Corte Suprema d...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-5
chain({"input_documents": docs, "question": query}, return_only_outputs=True) {'output_text': "\n\nThe president said that he was honoring Justice Breyer for his dedication to serving the country and that he was a retiring Justice of the United States Supreme Court. He also thanked him for his service and praised his c...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-6
chain({"input_documents": docs, "question": query}, return_only_outputs=True) {'intermediate_steps': ['\nThe president said that he was honoring Justice Breyer for his dedication to serving the country and that he was a retiring Justice of the United States Supreme Court. He also thanked Justice Breyer for his service....
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-7
'\n\nThe president said that he was honoring Justice Breyer for his dedication to serving the country and that he was a retiring Justice of the United States Supreme Court. He also thanked Justice Breyer for his service, noting his background as a top litigator in private practice, a former federal public defender, and...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-8
'\n\nThe president said that he was honoring Justice Breyer for his dedication to serving the country and that he was a retiring Justice of the United States Supreme Court. He also thanked Justice Breyer for his service, noting his background as a top litigator in private practice, a former federal public defender, and...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-9
'output_text': '\n\nThe president said that he was honoring Justice Breyer for his dedication to serving the country and that he was a retiring Justice of the United States Supreme Court. He also thanked Justice Breyer for his service, noting his background as a top litigator in private practice, a former federal publi...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-10
"answer the question (in Italian)" "If you do update it, please update the sources as well. " "If the context isn't useful, return the original answer." ) refine_prompt = PromptTemplate( input_variables=["question", "existing_answer", "context_str"], template=refine_template, ) question_template = ( ...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-11
"\n\nIl presidente ha detto che Justice Breyer ha dedicato la sua vita al servizio di questo paese, ha onorato la sua carriera e ha contribuito a costruire un consenso. Ha ricevuto un ampio sostegno, dall'Ordine Fraterno della Polizia a ex giudici nominati da democratici e repubblicani. Inoltre, ha sottolineato l'impor...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-12
"\n\nIl presidente ha detto che Justice Breyer ha dedicato la sua vita al servizio di questo paese, ha onorato la sua carriera e ha contribuito a costruire un consenso. Ha ricevuto un ampio sostegno, dall'Ordine Fraterno della Polizia a ex giudici nominati da democratici e repubblicani. Inoltre, ha sottolineato l'impor...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-13
"\n\nIl presidente ha detto che Justice Breyer ha dedicato la sua vita al servizio di questo paese, ha onorato la sua carriera e ha contribuito a costruire un consenso. Ha ricevuto un ampio sostegno, dall'Ordine Fraterno della Polizia a ex giudici nominati da democratici e repubblicani. Inoltre, ha sottolineato l'impor...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-14
'output_text': "\n\nIl presidente ha detto che Justice Breyer ha dedicato la sua vita al servizio di questo paese, ha onorato la sua carriera e ha contribuito a costruire un consenso. Ha ricevuto un ampio sostegno, dall'Ordine Fraterno della Polizia a ex giudici nominati da democratici e repubblicani. Inoltre, ha sotto...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-15
'score': '100'}, {'answer': ' This document does not answer the question', 'score': '0'}, {'answer': ' This document does not answer the question', 'score': '0'}, {'answer': ' This document does not answer the question', 'score': '0'}] Custom Prompts You can also use your own prompts with this chain. In this example...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
136296714b7c-16
result {'source': 30, 'intermediate_steps': [{'answer': ' Il presidente ha detto che Justice Breyer ha dedicato la sua vita a servire questo paese e ha onorato la sua carriera.', 'score': '100'}, {'answer': ' Il presidente non ha detto nulla sulla Giustizia Breyer.', 'score': '100'}, {'answer': ' Non so.', '...
https://python.langchain.com/en/latest/modules/chains/index_examples/qa_with_sources.html
f87054964b54-0
.ipynb .pdf Analyze Document Contents Summarize Question Answering Analyze Document# The AnalyzeDocumentChain is more of an end to chain. This chain takes in a single document, splits it up, and then runs it through a CombineDocumentsChain. This can be used as more of an end-to-end chain. with open("../../state_of_th...
https://python.langchain.com/en/latest/modules/chains/index_examples/analyze_document.html
f87054964b54-1
qa_chain = load_qa_chain(llm, chain_type="map_reduce") qa_document_chain = AnalyzeDocumentChain(combine_docs_chain=qa_chain) qa_document_chain.run(input_document=state_of_the_union, question="what did the president say about justice breyer?") ' The president thanked Justice Breyer for his service.' previous Transformat...
https://python.langchain.com/en/latest/modules/chains/index_examples/analyze_document.html
3ad96db4c29a-0
.ipynb .pdf Question Answering Contents Prepare Data Quickstart The stuff Chain The map_reduce Chain The refine Chain The map-rerank Chain Question Answering# This notebook walks through how to use LangChain for question answering over a list of documents. It covers four different types of chains: stuff, map_reduce, ...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-1
from langchain.llms import OpenAI Quickstart# If you just want to get started as quickly as possible, this is the recommended way to do it: chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff") query = "What did the president say about Justice Breyer" chain.run(input_documents=docs, question=query) ' The pre...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-2
chain({"input_documents": docs, "question": query}, return_only_outputs=True) {'output_text': ' Il presidente ha detto che Justice Breyer ha dedicato la sua vita a servire questo paese e ha ricevuto una vasta gamma di supporto.'} The map_reduce Chain# This sections shows results of using the map_reduce Chain to do ques...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-3
' None', ' None'], 'output_text': ' The president said that Justice Breyer is an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court, and thanked him for his service.'} Custom Prompts You can also use your own prompts with this chain. In this example, we will respond in Ital...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-4
chain({"input_documents": docs, "question": query}, return_only_outputs=True) {'intermediate_steps': ["\nStasera vorrei onorare qualcuno che ha dedicato la sua vita a servire questo paese: il giustizia Stephen Breyer - un veterano dell'esercito, uno studioso costituzionale e un giustizia in uscita della Corte Suprema d...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-5
chain({"input_documents": docs, "question": query}, return_only_outputs=True) {'output_text': '\n\nThe president said that he wanted to honor Justice Breyer for his dedication to serving the country, his legacy of excellence, and his commitment to advancing liberty and justice, as well as for his support of the Equalit...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-6
'\n\nThe president said that he wanted to honor Justice Breyer for his dedication to serving the country, his legacy of excellence, and his commitment to advancing liberty and justice, as well as for his support of the Equality Act and his commitment to protecting the rights of LGBTQ+ Americans. He also praised Justice...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-7
) initial_qa_template = ( "Context information is below. \n" "---------------------\n" "{context_str}" "\n---------------------\n" "Given the context information and not prior knowledge, " "answer the question: {question}\nYour answer should be in Italian.\n" ) initial_qa_prompt = PromptTemplate...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-8
"\nIl presidente ha detto che Justice Breyer ha dedicato la sua vita al servizio di questo paese, ha reso omaggio al suo servizio e ha sostenuto la nomina di una top litigatrice in pratica privata, un ex difensore pubblico federale e una famiglia di insegnanti e agenti di polizia delle scuole pubbliche. Ha anche sottol...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-9
'output_text': "\n\nIl presidente ha detto che Justice Breyer ha dedicato la sua vita al servizio di questo paese, ha reso omaggio al suo servizio e ha sostenuto la nomina di una top litigatrice in pratica privata, un ex difensore pubblico federale e una famiglia di insegnanti e agenti di polizia delle scuole pubbliche...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-10
{'answer': ' This document does not answer the question', 'score': '0'}, {'answer': ' This document does not answer the question', 'score': '0'}, {'answer': ' This document does not answer the question', 'score': '0'}] Custom Prompts You can also use your own prompts with this chain. In this example, we will respond ...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
3ad96db4c29a-11
'score': '100'}, {'answer': ' Il presidente non ha detto nulla sulla Giustizia Breyer.', 'score': '100'}, {'answer': ' Non so.', 'score': '0'}, {'answer': ' Non so.', 'score': '0'}], 'output_text': ' Il presidente ha detto che Justice Breyer ha dedicato la sua vita a servire questo paese.'} previous Question ...
https://python.langchain.com/en/latest/modules/chains/index_examples/question_answering.html
068158327c19-0
.ipynb .pdf Hypothetical Document Embeddings Contents Multiple generations Using our own prompts Using HyDE Hypothetical Document Embeddings# This notebook goes over how to use Hypothetical Document Embeddings (HyDE), as described in this paper. At a high level, HyDE is an embedding technique that takes queries, gene...
https://python.langchain.com/en/latest/modules/chains/index_examples/hyde.html
068158327c19-1
result = embeddings.embed_query("Where is the Taj Mahal?") Using our own prompts# Besides using preconfigured prompts, we can also easily construct our own prompts and use those in the LLMChain that is generating the documents. This can be useful if we know the domain our queries will be in, as we can condition the pro...
https://python.langchain.com/en/latest/modules/chains/index_examples/hyde.html
068158327c19-2
Using DuckDB in-memory for database. Data will be transient. print(docs[0].page_content) In state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections. We cannot let this happen. Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Votin...
https://python.langchain.com/en/latest/modules/chains/index_examples/hyde.html
810fef85a6b8-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
810fef85a6b8-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
810fef85a6b8-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
810fef85a6b8-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
810fef85a6b8-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
810fef85a6b8-5
"\n\nStiamo unendo le nostre forze con quelle dei nostri alleati europei per sequestrare yacht, appartamenti di lusso e jet privati di Putin. Abbiamo chiuso lo spazio aereo americano ai voli russi e stiamo fornendo più di un miliardo di dollari in assistenza all'Ucraina. Abbiamo anche mobilitato le nostre forze terrest...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-6
"\n\nIl Presidente Biden ha lottato per passare l'American Rescue Plan per aiutare le persone che soffrivano a causa della pandemia. Il piano ha fornito sollievo economico immediato a milioni di americani, ha aiutato a mettere cibo sulla loro tavola, a mantenere un tetto sopra le loro teste e a ridurre il costo dell'as...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-7
The refine Chain# This sections shows results of using the refine Chain to do summarization. chain = load_summarize_chain(llm, chain_type="refine") chain.run(docs) "\n\nIn response to Russia's aggression in Ukraine, the United States has united with other freedom-loving nations to impose economic sanctions and hold Put...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-8
chain({"input_documents": docs}, return_only_outputs=True) {'refine_steps': [" In response to Russia's aggression in Ukraine, the United States has united with other freedom-loving nations to impose economic sanctions and hold Putin accountable. The U.S. Department of Justice is also assembling a task force to go after...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-9
"\n\nIn response to Russia's aggression in Ukraine, the United States has united with other freedom-loving nations to impose economic sanctions and hold Putin accountable. The U.S. Department of Justice is also assembling a task force to go after the crimes of Russian oligarchs and seize their ill-gotten gains. We are ...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-10
'output_text': "\n\nIn response to Russia's aggression in Ukraine, the United States has united with other freedom-loving nations to impose economic sanctions and hold Putin accountable. The U.S. Department of Justice is also assembling a task force to go after the crimes of Russian oligarchs and seize their ill-gotten...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-11
"------------\n" "{text}\n" "------------\n" "Given the new context, refine the original summary in Italian" "If the context isn't useful, return the original summary." ) refine_prompt = PromptTemplate( input_variables=["existing_answer", "text"], template=refine_template, ) chain = load_summari...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-12
"\n\nQuesta sera, ci incontriamo come democratici, repubblicani e indipendenti, ma soprattutto come americani. La Russia di Putin ha cercato di scuotere le fondamenta del mondo libero, ma ha sottovalutato la forza della gente ucraina. Insieme ai nostri alleati, stiamo imponendo sanzioni economiche, tagliando l'accesso ...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-13
"\n\nQuesta sera, ci incontriamo come democratici, repubblicani e indipendenti, ma soprattutto come americani. La Russia di Putin ha cercato di scuotere le fondamenta del mondo libero, ma ha sottovalutato la forza della gente ucraina. Insieme ai nostri alleati, stiamo imponendo sanzioni economiche, tagliando l'accesso ...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html
810fef85a6b8-14
'output_text': "\n\nQuesta sera, ci incontriamo come democratici, repubblicani e indipendenti, ma soprattutto come americani. La Russia di Putin ha cercato di scuotere le fondamenta del mondo libero, ma ha sottovalutato la forza della gente ucraina. Insieme ai nostri alleati, stiamo imponendo sanzioni economiche, tagli...
https://python.langchain.com/en/latest/modules/chains/index_examples/summarize.html