Fixing merge issues

This commit is contained in:
Colin Jarvis 2023-05-02 09:30:35 +01:00
parent 257d0cd9e1
commit 97319dd69a

View File

@ -10,20 +10,11 @@
"This notebook takes you through how to use LangChain to augment an OpenAI model with access to external tools. In particular, you'll be able to create LLM agents that use custom tools to answer user queries.\n",
"\n",
"\n",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"## What is Langchain?\n",
"[LangChain](https://python.langchain.com/en/latest/index.html) is a framework for developing applications powered by language models. Their framework enables you to build layered LLM-powered applications that are context-aware and able to interact dynamically with their environment as agents, leading to simplified code for you and a more dynamic user experience for your customers.\n",
"\n",
"## Why do LLMs need to use Tools?\n",
"One of the most common challenges with LLMs is overcoming the lack of recency and specificity in their training data - answers can be out of date, and they are prone to hallucinations given the huge variety in their knowledge base. Tools are a great method of allowing an LLM to answer within a controlled context that draws on your existing knowledge bases and internal APIs - instead of trying to prompt engineer the LLM all the way to your intended answer, you allow it access to tools that it calls on dynamically for info, parses, and serves to customer. \n",
=======
"## What is Langchain\n",
"\n",
"LangChain is a [framework](https://python.langchain.com/en/latest/index.html) for developing applications powered by language models. Its main features include prompt chaining (running a sequence of language model queries in which outputs of earlier queries are made part of the input of later queries) and utilities for converting language models into tool-using agents.\n",
"\n",
"\n",
"## Why do LLMs need to use Tools\n",
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"\n",
"Providing LLMs access to tools can enable them to answer questions with context directly from search engines, APIs or your own databases. Instead of answering directly, an LLM with access to tools can perform intermediate steps to gather relevant information. Tools can also be used in combination. [For example](https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html), a language model can be made to use a search tool to lookup quantitative information and a calculator to execute calculations.\n",
"\n",
@ -180,17 +171,10 @@
"\n",
"An [LLM agent](https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html) in Langchain has many configurable components, which are detailed in the Langchain documentation.\n",
"\n",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"We'll employ a few of the core concepts to make an agent who talks in the way we want, can use tools to answer questions, and uses the appropriate language model to power the conversation.\n",
"- **Prompt Template:** The input template to control the LLM's behaviour and how it accepts inputs and produces outputs - this is the brain that drives your application ([docs](https://python.langchain.com/en/latest/modules/prompts/prompt_templates.html)).\n",
"- **Output Parser:** A method of parsing the output from the prompt. If the LLM produces output using certain headers, you can enable complex interactions where variables are generated by the LLM in their response and passed into the next step of the chain ([docs](https://python.langchain.com/en/latest/modules/prompts/output_parsers.html)).\n",
"- **LLM Chain:** A Chain brings together a prompt template with an LLM that will execute it - in this case we'll be using ```gpt-3.5-turbo``` but this framework can be used with OpenAI completions models, or other LLMs entirely ([docs](https://python.langchain.com/en/latest/modules/chains.html)).\n",
=======
"We'll employ a few of the core concepts to make an agent who talks in the way we want, can use tools to answer questions, and uses the right base LLM to power the conversation.\n",
"- **Prompt Template:** The template to control the LLM's behaviour, in particular what inputs it expects and what outputs it produces ([docs](https://python.langchain.com/en/latest/modules/prompts/prompt_templates.html)).\n",
"- **Output Parser:** The LLM can specify actions to be taken but these actions need to be parsed from its outputs ([docs](https://python.langchain.com/en/latest/modules/prompts/output_parsers.html)).\n",
"- **LLM Chain:** A Chain brings together a prompt template with a LLM that will execute it - in this case we'll be using ```gpt-3.5-turbo```([docs](https://python.langchain.com/en/latest/modules/chains.html)).\n",
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"- **Tool:** An external service that the LLM can use to retrieve information or execute commands should the user require it ([docs](https://python.langchain.com/en/latest/modules/agents/tools.html)).\n",
"- **Agent:** The glue that brings all of this together, an agent can call multiple LLM Chains, each with their own tools. Agents can be extended with your own logic to allow retries, error handling and any other methods you choose to add reliability to your application ([docs](https://python.langchain.com/en/latest/modules/agents.html)).\n",
"\n",
@ -384,17 +368,12 @@
"Action: Search\n",
"Action Input: \"Canada population 2023\"\u001B[0m\n",
"\n",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"Observation:\u001b[36;1m\u001b[1;3m39,566,248\u001b[0m\u001b[32;1m\u001b[1;3mAhoy, that be a lot of people! But I need to make sure this be true.\n",
"Action: Search\n",
"Action Input: \"Canada population 2023 official source\"\u001b[0m\n",
"\n",
"Observation:\u001b[36;1m\u001b[1;3mThe current population of Canada is 38,664,637 as of Wednesday, April 19, 2023, based on Worldometer elaboration of the latest United Nations data.\u001b[0m\u001b[32;1m\u001b[1;3mArrr, that be the official number! I be confident in me answer now.\n",
"Final Answer: The population of Canada as of 2023 is 38,664,637. Arg!\u001b[0m\n",
=======
"Observation:\u001B[36;1m\u001B[1;3mThe current population of Canada is 38,662,830 as of Monday, April 17, 2023, based on Worldometer elaboration of the latest United Nations data.\u001B[0m\u001B[32;1m\u001B[1;3mAhoy, that be the answer I was lookin' for!\n",
"Final Answer: The population of Canada as of 2023 be 38,662,830, Arg!\u001B[0m\n",
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"\n",
"\u001B[1m> Finished chain.\u001B[0m\n"
]
@ -558,17 +537,12 @@
"Action: Search\n",
"Action Input: \"Canada population 2023\"\u001B[0m\n",
"\n",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"Observation:\u001b[36;1m\u001b[1;3m39,566,248\u001b[0m\u001b[32;1m\u001b[1;3mThis data seems reliable, but I should double-check the source.\n",
"Action: Search\n",
"Action Input: \"Source of Canada population 2023\"\u001b[0m\n",
"\n",
"Observation:\u001b[36;1m\u001b[1;3mThe current population of Canada is 38,664,637 as of Wednesday, April 19, 2023, based on Worldometer elaboration of the latest United Nations data. Canada 2020 population is estimated at 37,742,154 people at mid year according to UN data. Canada population is equivalent to 0.48% of the total world population.\u001b[0m\u001b[32;1m\u001b[1;3mI now know the final answer\n",
"Final Answer: As of April 19, 2023, the population of Canada is 38,664,637.\u001b[0m\n",
=======
"Observation:\u001B[36;1m\u001B[1;3mThe current population of Canada is 38,662,830 as of Monday, April 17, 2023, based on Worldometer elaboration of the latest United Nations data.\u001B[0m\u001B[32;1m\u001B[1;3mThat's the answer to the question.\n",
"Final Answer: As of April 17, 2023, the population of Canada is 38,662,830.\u001B[0m\n",
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"\n",
"\u001B[1m> Finished chain.\u001B[0m\n"
]
@ -609,13 +583,8 @@
"Action: Search\n",
"Action Input: \"population of Mexico 2023\"\u001B[0m\n",
"\n",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"Observation:\u001b[36;1m\u001b[1;3m132,709,512\u001b[0m\u001b[32;1m\u001b[1;3mI now know the final answer.\n",
"Final Answer: As of 2023, the population of Mexico is 132,709,512.\u001b[0m\n",
=======
"Observation:\u001B[36;1m\u001B[1;3m128,455,567\u001B[0m\u001B[32;1m\u001B[1;3mI now know the final answer.\n",
"Final Answer: As of 2023, the population of Mexico is 128,455,567.\u001B[0m\n",
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"\n",
"\u001B[1m> Finished chain.\u001B[0m\n"
]
@ -1003,11 +972,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"execution_count": 54,
=======
"execution_count": null,
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"id": "d1e12121",
"metadata": {
"pycharm": {
@ -1057,17 +1022,11 @@
"text": [
"\n",
"\n",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mThought: This is an interesting question. I'm not sure if I have the answer in my knowledge base, so I might need to search for it.\n",
=======
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3mThought: This is an interesting question. I'm not sure if this is possible, but I'll try to find out.\n",
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"Action: Search\n",
"Action Input: \"How to live without a bank account\"\u001B[0m\n",
"\n",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"Observation:\u001b[36;1m\u001b[1;3mUnderbanked households have a checking or savings account but also use alternative financial services such as money orders, check cashing, international remittances, payday loans, refund anticipation loans, rent-to-own services, pawnshop loans, or auto title loans, according to the FDIC.\u001b[0m\u001b[32;1m\u001b[1;3mIt seems like there are alternative financial services available for those who don't have a bank account. I should look into this further to provide a more comprehensive answer.\n",
"Action: Search\n",
"Action Input: \"Alternative financial services for those without a bank account\"\u001b[0m\n",
@ -1082,23 +1041,6 @@
"\n",
"Observation:\u001b[33;1m\u001b[1;3m There are a few resources available for alternative financial services or opening a bank account. Prepaid credit cards are becoming more popular and can be found at convenience stores. Capital One offers commercial solutions and a comprehensive suite of financial services tailored to short and long term goals. Airbnb also offers Air Cover for Hosts, which provides $1 million in damage protection, pet damage protection, and income loss protection.\u001b[0m\u001b[32;1m\u001b[1;3mIt's important to note that while prepaid credit cards and alternative financial services can be helpful, they may not offer the same level of protection and benefits as a traditional bank account. It's also important to do research and compare options before making a decision. \n",
"Final Answer: While it is possible to live without a bank account by using alternative financial services, it may come with potential drawbacks and limitations. It's important to do research and compare options before making a decision, and there are resources available for those who may be interested in opening a bank account or exploring alternative financial services.\u001b[0m\n",
=======
"Observation:\u001B[36;1m\u001B[1;3mUnderbanked households have a checking or savings account but also use alternative financial services such as money orders, check cashing, international remittances, payday loans, refund anticipation loans, rent-to-own services, pawnshop loans, or auto title loans, according to the FDIC.\u001B[0m\u001B[32;1m\u001B[1;3mIt seems like there are ways to live without a bank account, but it may not be easy. I should look for more information on alternative financial services.\n",
"Action: Search\n",
"Action Input: \"Alternative financial services for the underbanked\"\u001B[0m\n",
"\n",
"Observation:\u001B[36;1m\u001B[1;3mInstead, people who are unbanked use alternative financial services—payday loans, money orders, check cashing services, pawnshop loans, and the like—to meet their banking needs. These financial services fill an important role for unbanked individuals, but they can also cause further financial hardship.\u001B[0m\u001B[32;1m\u001B[1;3mIt seems like there are both advantages and disadvantages to using alternative financial services. I should look for more information on how to manage finances without a bank account.\n",
"Action: Knowledge Base\n",
"Action Input: \"How to manage finances without a bank account\"\u001B[0m\n",
"\n",
"Observation:\u001B[33;1m\u001B[1;3m There are a few things that you can do to manage your finances without a bank account. You can try an alternative currency, get a payday loan from a standard banking institution, or use a prepaid credit card. However, it is important to be aware that prepaid credit cards can be easy to scam, so it is important to be careful when using them.\u001B[0m\u001B[32;1m\u001B[1;3mIt seems like there are some options for managing finances without a bank account, but they may come with risks. I should look for more information on the pros and cons of each option.\n",
"Action: Search\n",
"Action Input: \"Pros and cons of alternative currency, payday loans, and prepaid credit cards\"\u001B[0m\n",
"\n",
"Observation:\u001B[36;1m\u001B[1;3mHere we explore the good, the bad, and the alternatives to cash advances ... Payday loan cash advances: The payday loan operates much like the name implies.\u001B[0m\u001B[32;1m\u001B[1;3mIt seems like there are pros and cons to each option for managing finances without a bank account. I should summarize the information I found to provide a comprehensive answer.\n",
"Thought: Based on my research, it is possible to live without a bank account by using alternative financial services such as payday loans, money orders, check cashing services, pawnshop loans, and prepaid credit cards. However, these options come with risks such as high fees and the potential for scams. It is important to carefully consider the pros and cons of each option and to be cautious when using them. It may also be helpful to seek advice from a financial advisor or credit counselor. \n",
"Final Answer: It is possible to live without a bank account by using alternative financial services, but it is important to carefully consider the risks and to seek advice from a financial professional.\u001B[0m\n",
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"\n",
"\u001B[1m> Finished chain.\u001B[0m\n"
]
@ -1130,7 +1072,6 @@
"text": [
"\n",
"\n",
<<<<<<< HEAD:examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mThought: This is a complex topic that requires a balanced perspective\n",
"Action: Knowledge Base\n",
@ -1142,23 +1083,6 @@
"\n",
"Observation:\u001b[36;1m\u001b[1;3mThere are dedicated species survival programs which have helped species come out from the brink of extinction, good examples of that being the black-footed ferrets, the red wolves, the Przewalski's wild horse, and the California condors.\u001b[0m\u001b[32;1m\u001b[1;3mWhile there are valid arguments on both sides, it seems that zoos can have a positive impact on conservation efforts for endangered species.\n",
"Final Answer: Zoos can have both positive and negative effects on animals, but they can play a role in conservation efforts for endangered species. It's important to consider both sides of the argument and do research before forming an opinion.\u001b[0m\n",
=======
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3mThought: This is a complex topic that requires a balanced perspective\n",
"Action: Search\n",
"Action Input: \"Pros and cons of zoos for animals\"\u001B[0m\n",
"\n",
"Observation:\u001B[36;1m\u001B[1;3mZoos are detrimental to animals' physical health. A study of 35 species of carnivores, including brown bears, cheetahs, and lions, found that zoo enclosures ...\u001B[0m\u001B[32;1m\u001B[1;3mI need to find more information to provide a balanced perspective\n",
"Action: Search\n",
"Action Input: \"Arguments for and against zoos\"\u001B[0m\n",
"\n",
"Observation:\u001B[36;1m\u001B[1;3mWhile zoo advocates and conservationists argue that zoos save endangered species and educate the public, many animal rights activists believe the cost of ...\u001B[0m\u001B[32;1m\u001B[1;3mI need to provide some specific examples to illustrate the arguments for and against zoos\n",
"Action: Knowledge Base\n",
"Action Input: \"What are some specific examples of arguments for and against zoos?\"\u001B[0m\n",
"\n",
"Observation:\u001B[33;1m\u001B[1;3m Arguments for zoos include that they have gotten a lot better in the last 30-40 years, they participate in research and conservation projects, and they have helped to save species from extinction. Arguments against zoos include that they are still businesses, they often don't educate the public as much as they claim, and they still capture animals from the wild.\u001B[0m\u001B[32;1m\u001B[1;3mI now know the final answer\n",
"Final Answer: The debate over whether zoos are good or bad for animals is complex and multifaceted. While some argue that zoos play an important role in conservation and education, others believe that they are detrimental to animals' physical and mental health and that they perpetuate the idea that animals exist for human entertainment. Ultimately, the answer to whether zoos are good or bad for animals depends on a variety of factors, including the quality of the zoo, the species of animals involved, and the specific goals of the zoo.\u001B[0m\n",
>>>>>>> 2b6f6392b1ff679ed0ff246202f9a2cf5b3f9b12:examples/Conversational_agents_using_tools.ipynb
"\n",
"\u001B[1m> Finished chain.\u001B[0m\n"
]