id
stringlengths
14
16
source
stringlengths
49
117
text
stringlengths
16
2.73k
b9feafca9fc9-6
https://python.langchain.com/en/latest/use_cases/agents/wikibase_agent.html
) # Parse out the action and action input regex = r"Action: (.*?)[\n]*Action Input:[\s]*(.*)" match = re.search(regex, llm_output, re.DOTALL) if not match: raise ValueError(f"Could not parse LLM output: `{llm_output}`") action = match.group(1).strip() action_i...
b9feafca9fc9-7
https://python.langchain.com/en/latest/use_cases/agents/wikibase_agent.html
Action Input: children Observation:P1971Now I can query the number of children J.S. Bach had. Action: SparqlQueryRunner Action Input: SELECT ?children WHERE { wd:Q1339 wdt:P1971 ?children } Observation:[{"children": {"datatype": "http://www.w3.org/2001/XMLSchema#decimal", "type": "literal", "value": "20"}}]I now know t...
b9feafca9fc9-8
https://python.langchain.com/en/latest/use_cases/agents/wikibase_agent.html
Observation:[{"playerID": {"type": "literal", "value": "o/olajuha01"}}]I now know the final answer Final Answer: Hakeem Olajuwon's Basketball-Reference.com NBA player ID is "o/olajuha01". > Finished chain. 'Hakeem Olajuwon\'s Basketball-Reference.com NBA player ID is "o/olajuha01".' Contents Wikibase Agent Prelimin...
df9bec8deecd-0
https://python.langchain.com/en/latest/use_cases/agents/multi_modal_output_agent.html
.ipynb .pdf Multi-modal outputs: Image & Text Contents Multi-modal outputs: Image & Text Dall-E StableDiffusion Multi-modal outputs: Image & Text# This notebook shows how non-text producing tools can be used to create multi-modal agents. This example is limited to text and image outputs and uses UUIDs to transfer con...
df9bec8deecd-1
https://python.langchain.com/en/latest/use_cases/agents/multi_modal_output_agent.html
"""Display the multi-modal output from the agent.""" UUID_PATTERN = re.compile( r"([0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12})" ) outputs = UUID_PATTERN.split(output) outputs = [re.sub(r"^\W+", "", el) for el in outputs] # Clean trailing and leading non-word char...
df9bec8deecd-2
https://python.langchain.com/en/latest/use_cases/agents/multi_modal_output_agent.html
The UUID of the generated image is Contents Multi-modal outputs: Image & Text Dall-E StableDiffusion By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
373a74f277c7-0
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
.ipynb .pdf Voice Assistant Voice Assistant# This chain creates a clone of ChatGPT with a few modifications to make it a voice assistant. It uses the pyttsx3 and speech_recognition libraries to convert text to speech and speech to text respectively. The prompt template is also changed to make it more suitable for voice...
373a74f277c7-1
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
{history} Human: {human_input} Assistant:""" prompt = PromptTemplate( input_variables=["history", "human_input"], template=template ) chatgpt_chain = LLMChain( llm=OpenAI(temperature=0), prompt=prompt, verbose=True, memory=ConversationBufferWindowMemory(k=2), ) import speech_recognition as s...
373a74f277c7-2
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Okay, go! listening now... Recognizing... C:\Users\jaden\AppData\Roaming\Python\Python310\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 Hello, Ass...
373a74f277c7-3
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Assistant is aware that human input is being transcribed from audio and as such there may be some errors in the transcription. It will attempt to account for some words being swapped with similar-sounding words or phrases. Assistant will also keep responses concise, because human attention spans are more limited over t...
373a74f277c7-4
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Assistant is aware that human input is being transcribed from audio and as such there may be some errors in the transcription. It will attempt to account for some words being swapped with similar-sounding words or phrases. Assistant will also keep responses concise, because human attention spans are more limited over t...
373a74f277c7-5
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist. Assistant is aware that human ...
373a74f277c7-6
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based ...
373a74f277c7-7
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-soundin...
373a74f277c7-8
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Assistant: > Finished chain. Neural networks are inspired by the way the human brain works. They are composed of interconnected nodes that process data and make decisions, just like neurons in the brain. Neural networks can learn from their mistakes and improve their performance over time, just like humans do. listeni...
373a74f277c7-9
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Human: I'd like to learn more about neural networks. AI: Sure! Neural networks are a type of artificial intelligence that use a network of interconnected nodes to process data and make decisions. They are used in a variety of applications, from image recognition to natural language processing. Neural networks are oft...
373a74f277c7-10
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based ...
373a74f277c7-11
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Once upon a time, there was a young boy named Jack who lived in a small village. Jack was always honest and trustworthy, and his friends and family knew they could always count on him. One day, Jack was walking through the forest when he stumbled upon a magical tree. The tree told Jack that if he was honest and trustwo...
373a74f277c7-12
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist. Assistant is aware that human ...
373a74f277c7-13
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Thank you! I'm glad you enjoyed it. listening now... Recognizing... Thank you. > Entering new LLMChain chain... Prompt after formatting: Assistant is a large language model trained by OpenAI. Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth ex...
373a74f277c7-14
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
AI: Once upon a time, there was a young boy named Jack who lived in a small village. Jack was always honest and trustworthy, and his friends and family knew they could always count on him. One day, Jack was walking through the forest when he stumbled upon a magical tree. The tree told Jack that if he was honest and tr...
373a74f277c7-15
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based ...
373a74f277c7-16
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
> Entering new LLMChain chain... Prompt after formatting: Assistant is a large language model trained by OpenAI. Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assis...
373a74f277c7-17
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
AI: Yes, there are several online brands that offer photo editing and other creative tools without the need to download any software. Adobe Photoshop Express, Pixlr, and Fotor are some of the most popular online photo editing tools. Freq is an online music production platform that allows users to create and share musi...
373a74f277c7-18
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
Assistant is aware that human input is being transcribed from audio and as such there may be some errors in the transcription. It will attempt to account for some words being swapped with similar-sounding words or phrases. Assistant will also keep responses concise, because human attention spans are more limited over t...
373a74f277c7-19
https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html
21 # audio = r.record(source,duration = 5) 22 print('Recognizing...') File c:\ProgramData\miniconda3\envs\lang\lib\site-packages\speech_recognition\__init__.py:523, in Recognizer.listen(self, source, timeout, phrase_time_limit, snowboy_configuration) 520 if phrase_time_limit and elapsed_time - phrase_s...
b3bcbe7195e9-0
https://python.langchain.com/en/latest/use_cases/evaluation/huggingface_datasets.html
.ipynb .pdf Using Hugging Face Datasets Contents Setup Examples Predictions Evaluation Using Hugging Face Datasets# This example shows how to use Hugging Face datasets to evaluate models. Specifically, we show how to load examples to evaluate models on from Hugging Face’s dataset package. Setup# For demonstration pur...
b3bcbe7195e9-1
https://python.langchain.com/en/latest/use_cases/evaluation/huggingface_datasets.html
'The watermelon seeds will be excreted'], 'incorrect_answers': ['You grow watermelons in your stomach', 'You get sick', 'You have bad dreams', 'You die', 'You get indigestion', 'You fall unconscious', 'You digest the watermelon seeds'], 'source': 'https://wonderopolis.org/wonder/will-a-watermelon-grow-in-...
b3bcbe7195e9-2
https://python.langchain.com/en/latest/use_cases/evaluation/huggingface_datasets.html
eval_chain = QAEvalChain.from_llm(llm) graded_outputs = eval_chain.evaluate(examples, predictions, question_key="question", answer_key="best_answer", prediction_key="text") graded_outputs [{'text': ' INCORRECT'}, {'text': ' INCORRECT'}, {'text': ' INCORRECT'}, {'text': ' CORRECT'}, {'text': ' INCORRECT'}] previous ...
4b5fbcac7671-0
https://python.langchain.com/en/latest/use_cases/evaluation/qa_generation.html
.ipynb .pdf QA Generation QA Generation# This notebook shows how to use the QAGenerationChain to come up with question-answer pairs over a specific document. This is important because often times you may not have data to evaluate your question-answer system over, so this is a cheap and lightweight way to generate it! f...
07fd02657314-0
https://python.langchain.com/en/latest/use_cases/evaluation/qa_benchmarking_sota.html
.ipynb .pdf Question Answering Benchmarking: State of the Union Address Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Question Answering Benchmarking: State of the Union Address# Here we go over how to benchmark performance on a question answering task over ...
07fd02657314-1
https://python.langchain.com/en/latest/use_cases/evaluation/qa_benchmarking_sota.html
from langchain.chains import RetrievalQA from langchain.llms import OpenAI chain = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=vectorstore.as_retriever(), input_key="question") Make a prediction# First, we can make predictions one datapoint at a time. Doing it at this level of granularity al...
07fd02657314-2
https://python.langchain.com/en/latest/use_cases/evaluation/qa_benchmarking_sota.html
from collections import Counter Counter([pred['grade'] for pred in predictions]) Counter({' CORRECT': 7, ' INCORRECT': 4}) We can also filter the datapoints to the incorrect examples and look at them. incorrect = [pred for pred in predictions if pred['grade'] == " INCORRECT"] incorrect[0] {'question': 'What is the U.S....
c3fd85aa55bb-0
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
.ipynb .pdf Evaluating an OpenAPI Chain Contents Load the API Chain Optional: Generate Input Questions and Request Ground Truth Queries Run the API Chain Evaluate the requests chain Evaluate the Response Chain Generating Test Datasets Evaluating an OpenAPI Chain# This notebook goes over ways to semantically evaluate ...
c3fd85aa55bb-1
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
# from langchain.prompts import PromptTemplate # template = """Below is a service description: # {spec} # Imagine you're a new user trying to use {operation} through a search bar. What are 10 different things you want to request? # Wants/Questions: # 1. """ # prompt = PromptTemplate.from_template(template) # generation...
c3fd85aa55bb-2
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
'expected_query': {'max_price': 300, 'q': 'laptop'}}, {'question': 'Show me the cheapest gaming PC.', 'expected_query': {'max_price': 500, 'q': 'gaming pc'}}, {'question': 'Are there any tablets under $400?', 'expected_query': {'max_price': 400, 'q': 'tablet'}}, {'question': 'What are the best headphones?', 'e...
c3fd85aa55bb-3
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
failed_examples.append({'q': question, 'error': e}) scores["completed"].append(0.0) # If the chain failed to run, show the failing examples failed_examples [] answers = [res['output'] for res in chain_outputs] answers ['There are currently 10 Apple iPhone models available: Apple iPhone 14 Pro Max 256GB, Apple i...
c3fd85aa55bb-4
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
'It looks like you are looking for the best headphones. Based on the API response, it looks like the Apple AirPods Pro (2nd generation) 2022, Apple AirPods Max, and Bose Noise Cancelling Headphones 700 are the best options.', 'The top rated laptops based on the API response are the Apple MacBook Pro (2021) M1 Pro 8C C...
c3fd85aa55bb-5
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
"I found several Nike and Adidas shoes in the API response. Here are the links to the products: Nike Dunk Low M - Black/White: https://www.klarna.com/us/shopping/pl/cl337/3200177969/Shoes/Nike-Dunk-Low-M-Black-White/?utm_source=openai&ref-site=openai_plugin, Nike Air Jordan 4 Retro M - Midnight Navy: https://www.klarna...
c3fd85aa55bb-6
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
https://www.klarna.com/us/shopping/pl/cl337/3202929696/Shoes/Nike-Air-Jordan-11-Retro-Cherry-White-Varsity-Red-Black/?utm_source=openai&ref-site=openai_plugin, Nike Dunk High W - White/Black: https://www.klarna.com/us/shopping/pl/cl337/3201956448/Shoes/Nike-Dunk-High-W-White-Black/?utm_source=openai&ref-site=openai_plu...
c3fd85aa55bb-7
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
"I found several skirts that may interest you. Please take a look at the following products: Avenue Plus Size Denim Stretch Skirt, LoveShackFancy Ruffled Mini Skirt - Antique White, Nike Dri-Fit Club Golf Skirt - Active Pink, Skims Soft Lounge Ruched Long Skirt, French Toast Girl's Front Pleated Skirt with Tabs, Alexia...
c3fd85aa55bb-8
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
template = """You are trying to answer the following question by querying an API: > Question: {question} The query you know you should be executing against the API is: > Query: {truth_query} Is the following predicted query semantically the same (eg likely to produce the same answer)? > Predicted Query: {predict_query}...
c3fd85aa55bb-9
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
' The original query is asking for laptops with a maximum price of 300. The predicted query is asking for laptops with a minimum price of 0 and a maximum price of 500. This means that the predicted query is likely to return more results than the original query, as it is asking for a wider range of prices. Therefore, th...
c3fd85aa55bb-10
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
" The original query is asking for the top rated laptops, so the 'size' parameter should be set to 10 to get the top 10 results. The 'min_price' parameter should be set to 0 to get results from all price ranges. The 'max_price' parameter should be set to null to get results from all price ranges. The 'q' parameter shou...
c3fd85aa55bb-11
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
' The first part of the query is asking for a Desktop PC, which is the same as the original query. The second part of the query is asking for a size of 10, which is not relevant to the original query. The third part of the query is asking for a minimum price of 0, which is not relevant to the original query. The fourth...
c3fd85aa55bb-12
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
from langchain.prompts import PromptTemplate template = """You are trying to answer the following question by querying an API: > Question: {question} The API returned a response of: > API result: {api_response} Your response to the user: {answer} Please evaluate the accuracy and utility of your response to the user's o...
c3fd85aa55bb-13
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
' The original query is asking for laptops with a maximum price of 300. The predicted query is asking for laptops with a minimum price of 0 and a maximum price of 500. This means that the predicted query is likely to return more results than the original query, as it is asking for a wider range of prices. Therefore, th...
c3fd85aa55bb-14
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
" The original query is asking for the top rated laptops, so the 'size' parameter should be set to 10 to get the top 10 results. The 'min_price' parameter should be set to 0 to get results from all price ranges. The 'max_price' parameter should be set to null to get results from all price ranges. The 'q' parameter shou...
c3fd85aa55bb-15
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
' The first part of the query is asking for a Desktop PC, which is the same as the original query. The second part of the query is asking for a size of 10, which is not relevant to the original query. The third part of the query is asking for a minimum price of 0, which is not relevant to the original query. The fourth...
c3fd85aa55bb-16
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
" The API response provided the name, price, and URL of the product, which is exactly what the user asked for. The response also provided additional information about the product's attributes, which is useful for the user to make an informed decision. Therefore, the response is accurate and useful. Final Grade: A", " ...
c3fd85aa55bb-17
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
" The API response provided a list of skirts that could potentially meet the user's needs. The response also included the name, price, and attributes of each skirt. This is a great start, as it provides the user with a variety of options to choose from. However, the response does not provide any images of the skirts, w...
c3fd85aa55bb-18
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
mean_scores = sum(metric_scores) / len(metric_scores) if len(metric_scores) > 0 else float('nan') row = "{:<20}\t{:<10.2f}\t{:<10.2f}\t{:<10.2f}".format(metric, min(metric_scores), mean_scores, max(metric_scores)) print(row) Metric Min Mean Max completed 1.00 1...
c3fd85aa55bb-19
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
# See which HTTP Methods are available for a given path methods = spec.get_methods_for_path('/v1/public/openai/explain-task') methods ['post'] # Load a single endpoint operation operation = APIOperation.from_openapi_spec(spec, '/v1/public/openai/explain-task', 'post') # The operation can be serialized as typescript pri...
c3fd85aa55bb-20
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
generation_chain = LLMChain(llm=llm, prompt=prompt) purpose = generation_chain.run(spec=operation.to_typescript()) template = """Write a list of {num_to_generate} unique messages users might send to a service designed to{purpose} They must each be completely unique. 1.""" def parse_list(text: str) -> List[str]: # M...
c3fd85aa55bb-21
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
llm, requests=Requests(), verbose=verbose, return_intermediate_steps=True # Return request and response text ) predicted_outputs =[api_chain(query) for query in queries] request_args = [output["intermediate_steps"]["request_args"] for output in predicted_outputs] # Show the generated request request_args ...
c3fd85aa55bb-22
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
'{"task_description": "Explain the meaning of \'hello\' in Japanese", "learning_language": "Japanese", "native_language": "English", "full_query": "Can you explain the meaning of \'hello\' in Japanese?"}', '{"task_description": "understanding the Russian word for \'thank you\'", "learning_language": "Russian", "native...
c3fd85aa55bb-23
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
Query: Can you explain how to say 'hello' in Spanish? Request: {"task_description": "say 'hello'", "learning_language": "Spanish", "native_language": "English", "full_query": "Can you explain how to say 'hello' in Spanish?"} Requested changes: Query: I need help understanding the French word for 'goodbye'. Request: {"...
c3fd85aa55bb-24
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
Request: {"task_description": "Find the Dutch word for 'no'", "learning_language": "Dutch", "native_language": "English", "full_query": "I'm looking for the Dutch word for 'no'."} Requested changes: Query: Can you explain the meaning of 'hello' in Japanese? Request: {"task_description": "Explain the meaning of 'hello'...
c3fd85aa55bb-25
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
['{"task_description": "say \'hello\'", "learning_language": "Spanish", "native_language": "English", "full_query": "Can you explain how to say \'hello\' in Spanish?"}', '{"task_description": "understanding the French word for \'goodbye\'", "learning_language": "French", "native_language": "English", "full_query": "I ...
c3fd85aa55bb-26
https://python.langchain.com/en/latest/use_cases/evaluation/openapi_eval.html
'{"task_description": "say goodbye", "learning_language": "Chinese", "native_language": "English", "full_query": "Can you tell me how to say \'goodbye\' in Chinese?"}', '{"task_description": "Learn the Arabic word for \'please\'", "learning_language": "Arabic", "native_language": "English", "full_query": "I\'m trying ...
0b5fc6fd41ea-0
https://python.langchain.com/en/latest/use_cases/evaluation/llm_math.html
.ipynb .pdf LLM Math Contents Setting up a chain LLM Math# Evaluating chains that know how to do math. # Comment this out if you are NOT using tracing import os os.environ["LANGCHAIN_HANDLER"] = "langchain" from langchain.evaluation.loading import load_dataset dataset = load_dataset("llm-math") Downloading and prepar...
0b5fc6fd41ea-1
https://python.langchain.com/en/latest/use_cases/evaluation/llm_math.html
for i, example in enumerate(dataset): print("input: ", example["question"]) print("expected output :", example["answer"]) print("prediction: ", numeric_output[i]) input: 5 expected output : 5.0 prediction: 5.0 input: 5 + 3 expected output : 8.0 prediction: 8.0 input: 2^3.171 expected output : 9.0067086...
0b5fc6fd41ea-2
https://python.langchain.com/en/latest/use_cases/evaluation/llm_math.html
© Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
58c55325a07c-0
https://python.langchain.com/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
.ipynb .pdf Agent VectorDB Question Answering Benchmarking Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Agent VectorDB Question Answering Benchmarking# Here we go over how to benchmark performance on a question answering task using an agent to route between...
58c55325a07c-1
https://python.langchain.com/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
{'question': 'What is the purpose of YC?', 'answer': 'The purpose of YC is to cause startups to be founded that would not otherwise have existed.', 'steps': [{'tool': 'Paul Graham QA System', 'tool_input': None}, {'tool': None, 'tool_input': 'What is the purpose of YC?'}]} Setting up a chain# Now we need to create ...
58c55325a07c-2
https://python.langchain.com/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
from langchain.agents import AgentType tools = [ Tool( name = "State of Union QA System", func=chain_sota.run, description="useful for when you need to answer questions about the most recent state of the union address. Input should be a fully formed question." ), Tool( name =...
58c55325a07c-3
https://python.langchain.com/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
'output': 'The purpose of the NATO Alliance is to secure peace and stability in Europe after World War 2.'} Next, we can use a language model to score them programatically from langchain.evaluation.qa import QAEvalChain llm = OpenAI(temperature=0) eval_chain = QAEvalChain.from_llm(llm) graded_outputs = eval_chain.evalu...
58c55325a07c-4
https://python.langchain.com/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
Make many predictions Evaluate performance By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
a5e452c8eeec-0
https://python.langchain.com/en/latest/use_cases/evaluation/agent_benchmarking.html
.ipynb .pdf Agent Benchmarking: Search + Calculator Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Agent Benchmarking: Search + Calculator# Here we go over how to benchmark performance of an agent on tasks where it has access to a calculator and a search tool...
a5e452c8eeec-1
https://python.langchain.com/en/latest/use_cases/evaluation/agent_benchmarking.html
new_data = {"input": data["question"], "answer": data["answer"]} try: predictions.append(agent(new_data)) predicted_dataset.append(new_data) except Exception as e: predictions.append({"output": str(e), **new_data}) error_dataset.append(new_data) Evaluate performance# Now we can e...
0055a6a278c0-0
https://python.langchain.com/en/latest/use_cases/evaluation/generic_agent_evaluation.html
.ipynb .pdf Generic Agent Evaluation Contents Setup Testing the Agent Evaluating the Agent Generic Agent Evaluation# Good evaluation is key for quickly iterating on your agent’s prompts and tools. Here we provide an example of how to use the TrajectoryEvalChain to evaluate your agent. Setup# Let’s start by defining o...
0055a6a278c0-1
https://python.langchain.com/en/latest/use_cases/evaluation/generic_agent_evaluation.html
llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo") agent = initialize_agent( tools, llm, agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION, verbose=True, memory=memory, return_intermediate_steps=True, # This is needed for the evaluation later ) Testing the Agent# Now let’s try our a...
0055a6a278c0-2
https://python.langchain.com/en/latest/use_cases/evaluation/generic_agent_evaluation.html
"action_input": "The length of the Eiffel Tower is 324 meters. The distance from coast to coast in the US is approximately 4,828 kilometers. First, we need to convert 4,828 kilometers to meters, which gives us 4,828,000 meters. To find out how many Eiffel Towers we need, we can divide 4,828,000 by 324. This gives us ap...
0055a6a278c0-3
https://python.langchain.com/en/latest/use_cases/evaluation/generic_agent_evaluation.html
The length of the Eiffel Tower is 324 meters. The distance from coast to coast in the US is approximately 4,828 kilometers. First, we need to convert 4,828 kilometers to meters, which gives us 4,828,000 meters. To find out how many Eiffel Towers we need, we can divide 4,828,000 by 324. This gives us approximately 14,90...
0055a6a278c0-4
https://python.langchain.com/en/latest/use_cases/evaluation/generic_agent_evaluation.html
print("Score from 1 to 5: ", evaluation["score"]) print("Reasoning: ", evaluation["reasoning"]) Score from 1 to 5: 1 Reasoning: First, let's evaluate the final answer. The final answer is incorrect because it uses the volume of golf balls instead of ping pong balls. The answer is not helpful. Second, does the model u...
0055a6a278c0-5
https://python.langchain.com/en/latest/use_cases/evaluation/generic_agent_evaluation.html
print("Score from 1 to 5: ", evaluation["score"]) print("Reasoning: ", evaluation["reasoning"]) Score from 1 to 5: 3 Reasoning: i. Is the final answer helpful? Yes, the final answer is helpful as it provides an approximate number of Eiffel Towers needed to cover the US from coast to coast. ii. Does the AI language us...
0055a6a278c0-6
https://python.langchain.com/en/latest/use_cases/evaluation/generic_agent_evaluation.html
© Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
a6d05da274c0-0
https://python.langchain.com/en/latest/use_cases/evaluation/question_answering.html
.ipynb .pdf Question Answering Contents Setup Examples Predictions Evaluation Customize Prompt Evaluation without Ground Truth Comparing to other evaluation metrics Question Answering# This notebook covers how to evaluate generic question answering problems. This is a situation where you have an example containing a ...
a6d05da274c0-1
https://python.langchain.com/en/latest/use_cases/evaluation/question_answering.html
{'text': ' No, this sentence is not plausible. Joao Moutinho is a professional soccer player, not an American football player, so it is not likely that he would be catching a screen pass in the NFC championship.'}] Evaluation# We can see that if we tried to just do exact match on the answer answers (11 and No) they wou...
a6d05da274c0-2
https://python.langchain.com/en/latest/use_cases/evaluation/question_answering.html
Predicted Answer: No, this sentence is not plausible. Joao Moutinho is a professional soccer player, not an American football player, so it is not likely that he would be catching a screen pass in the NFC championship. Predicted Grade: CORRECT Customize Prompt# You can also customize the prompt that is used. Here is ...
a6d05da274c0-3
https://python.langchain.com/en/latest/use_cases/evaluation/question_answering.html
"context": "I am 30 years old. I live in New York and take the train to work everyday.", }, { "question": 'Who won the NFC championship game in 2023?"', "context": "NFC Championship Game 2023: Philadelphia Eagles 31, San Francisco 49ers 7" } ] QA_PROMPT = "Answer the question based on the c...
a6d05da274c0-4
https://python.langchain.com/en/latest/use_cases/evaluation/question_answering.html
new_examples = examples.copy() for eg in new_examples: del eg ['question'] del eg['answer'] from evaluate import load squad_metric = load("squad") results = squad_metric.compute( references=new_examples, predictions=predictions, ) results {'exact_match': 0.0, 'f1': 28.125} previous QA Generation next SQ...
0f6c85dcc817-0
https://python.langchain.com/en/latest/use_cases/evaluation/sql_qa_benchmarking_chinook.html
.ipynb .pdf SQL Question Answering Benchmarking: Chinook Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance SQL Question Answering Benchmarking: Chinook# Here we go over how to benchmark performance on a question answering task over a SQL database. It is highly r...
0f6c85dcc817-1
https://python.langchain.com/en/latest/use_cases/evaluation/sql_qa_benchmarking_chinook.html
Setting up a chain# This uses the example Chinook database. To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at the root of this repository. Note that here we load a simple chain. If you want to experiment with more complex chains, or ...
0f6c85dcc817-2
https://python.langchain.com/en/latest/use_cases/evaluation/sql_qa_benchmarking_chinook.html
graded_outputs = eval_chain.evaluate(predicted_dataset, predictions, question_key="question", prediction_key="result") We can add in the graded output to the predictions dict and then get a count of the grades. for i, prediction in enumerate(predictions): prediction['grade'] = graded_outputs[i]['text'] from collect...
9f3833746519-0
https://python.langchain.com/en/latest/use_cases/evaluation/benchmarking_template.html
.ipynb .pdf Benchmarking Template Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Benchmarking Template# This is an example notebook that can be used to create a benchmarking notebook for a task of your choice. Evaluation is really hard, and so we greatly welc...
9f3833746519-1
https://python.langchain.com/en/latest/use_cases/evaluation/benchmarking_template.html
Any guide to evaluating performance in a more systematic manner goes here. previous Agent VectorDB Question Answering Benchmarking next Data Augmented Question Answering Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance By Harrison Chase © Copyright...
017e72aabb99-0
https://python.langchain.com/en/latest/use_cases/evaluation/qa_benchmarking_pg.html
.ipynb .pdf Question Answering Benchmarking: Paul Graham Essay Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Question Answering Benchmarking: Paul Graham Essay# Here we go over how to benchmark performance on a question answering task over a Paul Graham essa...
017e72aabb99-1
https://python.langchain.com/en/latest/use_cases/evaluation/qa_benchmarking_pg.html
from langchain.llms import OpenAI chain = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=vectorstore.as_retriever(), input_key="question") Make a prediction# First, we can make predictions one datapoint at a time. Doing it at this level of granularity allows use to explore the outputs in detail...
017e72aabb99-2
https://python.langchain.com/en/latest/use_cases/evaluation/qa_benchmarking_pg.html
We can also filter the datapoints to the incorrect examples and look at them. incorrect = [pred for pred in predictions if pred['grade'] == " INCORRECT"] incorrect[0] {'question': 'What did the author write their dissertation on?', 'answer': 'The author wrote their dissertation on applications of continuations.', 're...
80f895de3d1c-0
https://python.langchain.com/en/latest/use_cases/evaluation/data_augmented_question_answering.html
.ipynb .pdf Data Augmented Question Answering Contents Setup Examples Evaluate Evaluate with Other Metrics Data Augmented Question Answering# This notebook uses some generic prompts/language models to evaluate an question answering system that uses other sources of data besides what is in the model. For example, this...
80f895de3d1c-1
https://python.langchain.com/en/latest/use_cases/evaluation/data_augmented_question_answering.html
} ] # Generated examples from langchain.evaluation.qa import QAGenerateChain example_gen_chain = QAGenerateChain.from_llm(OpenAI()) new_examples = example_gen_chain.apply_and_parse([{"doc": t} for t in texts[:5]]) new_examples [{'query': 'According to the document, what did Vladimir Putin miscalculate?', 'answer': 'H...
80f895de3d1c-2
https://python.langchain.com/en/latest/use_cases/evaluation/data_augmented_question_answering.html
graded_outputs = eval_chain.evaluate(examples, predictions) for i, eg in enumerate(examples): print(f"Example {i}:") print("Question: " + predictions[i]['query']) print("Real Answer: " + predictions[i]['answer']) print("Predicted Answer: " + predictions[i]['result']) print("Predicted Grade: " + grad...
80f895de3d1c-3
https://python.langchain.com/en/latest/use_cases/evaluation/data_augmented_question_answering.html
Example 4: Question: How many countries were part of the coalition formed to confront Putin? Real Answer: 27 members of the European Union, France, Germany, Italy, the United Kingdom, Canada, Japan, Korea, Australia, New Zealand, and many others, even Switzerland. Predicted Answer: The coalition included freedom-lovin...
80f895de3d1c-4
https://python.langchain.com/en/latest/use_cases/evaluation/data_augmented_question_answering.html
First you can get an API key from the Inspired Cognition Dashboard and do some setup: export INSPIREDCO_API_KEY="..." pip install inspiredco import inspiredco.critique import os critique = inspiredco.critique.Critique(api_key=os.environ['INSPIREDCO_API_KEY']) Then run the following code to set up the configuration and ...
80f895de3d1c-5
https://python.langchain.com/en/latest/use_cases/evaluation/data_augmented_question_answering.html
print(f"Example {i}:") print("Question: " + predictions[i]['query']) print("Real Answer: " + predictions[i]['answer']) print("Predicted Answer: " + predictions[i]['result']) print("Predicted Scores: " + score_string) print() Example 0: Question: What did the president say about Ketanji Brown Jackson...
80f895de3d1c-6
https://python.langchain.com/en/latest/use_cases/evaluation/data_augmented_question_answering.html
Example 3: Question: Who is the Ukrainian Ambassador to the United States? Real Answer: The Ukrainian Ambassador to the United States is here tonight. Predicted Answer: I don't know. Predicted Scores: rouge=0.0000, chrf=0.0375, bert_score=0.3159, uni_eval=0.7493 Example 4: Question: How many countries were part of the...
80f895de3d1c-7
https://python.langchain.com/en/latest/use_cases/evaluation/data_augmented_question_answering.html
Question: How much direct assistance is the United States providing to Ukraine? Real Answer: The United States is providing more than $1 Billion in direct assistance to Ukraine. Predicted Answer: The United States is providing more than $1 billion in direct assistance to Ukraine. Predicted Scores: rouge=1.0000, chrf=0...
ede06440915a-0
https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html
.ipynb .pdf Multi-Player Dungeons & Dragons Contents Import LangChain related modules DialogueAgent class DialogueSimulator class Define roles and quest Ask an LLM to add detail to the game description Use an LLM to create an elaborate quest description Main Loop Multi-Player Dungeons & Dragons# This notebook shows h...
ede06440915a-1
https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html
self.message_history = ["Here is the conversation so far."] def send(self) -> str: """ Applies the chatmodel to the message history and returns the message string """ message = self.model( [ self.system_message, HumanMessage(content...