Using AutoGPT with LangChain

# Using AutoGPT with LangChain
You should only respond in JSON format as described below Response Format: { "thoughts": { "text": "thought", "reasoning": "reasoning", "plan": "- short bulleted\n- list that conveys\n- long-term plan", "criticism": "constructive self-criticism", "speak": "thoughts summary to say to the user" }, "command": { "name": "command name", "args": { "arg name": "value" } } } Ensure the response can be parsed by Python json.loads System: The current time and date is Thu May 18 18:17:48 2023 System: This reminds you of these events from your past: [] Human: Determine which next command to use, and respond using the format specified above:*** ``` This is the prompt that AutoGPT sends to the LLM for a text continuation. From it, we see: 1. That role-prompting is used at the beginning, having an autonomous assistant called Jim. 2. The goal that the assistant should pursue, i.e., “Provide an analysis of the major historical events that led to the French Revolution.” 3. A set of constraints explicitly explain to the LLM that it has limited memory and that memories are saved into txt files, from which they can also be retrieved. 4. A set of commands that the assistant can issue, i.e. (1) “search” to look for external knowledge using a search engine, (2) “write_file” to write content into a file (for storing memories), (3) “read_file” to read content from a file (for retrieving memories) and (4) “Finish” to return the final result and stop the computations. 5. The assistant can use a set of high-level resources, like Internet access and an LLM agent, to perform single tasks. 6. A set of instructions about continuously refining the assistant plan. 7. A response format that the assistant should conform to when answering. Notice that the response format “forces” the LLM into explicitly writing its thinking, reasoning, and a devised plan (i.e., a bullet point list of steps to reach the aforementioned goal). Then, the agent criticizes the plan (i.e., explains what it needs to be careful of) and writes in the “speak” field a natural language explanation of the next action it’s going to do from its plan. All these fields explicitly lead the LLM to think about the next step to do and eventually output a command. 8. Last, the prompt also contains the current time and date and a list of similar past events (which is now empty but won’t be empty in the successive interactions with the assistant). Let’s see how the agent’s output is to that prompt. Here the output continues: ``` { "thoughts": { "text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.", "reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events and how they contributed to the revolution.", "plan": "- Research the key events that led to the French Revolution\n- Organize the events chronologically\n- Analyze the events to determine their significance in the lead up to the revolution", "criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.", "speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically." }, "command": { "name": "search", "args": {


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
"tool_input": "Key events that led to the French Revolution" } } } ``` Here, the agent wrote the output in the expected JSON format. Reading through the “text” and “reasoning,” we see what the agent has thought about before devising the “plan.” Then, the plan is criticized in the “criticism” field, and a natural language explanation is written in the “speak” field. Last, the agent selected as command the “search” command, with the "Key events that led to the French Revolution" value for the “tool_input” parameter. Once the “search” tool returns its answer, we see the next prompt created by AutoGPT. We’ll show mainly the parts of the prompt which are different from the previous prompt. ``` System: You are Jim, Assistant Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications. If you have completed all your tasks, make sure to use the "finish" command. GOALS: 1. Provide an analysis of the major historical events that led to the French Revolution Constraints: 1. ~4000-word limit for short-term memory. Your short-term memory is short, so immediately save important information to files. 2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember. 3. No user assistance 4. Exclusively use the commands listed in double quotes e.g. "command name" Commands: 1. search: Useful for when you need to answer questions about current events. You should ask targeted questions, args json schema: {"tool_input": {"type": "string"}} 2. write_file: Write the file to disk, args json schema: {"file_path": {"title": "File Path", "description": "name of file", "type": "string"}, "text": {"title": "Text", "description": "text to write to file", "type": "string"}, "append": {"title": "Append", "description": "Whether to append to an existing file.", "default": false, "type": "boolean"}} 3. read_file: Read the file from disk, args json schema: {"file_path": {"title": "File Path", "description": "name of file", "type": "string"}} 4. finish: use this to signal that you have finished all your objectives, args: "response": "final response to let people know you have finished your objectives" Resources: 1. Internet access for searches and information gathering. 2. Long Term memory management. 3. GPT-3.5 powered Agents for delegation of simple tasks. 4. File output. Performance Evaluation: 1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities. 2. Constructively self-criticize your big-picture behavior constantly. 3. Reflect on past decisions and strategies to refine your approach. 4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. You should only respond in JSON format as described below Response Format: { "thoughts": { "text": "thought", "reasoning": "reasoning", "plan": "- short bulleted\n- list that conveys\n- long-term plan", "criticism": "constructive self-criticism", "speak": "thoughts summary to say to the user" }, "command": { "name": "command name", "args": { "arg name": "value" } } } Ensure the response can be parsed by Python json.loads System: The current time and date is Thu May 18 18:18:13 2023 System: This reminds you of these events from your past: ['Assistant Reply: {\n "thoughts": {\n "text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.",\n "reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
and how they contributed to the revolution.",\n "plan": "- Research the key events that led to the French Revolution\\n- Organize the events chronologically\\n- Analyze the events to determine their significance in the lead up to the revolution",\n "criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.",\n "speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically."\n },\n "command": {\n "name": "search",\n "args": {\n "tool_input": "Key events that led to the French Revolution"\n }\n }\n} \nResult: Command search returned: Table of Contents · Causes of the French Revolution · Estates General · Rise of the Third Estate · Tennis Court Oath · The Bastille · Declaration of the Rights of Man\xa0... Some key moments in the French Revolution, 1789- 1794; April 25. The first use of guillotine; June 13. Prussia declares war on France; August 9. Paris Commune\xa0... 14 July 1789: Storming of Bastille ... A wave of revolutionary hysteria sweeps through Paris, leading to fears of a military coup. In retaliation, rebels storm\xa0... 4 days ago ... Why did the French Revolution lead to war with other nations? ... distinguish that event from the later French revolutions of 1830 and 1848. Jun 18, 2021 ... In 1789, the French people were not happy. Due to war and King Louis XVI\'s spending habits, the country was utterly broke. On top of that, the\xa0... Jan 24, 2019 ... Iran\'s Islamic Revolution shook the world in 1979, with currents that ... together a timeline featuring key events that led to the fall of\xa0... A summary of the causes of the French Revolution, including the Enlightenment, the estates system, the American Revolution, and absolutism. Eleven Major Events In the French Revolution · Call of the Estate General (May 5, 1789) · Tennis Court Oath (June 20, 1789) · Storming of the Bastille (July 14,\xa0... Congress, led by Representative James Madison, enacts the first protective tariff. ... When the French Revolution turned violent in 1792, however,\xa0... Dec 5, 2018 ... The execution of King Louis XVI and his wife Marie Antoinette resulted in the Revolution entering its most bloody stage known as the Reign of\xa0... '] Human: Determine which next command to use, and respond using the format specified above: AI: { "thoughts": { "text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.", "reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events and how they contributed to the revolution.", "plan": "- Research the key events that led to the French Revolution\n- Organize the events chronologically\n- Analyze the events to determine their significance in the lead up to the revolution", "criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.", "speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically." }, "command": { "name": "search", "args": { "tool_input": "Key events that led to the French Revolution" }


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
} } System: Command search returned: Table of Contents · Causes of the French Revolution · Estates General · Rise of the Third Estate · Tennis Court Oath · The Bastille · Declaration of the Rights of Man ... Some key moments in the French Revolution, 1789- 1794; April 25. The first use of guillotine; June 13. Prussia declares war on France; August 9. Paris Commune ... 14 July 1789: Storming of Bastille ... A wave of revolutionary hysteria sweeps through Paris, leading to fears of a military coup. In retaliation, rebels storm ... 4 days ago ... Why did the French Revolution lead to war with other nations? ... distinguish that event from the later French revolutions of 1830 and 1848. Jun 18, 2021 ... In 1789, the French people were not happy. Due to war and King Louis XVI's spending habits, the country was utterly broke. On top of that, the ... Jan 24, 2019 ... Iran's Islamic Revolution shook the world in 1979, with currents that ... together a timeline featuring key events that led to the fall of ... A summary of the causes of the French Revolution, including the enlightenment, estates system, American Revolution, and absolutism. Eleven Major Events In the French Revolution · Call of the Estate General (May 5, 1789) · Tennis Court Oath (June 20, 1789) · Storming of the Bastille (July 14, ... Congress, led by Representative James Madison, enacts the first protective tariff. ... When the French Revolution turned violent in 1792, however, ... Dec 5, 2018 ... The execution of King Louis XVI and his wife Marie Antoinette resulted in the Revolution entering its most bloody stage known as the Reign of ... Human: Determine which next command to use, and respond using the format specified above: ``` ```python ***System: You are Jim, Assistant Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications. If you have completed all your tasks, make sure to use the "finish" command.*** ***GOALS:*** […] ***Constraints:*** […] ***Commands:*** […] ***Resources:*** […] ***Performance Evaluation:*** […] ***You should only respond in JSON format as described below Response Format:*** […] ***Ensure the response can be parsed by Python json.loads*** ***System: The current time and date is Thu May 18 18:18:13 2023*** ***System: This reminds you of these events from your past: ['Assistant Reply: {\n "thoughts": {\n "text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.",\n "reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events and how they contributed to the revolution.",\n "plan": "- Research the key events that led to the French Revolution\n- Organize the events chronologically\n- Analyze the events to determine their significance in the lead up to the revolution",\n "criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.",\n "speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically."\n },\n "command": {\n "name": "search",\n "args": {\n "tool_input": "Key events that led to the French Revolution"\n }\n }\n} \nResult: Command search returned: Table of


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
Contents · Causes of the French Revolution · Estates General · Rise of the Third Estate · Tennis Court Oath · The Bastille · Declaration of the Rights of Man\xa0... Some key moments in the French Revolution, 1789- 1794; April 25. The first use of guillotine; June 13. Prussia declares war on France; August 9. Paris Commune\xa0... 14 July 1789: Storming of Bastille ... A wave of revolutionary hysteria sweeps through Paris, leading to fears of a military coup. In retaliation, rebels storm\xa0... 4 days ago ... Why did the French Revolution lead to war with other nations? ... distinguish that event from the later French revolutions of 1830 and 1848. Jun 18, 2021 ... In 1789, the French people were not happy. Due to war and King Louis XVI's spending habits, the country was utterly broke. On top of that, the\xa0... Jan 24, 2019 ... Iran's Islamic Revolution shook the world in 1979, with currents that ... together a timeline featuring key events that led to the fall of\xa0... A summary of the causes of the French Revolution, including the Enlightenment, the estates system, the American Revolution, and absolutism. Eleven Major Events In the French Revolution · Call of the Estate General (May 5, 1789) · Tennis Court Oath (June 20, 1789) · Storming of the Bastille (July 14,\xa0... Congress, led by Representative James Madison, enacts the first protective tariff. ... When the French Revolution turned violent in 1792, however,\xa0... Dec 5, 2018 ... The execution of King Louis XVI and his wife Marie Antoinette resulted in the Revolution entering its most bloody stage known as the Reign of\xa0... ']*** ***Human: Determine which next command to use, and respond using the format specified above:*** ***AI: {*** ***"thoughts": {*** ***"text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.",*** ***"reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events and how they contributed to the revolution.",*** ***"plan": "- Research the key events that led to the French Revolution\n- Organize the events chronologically\n- Analyze the events to determine their significance in the lead up to the revolution",*** ***"criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.",*** ***"speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically." },*** ***"command": {*** ***"name": "search",*** ***"args": { "tool_input": "Key events that led to the French Revolution" }*** ***}*** ***}*** ***System: Command search returned: Table of Contents · Causes of the French Revolution · Estates General · Rise of the Third Estate · Tennis Court Oath · The Bastille · Declaration of the Rights of Man ... Some key moments in the French Revolution, 1789- 1794; April 25. The first use of guillotine; June 13. Prussia declares war on France; August 9. Paris Commune ... 14 July 1789: Storming of Bastille ... A wave of revolutionary hysteria sweeps through Paris, leading to fears of a military coup. In retaliation, rebels storm ... 4 days ago ... Why did the French Revolution lead to war with other nations? ... distinguish that event from the later French revolutions of 1830 and 1848. Jun


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
18, 2021 ... In 1789, the French people were not happy. Due to war and King Louis XVI's spending habits, the country was utterly broke. On top of that, the ... Jan 24, 2019 ... Iran's Islamic Revolution shook the world in 1979, with currents that ... together a timeline featuring key events that led to the fall of ... A summary of the causes of the French Revolution, including the enlightenment, estates system, American Revolution, and absolutism. Eleven Major Events In the French Revolution · Call of the Estate General (May 5, 1789) · Tennis Court Oath (June 20, 1789) · Storming of the Bastille (July 14, ... Congress, led by Representative James Madison, enacts the first protective tariff. ... When the French Revolution turned violent in 1792, however, ... Dec 5, 2018 ... The execution of King Louis XVI and his wife Marie Antoinette resulted in the Revolution entering its most bloody stage known as the Reign of ...*** ***Human: Determine which next command to use, and respond using the format specified above:*** ``` In the line starting with “System: This reminds you of these events from your past:,” this time we see a non-empty list containing the LLM output from the previous interaction with the assistant, whose input and output are then added after the line “Human: Determine which next command to use and respond using the format specified above:” in a format similar to a few-shot example. The complete AutoGPT execution with this goal lasted for several minutes, and we won’t show all its intermediate steps here. The last prompt inputted to the assistant contains the following: ``` ***AI: {*** ***"thoughts": {*** ***"text": "Now that I have summarized the major historical events that led to the French Revolution, I should analyze their significance and draw some conclusions about the revolution's impact on world history. I should start by organizing my thoughts and outlining my analysis.",*** ***"reasoning": "Organizing my thoughts and outlining my analysis will help me to stay focused and ensure that I cover all the key points in my analysis. It will also help me to identify any gaps in my knowledge or areas where I need to do further research.",*** ***"plan": "- Organize my thoughts and outline my analysis of the significance of the French Revolution\n- Identify any gaps in my knowledge or areas where I need to do further research",*** ***"criticism": "I need to make sure that my analysis is well-supported by evidence and that I am accurately representing the historical events that led to the French Revolution. I should also be careful not to oversimplify the complex factors that contributed to the outbreak of the revolution.",*** ***"speak": "I will organize my thoughts and outline my analysis of the significance of the French Revolution, and identify any gaps in my knowledge or areas where I need to do further research."*** ***},*** ***"command": {*** ***"name": "write_file",*** ***"args": {*** ***"file_path": "french_revolution_analysis.txt",*** ***"text": "Analysis of the Significance of the French Revolution:\\\\n\\\\nThe French Revolution was a watershed moment in world history that had a profound impact on the political, social, and economic landscape of Europe and beyond. Some of the key factors that contributed to the significance of the French Revolution include:\\\\n\\\\n- The rise of nationalism: The French Revolution helped to popularize the idea of nationalism, which would go on to play a major role in the political and social movements of the 19th and 20th centuries.\\\\n- The spread of liberal democracy: The French Revolution helped to spread the idea of liberal democracy, which would become the dominant political system in the Western world.\\\\n- The end of


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
feudalism: The French Revolution marked the end of the feudal system in France and paved the way for the rise of capitalism and industrialization.\\\\n- The impact on international relations: The French Revolution had a major impact on international relations, leading to a series of wars and conflicts that would shape the course of European history for decades to come.\\\\ n\\\\n In conclusion, the French Revolution was a pivotal moment in world history that had a profound impact on the political, social, and economic landscape of Europe and beyond. By analyzing the significance of the French Revolution, we can gain a better understanding of the forces that have shaped the modern world.",*** ***"append": false*** ***}*** ***}*** ***}*** ***System: Command write_file returned: File written successfully to french_revolution_analysis.txt. Human: Determine which next command to use, and respond using the format specified above:*** ``` This prompt shows that the last executed command wrote the final overview into the “french_revolution_analysis.txt” file. Then, the assistant produced its final output. ```python ***I have completed my analysis of the significance of the French Revolution and have written it into a file. I will review my work and make any necessary revisions, and consider how to present my analysis to others.*** ``` ``` System: You are Jim, Assistant Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications. If you have completed all your tasks, make sure to use the "finish" command. GOALS: 1. Provide an analysis of the major historical events that led to the French Revolution Constraints: 1. ~4000-word limit for short-term memory. Your short-term memory is short, so immediately save important information to files. 2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember. 3. No user assistance 4. Exclusively use the commands listed in double quotes e.g. "command name" Commands: 1. search: Useful for when you need to answer questions about current events. You should ask targeted questions, args json schema: {"tool_input": {"type": "string"}} 2. write_file: Write the file to disk, args json schema: {"file_path": {"title": "File Path", "description": "name of file", "type": "string"}, "text": {"title": "Text", "description": "text to write to file", "type": "string"}, "append": {"title": "Append", "description": "Whether to append to an existing file.", "default": false, "type": "boolean"}} 3. read_file: Read the file from disk, args json schema: {"file_path": {"title": "File Path", "description": "name of file", "type": "string"}} 4. finish: use this to signal that you have finished all your objectives, args: "response": "final response to let people know you have finished your objectives" Resources: 1. Internet access for searches and information gathering. 2. Long Term memory management. 3. GPT-3.5 powered Agents for delegation of simple tasks. 4. File output. Performance Evaluation: 1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities. 2. Constructively self-criticize your big-picture behavior constantly. 3. Reflect on past decisions and strategies to refine your approach. 4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. You should only respond in JSON format as described below Response Format: { "thoughts": { "text": "thought", "reasoning": "reasoning", "plan": "- short bulleted\n- list that conveys\n- long-term plan", "criticism": "constructive self-criticism", "speak": "thoughts summary to say to the user" }, "command": { "name": "command name", "args": { "arg name": "value" } } } Ensure the response can be parsed by Python json.loads System: The current time and date is Thu May 18 18:18:13 2023


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
System: This reminds you of these events from your past: ['Assistant Reply: {\n "thoughts": {\n "text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.",\n "reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events and how they contributed to the revolution.",\n "plan": "- Research the key events that led to the French Revolution\\n- Organize the events chronologically\\n- Analyze the events to determine their significance in the lead up to the revolution",\n "criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.",\n "speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically."\n },\n "command": {\n "name": "search",\n "args": {\n "tool_input": "Key events that led to the French Revolution"\n }\n }\n} \nResult: Command search returned: Table of Contents · Causes of the French Revolution · Estates General · Rise of the Third Estate · Tennis Court Oath · The Bastille · Declaration of the Rights of Man\xa0... Some key moments in the French Revolution, 1789- 1794; April 25. The first use of guillotine; June 13. Prussia declares war on France; August 9. Paris Commune\xa0... 14 July 1789: Storming of Bastille ... A wave of revolutionary hysteria sweeps through Paris, leading to fears of a military coup. In retaliation, rebels storm\xa0... 4 days ago ... Why did the French Revolution lead to war with other nations? ... distinguish that event from the later French revolutions of 1830 and 1848. Jun 18, 2021 ... In 1789, the French people were not happy. Due to war and King Louis XVI\'s spending habits, the country was utterly broke. On top of that, the\xa0... Jan 24, 2019 ... Iran\'s Islamic Revolution shook the world in 1979, with currents that ... together a timeline featuring key events that led to the fall of\xa0... A summary of the causes of the French Revolution, including the Enlightenment, the estates system, the American Revolution, and absolutism. Eleven Major Events In the French Revolution · Call of the Estate General (May 5, 1789) · Tennis Court Oath (June 20, 1789) · Storming of the Bastille (July 14,\xa0... Congress, led by Representative James Madison, enacts the first protective tariff. ... When the French Revolution turned violent in 1792, however,\xa0... Dec 5, 2018 ... The execution of King Louis XVI and his wife Marie Antoinette resulted in the Revolution entering its most bloody stage known as the Reign of\xa0... '] Human: Determine which next command to use, and respond using the format specified above: AI: { "thoughts": { "text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.", "reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events and how they contributed to the revolution.", "plan": "- Research the key events that led to the French Revolution\n- Organize the events chronologically\n- Analyze the events to determine their


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
significance in the lead up to the revolution", "criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.", "speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically." }, "command": { "name": "search", "args": { "tool_input": "Key events that led to the French Revolution" } } } System: Command search returned: Table of Contents · Causes of the French Revolution · Estates General · Rise of the Third Estate · Tennis Court Oath · The Bastille · Declaration of the Rights of Man ... Some key moments in the French Revolution, 1789- 1794; April 25. The first use of guillotine; June 13. Prussia declares war on France; August 9. Paris Commune ... 14 July 1789: Storming of Bastille ... A wave of revolutionary hysteria sweeps through Paris, leading to fears of a military coup. In retaliation, rebels storm ... 4 days ago ... Why did the French Revolution lead to war with other nations? ... distinguish that event from the later French revolutions of 1830 and 1848. Jun 18, 2021 ... In 1789, the French people were not happy. Due to war and King Louis XVI's spending habits, the country was utterly broke. On top of that, the ... Jan 24, 2019 ... Iran's Islamic Revolution shook the world in 1979, with currents that ... together a timeline featuring key events that led to the fall of ... A summary of the causes of the French Revolution, including the enlightenment, estates system, American Revolution, and absolutism. Eleven Major Events In the French Revolution · Call of the Estate General (May 5, 1789) · Tennis Court Oath (June 20, 1789) · Storming of the Bastille (July 14, ... Congress, led by Representative James Madison, enacts the first protective tariff. ... When the French Revolution turned violent in 1792, however, ... Dec 5, 2018 ... The execution of King Louis XVI and his wife Marie Antoinette resulted in the Revolution entering its most bloody stage known as the Reign of ... Human: Determine which next command to use, and respond using the format specified above: ``` ``` System: You are Jim, Assistant Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications. If you have completed all your tasks, make sure to use the "finish" command. GOALS: 1. Provide an analysis of the major historical events that led to the French Revolution Constraints: 1. ~4000-word limit for short-term memory. Your short-term memory is short, so immediately save important information to files. 2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember. 3. No user assistance 4. Exclusively use the commands listed in double quotes e.g. "command name" Commands: 1. search: Useful for when you need to answer questions about current events. You should ask targeted questions, args json schema: {"tool_input": {"type": "string"}} 2. write_file: Write the file to disk, args json schema: {"file_path": {"title": "File Path", "description": "name of file", "type": "string"}, "text": {"title": "Text", "description": "text to write to file", "type": "string"}, "append": {"title": "Append", "description": "Whether to append to an existing file.", "default": false, "type": "boolean"}} 3. read_file: Read the file from disk, args json schema: {"file_path": {"title": "File Path", "description": "name of file", "type": "string"}} 4. finish:


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
use this to signal that you have finished all your objectives, args: "response": "final response to let people know you have finished your objectives" Resources: 1. Internet access for searches and information gathering. 2. Long Term memory management. 3. GPT-3.5 powered Agents for delegation of simple tasks. 4. File output. Performance Evaluation: 1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities. 2. Constructively self-criticize your big-picture behavior constantly. 3. Reflect on past decisions and strategies to refine your approach. 4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. You should only respond in JSON format as described below Response Format: { "thoughts": { "text": "thought", "reasoning": "reasoning", "plan": "- short bulleted\n- list that conveys\n- long-term plan", "criticism": "constructive self-criticism", "speak": "thoughts summary to say to the user" }, "command": { "name": "command name", "args": { "arg name": "value" } } } Ensure the response can be parsed by Python json.loads System: The current time and date is Thu May 18 18:18:13 2023 System: This reminds you of these events from your past: ['Assistant Reply: {\n "thoughts": {\n "text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.",\n "reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events and how they contributed to the revolution.",\n "plan": "- Research the key events that led to the French Revolution\\n- Organize the events chronologically\\n- Analyze the events to determine their significance in the lead up to the revolution",\n "criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.",\n "speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically."\n },\n "command": {\n "name": "search",\n "args": {\n "tool_input": "Key events that led to the French Revolution"\n }\n }\n} \nResult: Command search returned: Table of Contents · Causes of the French Revolution · Estates General · Rise of the Third Estate · Tennis Court Oath · The Bastille · Declaration of the Rights of Man\xa0... Some key moments in the French Revolution, 1789- 1794; April 25. The first use of guillotine; June 13. Prussia declares war on France; August 9. Paris Commune\xa0... 14 July 1789: Storming of Bastille ... A wave of revolutionary hysteria sweeps through Paris, leading to fears of a military coup. In retaliation, rebels storm\xa0... 4 days ago ... Why did the French Revolution lead to war with other nations? ... distinguish that event from the later French revolutions of 1830 and 1848. Jun 18, 2021 ... In 1789, the French people were not happy. Due to war and King Louis XVI\'s spending habits, the country was utterly broke. On top of that, the\xa0... Jan 24, 2019 ... Iran\'s Islamic Revolution shook the world in 1979, with currents that ... together a timeline featuring key events that led to the fall of\xa0... A summary of the causes of the French Revolution, including the Enlightenment, the estates system, the American Revolution, and absolutism. Eleven Major Events In the French Revolution · Call of the Estate General (May 5, 1789) ·


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
Tennis Court Oath (June 20, 1789) · Storming of the Bastille (July 14,\xa0... Congress, led by Representative James Madison, enacts the first protective tariff. ... When the French Revolution turned violent in 1792, however,\xa0... Dec 5, 2018 ... The execution of King Louis XVI and his wife Marie Antoinette resulted in the Revolution entering its most bloody stage known as the Reign of\xa0... '] Human: Determine which next command to use, and respond using the format specified above: AI: { "thoughts": { "text": "I need to provide an analysis of the major historical events that led to the French Revolution. I should start by researching the key events that led to the revolution and organizing them chronologically.", "reasoning": "I need to have a clear understanding of the events that led to the French Revolution before I can provide an analysis. Organizing the events chronologically will help me to better understand the sequence of events and how they contributed to the revolution.", "plan": "- Research the key events that led to the French Revolution\n- Organize the events chronologically\n- Analyze the events to determine their significance in the lead up to the revolution", "criticism": "I need to make sure that I am not overlooking any important events or factors that contributed to the French Revolution. I should also be careful not to get bogged down in too much detail and lose sight of the big picture.", "speak": "I will start by researching the key events that led to the French Revolution and organizing them chronologically." }, "command": { "name": "search", "args": { "tool_input": "Key events that led to the French Revolution" } } } System: Command search returned: Table of Contents · Causes of the French Revolution · Estates General · Rise of the Third Estate · Tennis Court Oath · The Bastille · Declaration of the Rights of Man ... Some key moments in the French Revolution, 1789- 1794; April 25. The first use of guillotine; June 13. Prussia declares war on France ; August 9. Paris Commune ... 14 July 1789: Storming of Bastille ... A wave of revolutionary hysteria sweeps through Paris, leading to fears of a military coup. In retaliation, rebels storm ... 4 days ago ... Why did the French Revolution lead to war with other nations? ... distinguish that event from the later French revolutions of 1830 and 1848. Jun 18, 2021 ... In 1789, the French people were not happy. Due to war and King Louis XVI's spending habits, the country was utterly broke. On top of that, the ... Jan 24, 2019 ... Iran's Islamic Revolution shook the world in 1979, with currents that ... together a timeline featuring key events that led to the fall of ... A summary of the causes of the French Revolution, including the enlightenment, estates system, American Revolution, and absolutism. Eleven Major Events In the French Revolution · Call of the Estate General (May 5, 1789) · Tennis Court Oath (June 20, 1789) · Storming of the Bastille (July 14, ... Congress, led by Representative James Madison, enacts the first protective tariff. ... When the French Revolution turned violent in 1792, however, ... Dec 5, 2018 ... The execution of King Louis XVI and his wife Marie Antoinette resulted in the Revolution entering its most bloody stage known as the Reign of ... Human: Determine which next command to use, and respond using the format specified above: ``` Reading the “french_revolution_analysis.txt” file, we see the following: ```python ***Analysis of the Significance of the French Revolution:*** ***The French Revolution was a watershed moment in world history that had a


Using AutoGPT with LangChain

# Using AutoGPT with LangChain
profound impact on the political, social, and economic landscape of Europe and beyond. Some of the key factors that contributed to the significance of the French Revolution include:*** - ***The rise of nationalism: The French Revolution helped to popularize the idea of nationalism, which would go on to play a major role in the political and social movements of the 19th and 20th centuries.*** - ***The spread of liberal democracy: The French Revolution helped to spread the idea of liberal democracy, which would become the dominant political system in the Western world.*** - ***The end of feudalism: The French Revolution marked the end of the feudal system in France and paved the way for the rise of capitalism and industrialization.*** - ***The impact on international relations: The French Revolution had a major impact on international relations, leading to a series of wars and conflicts that would shape the course of European history for decades to come.*** ***In conclusion, the French Revolution was a pivotal moment in world history that had a profound impact on the political, social, and economic landscape of Europe and beyond. By analyzing the significance of the French Revolution, we can gain a better understanding of the forces that have shaped the modern world.*** ``` As we can see, based on the output Jim, the AI assistant, has performed well, managing to work on three distinct and detailed files. Jim’s performance highlights several key capabilities: - **Research and Analysis:** The assistant has demonstrated good research and analysis skills. It has managed to delve into the historical context, key events, and the long-term impact of the French Revolution, presenting them in an organized and comprehensible manner. - **Writing and Summarization:** The agent displayed good writing skills. It has effectively synthesized complex historical concepts into clear and concise summaries, enabling better understanding for any reader, irrespective of their background knowledge. - **Planning and Workflow Management:** It has shown a structured approach in managing the tasks. It completed its research, wrote summaries, and planned for review and presentation, all while maintaining a smooth workflow and ensuring the proper organization and storage of information. - **Autonomy:** We are able to see that Jim operated independently, without any user assistance, demonstrating their ability to handle tasks from beginning to end. The results showcase its capabilities in historical research, analysis, summarization, planning, and information management. ### Conclusion Wrapping things up, the AI assistant we've been discussing makes great use of a collection of tools, including a search function and tools to read and write files. These tools allow the assistant to dig deep into historical topics, pull apart the complex factors at play, and manage data effectively. The assistant's ability to dive deep into topics, strategize effectively, and communicate its findings clearly, truly highlights the potential of AutoGPT-based applications. In the next lesson, we’ll learn about agent simulations projects, like CAMEL and Generative Agents.


Introduction to LLM Memory

# Introduction to LLM Memory
Welcome to this module, where you’ll learn about adding memory to LLM-based chatbots! We learned the concept of chains in the previous module. The projects highlighted how effective chains are for dealing with large language models and using them for accomplishing complex tasks easily. The upcoming module will expand on the chain functionality by introducing the concept of memory. In chat applications, retaining information from previous interactions is essential to maintain a consistent conversation flow. The following lessons will help you understand when and how to use different types of memory. The memory will increase the models’ performance by using LangChain’s built-in components to memorize previous dialogues or the Deep Lake database integration to present a knowledge base as external memory. Here are the lessons you’ll find in this module and what you’ll learn: - **Optimizing Your Communication: The Importance of Monitoring Message History:** The world of chatbot applications is constantly evolving, and in our first lesson, we explore the importance of message history tracking in delivering context-aware responses that enhance user experiences. We recognize that maintaining a record of past interactions can greatly improve chatbot interactions. Python and LangChain emerge as powerful tools for implementing message history tracking in chatbots. - **Mastering Memory Types in LangChain: A Comprehensive Guide with Practical Examples:** Building upon the concept of message history tracking, our next lesson delves deeper into the realm of LangChain memory. Traditionally, chatbot development involved processing user prompts independently without considering the history of interactions. This approach often resulted in disjointed and unsatisfactory user experiences. LangChain's memory components provide a solution by enabling chatbots to manage and manipulate previous chat messages. Chatbots can deliver more coherent and engaging conversations by incorporating the context from previous interactions. - **Chat with a GitHub Repository:** Expanding further, our next lesson explores how language models, particularly Large Language Models (LLMs), have exceptional language comprehension. Leveraging LangChain, we focus on generating embeddings from corpora, enabling a chat application to answer questions from any text. The process involves capturing data from a GitHub repository and converting it to embeddings. These embeddings are stored in Activeloop's Deep Lake vector database, ensuring fast and easy access. The Deep Lake retriever object will then find related files based on the user's query and provide them as context to the model. The model leverages this information to generate accurate and relevant answers. - **Build a Question Answering Chatbot over Documents with Sources:** Moving on, our next lesson delves into the advanced application of building a Question Answering (QA) Chatbot that works over documents and provides credible sources of information for its answers. The RetrievalQAWithSourcesChain plays a pivotal role in sifting through a collection of documents and extracting relevant information to answer queries. The chain utilizes structured prompts to guide the language model's generation, improving the quality and relevance of responses. Moreover, the retrieval chain keeps track of the sources of information it retrieves, providing credible references to back up its responses. This empowers the QA Chatbot to provide trustworthy and well-supported answers. - **Build ChatGPT to Answer Questions on Your Financial Data:** In the context of financial data interpretation, our next lesson highlights the benefits of LangChain for large language models (LLMs). LangChain's customizability and interoperability make it a powerful tool for handling complex applications. We demonstrate this by using LangChain and Deep Lake to interpret Amazon's quarterly financial reports. By embedding the data and querying it through LangChain, we showcase how these tools can revolutionize the interpretation of financial data, streamlining text generation and ensuring consistency. - ****DataChad: an AI App with LangChain & Deep Lake to Chat


Introduction to LLM Memory

# Introduction to LLM Memory
with Any Data:**** Our next lesson introduces DataChad, an open-source project that enables querying any data source using LangChain, embeddings, Deep Lake, and LLMs like GPT-3.5-turbo or GPT-4. We discuss the recent addition of local deployment using GPT4all, which enhances privacy and data security. DataChad simplifies data querying and offers a new level of efficiency, making it valuable for deep dives into complex data or swift insights. In conclusion, the interconnectedness of these lessons highlights the power of LangChain, Python, Deep Lake, and large language models in various applications. Whether it's enhancing chatbot interactions through message history tracking, answering questions with sourced information, interpreting financial data, or querying diverse data sources, these tools provide a comprehensive solution for AI-driven projects. The flexibility, customizability, and interoperability of these technologies ensure that developers and researchers can harness their full potential and create innovative applications in a range of domains.


Course Intro

# Course Intro
## Introduction to the LangChain Course
Activeloop, Towards AI, and Intel Disruptor Initiative are excited to collaborate to bring Gen AI 360: Foundational Model Certification Course to tomorrow’s Generative AI professionals, executives, and enthusiasts. Hello and welcome to our “LangChain & Vector Databases In Production” course, an integral part of a three-course series aimed at introducing Large Language Models, Deep Lake, and LangChain. This specific course focuses on LangChain - a popular framework for easily and quickly building applications empowered by large language models like GPT-Turbo-3.5, GPT-4, and GPT4ALL. ### **Why This Course?** This LangChain course will equip you with the knowledge and practical skills to build products and apps using Large Language Models (LLMs). We place heavy emphasis on the hands-on application, striving to guide you through a deep, practical introduction to leveraging the power of LLMs through LangChain. One of the tools we extensively cover in this course is Activeloop's Deep Lake. It amalgamates the best features of data lakes and vector databases, facilitating companies to create their own data flywheels for refining their Large Language Models. Combined with LangChain, Deep Lake can seamlessly connect datasets to foundational models for various applications, from [understanding GitHub repositories](https://www.activeloop.ai/resources/lang-chain-gpt-4-for-code-understanding-twitter-algorithm/) to [analyzing financial statements](https://www.activeloop.ai/resources/ultimate-guide-to-lang-chain-deep-lake-build-chat-gpt-to-answer-questions-on-your-financial-data/). ### **Who Should Take This Course?** Whether you're a machine learning enthusiast or transitioning into the AI field from another domain in software, this course is for you. No prerequisites other than familiarity with Python & coding (to complete the projects). We aim to provide you with the necessary tools to apply Large Language Models across a wide range of industries, making AI more accessible and practical. ### How Long **Will This Course Take You?** On average, students complete this course at around 40 hours (or 5 full days equivalent of learning) if they follow along with all code examples and read through the material. Our quickest course takers have managed to complete the course as quickly as in 2.5 days! The course is designed as a self-paced journey - so don't feel any rush in completing it. However, people who do complete it within the first two weeks of signing up will get free access to Deep Lake Growth Plan for a Month! ### **What Will You Learn?** By taking this comprehensive course, students will gain a deep understanding of Large Language Models and how to use them effectively with LangChain. They will be introduced to various concepts, including prompting, managing outputs, and giving memory to LLMs. They will explore the integration of LLMs with external tools and even how to use them as reasoning engines with agents. Students will learn through a hands-on approach, engaging in multiple real-world projects such as building a news articles summarizer and creating a customer support question-answering chatbot. This course ensures students understand the theory and the practical application of LLMs. A critical aspect of this course centers on understanding the current limitations of LLMs, specifically hallucinations and limited memory. However, solutions to these limitations exist, and one of the most potent is the use of Vector Stores. Throughout this course, we will delve into the usage of Activeloop’s Deep Lake vector store as an effective remedy. ### Is the Course Free? Yes, the course is entirely free for everybody. ### **Certification** By participating in this course and completing the quizzes at the end of each chapter, you will have the opportunity to earn a certification in using Deep Lake - a valuable addition to your professional credentials. This certification program, offered at no cost, forms part of the Deep Lake Foundational Model Certification program in collaboration with Intel Disruptor Initiative and Towards AI. You can skip


Course Intro

# Course Intro
## Introduction to the LangChain Course
the quizzes as you read through the lessons and chapters, but please remember to complete them at the end to receive your certificate! ### **Course Impact** "*Reaching over 385,000 AI developers monthly, we're passionate about educating and upskilling engineers in this rapidly growing field. That is why we designed a practical course engineers can take to implement AI into their company processes or use LLMs to build entirely new products,*" said Louie Peters, CEO of Towards AI. Adding to this, Davit Buniatyan, CEO of Activeloop, emphasized, "*Every company will be adding foundational models and vector databases to their day-to-day operations and the products they build very soon. Upon course completion, Deep Lake Certified developers will be able to harness the full potential of Foundational Models and advanced technologies like Deep Lake and LangChain.*" This course serves as a pathway to stay ahead in this rapidly advancing field, arming you with the skills necessary to use these frameworks in your toolset, thereby providing a competitive advantage. We're looking forward to having you on this journey. Join us, and let's build the future of AI together!


Course Intro

# Course Intro
## Modules Covered
This course has been structured into several modules, each providing a detailed examination in increasing complexity of various facets of Large Language Models (LLMs), LangChain, and Deep Lake. Here is an overview of the modules you'll engage with. ### **1. From Zero to Hero** This introductory module serves as a quick guide, swiftly bringing you up to speed with all the fundamental concepts. It includes hands-on code snippets covering library installation, OpenAI credentials, deriving predictions from LLMs, and more. You'll also take a peek at Deep Lake and its applications. ### **2. Large Language Models and LangChain** This module provides a comprehensive overview of Large Language Models, including their capabilities, limitations, and use cases. You'll dive deep into LLMs like ChatGPT and GPT-4, explore these models' emergent abilities and scaling laws, and gain insights into phenomena like hallucinations and bias. This module also introduces LangChain and its role in integrating LLMs with other data sources and tools. You will also undertake a project to build a News Articles Summarizer. ### **3. Learning How to Prompt** Learning how to craft effective prompts is a key skill in working with LLMs. This module delves into the nuances of prompt engineering and teaches you to develop prompts that are easy to maintain. You'll learn techniques such as role prompting, few-shot prompting, and chain of thought. Towards the end of this module, you'll take your learning further by enhancing the News Articles Summarizer built in the previous module and undertaking a project to extract a knowledge graph from news articles. ### **4. Keeping Knowledge Organized with Indexes** The final module focuses on how to effectively leverage documents as a base for LLMs using LangChain's indexes and retrievers. You'll learn about data ingestion through various loaders, the importance of text splitters, and delve into the concept of embeddings and vector stores. The module ends with a project where you'll build a Customer Support Question Answering Chatbot using ChatGPT, Deep Lake, and LangChain. ### **5. Combining Components Together with Chains** In this module, you will get a handle on LangChain's chains - a concept that enables the creation of a single, coherent application. You will understand why chains are used and have the opportunity to work on multiple projects. These include creating a YouTube Video Summarizer, building a Jarvis for your Knowledge Base, and exploring code understanding with GPT-4 and LangChain. You will also learn about the Self-Critique Chain and how to guard against undesirable outputs. ### **6. Giving Memory to LLMs** This module emphasizes the importance of memory in maintaining context over a conversation. You will master the different types of memory in LangChain, including ConversationBufferMemory, ConversationBufferWindowMemory, ConversationSummaryMemory, and ConversationChain. Various exciting projects await you, such as creating a chatbot that interacts with a Github Repo, building a question-answering chatbot, and working with financial data. ### **7. Making LLMs Interact with the World Using Tools** In this module, you'll explore LangChain's tools and their diverse applications, including Google Search, requests, Python REPL, Wikipedia, and Wolfram-Alpha. Projects in this module revolve around enhancing blog posts with LangChain and Google Search, recreating the Bing chatbot, and leveraging multiple tools simultaneously. You'll also learn how to define custom tools for your specific needs. ### **8. Using Language Model as Reasoning Engines with Agents** The final module introduces you to the concept of agents in LangChain, with a particular emphasis on using a language model as a reasoning engine. You'll explore autonomous agents, their projects, and the application of AutoGPT with LangChain. The module culminates with a project on building autonomous agents to create comprehensive analysis reports. Each module


Course Intro

# Course Intro
## Modules Covered
has been thoughtfully designed to provide you with a solid understanding of LLMs, LangChain, and Deep Lake. By the end of this course, you'll have a firm grasp of these advanced tools and frameworks, ready to harness their potential to solve real-world problems.


Course Intro

# Course Intro
## Course Logistics
Here's everything you need to know about how the course will work. ### **Course Hosting and Pace** This course is hosted by **Activeloop**. It is designed as a **self-paced** learning journey, allowing you to proceed at your own comfort. The online format provides flexibility, enabling you to engage with the lessons whenever suits you best. On average the course duration is 40 hours, with some participants completing it in as fast as in 25 if they do not try to work on projects. At the end of each module you can test your new knowledge with multiple-choice quizzes, which are required to solve to continue the course. Once solved all the quizzes, you’ll be given your course Certification by completing the whole course. ### **Community Support** Got questions about this course or specific lessons? Want to exchange ideas with fellow learners? We encourage active interaction in the dedicated forum in the *[Towards AI’s Learn AI Together Discord Community](https://discord.com/invite/learnaitogether) (gen-ai-360 channel)*. This vibrant community comprises over 50,000 AI enthusiasts. There’s a dedicated channel within our community for this course where you can pose questions and share insights. For queries specifically related to Deep Lake, please join the *[Deep Lake Slack community](https://join.slack.com/t/hubdb/shared_invite/zt-ivhsj8sz-GWv9c5FLBDVw8vn~sxRKqQ),* where experts and users alike will be ready to assist. ### **Required API Tokens** The course involves practical projects and exercises that will require the use of various API keys. These will be thoroughly guided in the individual lessons. However, the two main API tokens that you will use throughout the course are: 1. **The OpenAI API token**: This will be used to query LLMs like ChatGPT and GPT-4. 2. **The Deep Lake API token**: Essential for creating Deep Lake datasets as vector stores for the projects we’ll build during the course. These are the steps you should take to get the OpenAI API token. 1. If you don't have an account yet, create one by going to **[https://platform.openai.com/](https://platform.openai.com/)**. If you already have an account, skip to step 5. 2. Fill out the registration form with your name, email address, and desired password. 3. OpenAI will send you a confirmation email with a link. Click on the link to confirm your account. 4. Please note that you'll need to verify your email account and provide a phone number for verification. 5. Log in to **[https://platform.openai.com/](https://platform.openai.com/)**. 6. Navigate to the API key section at **[https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys)**. 7. Click "Create new secret key" and give the key a recognizable name or ID. You should take these steps to get the Deep Lake API token. 1. Sign up for an account on Activeloop's platform. You can sign up at [Activeloop's website](https://app.activeloop.ai/register). After specifying your username, click on the “Sign up” button. You should now see your homepage. 2. You should now see a “Create API token” button at the top of your homepage. Click on it, and you’ll get redirected to the “API tokens” page. This is where you can generate, manage, and revoke your API keys for accessing Deep Lake. 3. Click on the "Create API token" button. You should see a popup asking for a token name and an expiration date. By default, the token expiration date is set so that the token expires after one day from its creation, but you can set it further in the future if you want to keep using the same token for the whole duration of the course. Once you’ve set the token name and its expiration date, click the “Create API token” button. 4. You should now see a green banner saying that the token has been successfully generated, along with your new API


Course Intro

# Course Intro
## Course Logistics
token, on the “API tokens” page. To copy your token to your clipboard, click the square icon on its right. Environment variables play an important role in storing sensitive information, such as API keys. Be careful not to share your API tokens with anyone! ### Expected Cost of OpenAI Usage By running the code samples from this course you'll make requests to the OpenAI API, incurring in costs. We expect the total cost of running all the lessons in this course, along with some experimentations, to be under $3. If you’re eager to explore and experiment without worrying about costs - don’t worry! Go to the lesson called “Using the Open-Source GPT4All Model Locally” in the “Large Language Models and LangChain” module. This lesson teaches you how to use the open-source LLM GPT4All on your own computer, so you can enjoy benefits LLMs provide without having to pay for the OpenAI models’ API. With GPT4All, you can replace the OpenAI models in every lesson and continue your exciting journey without need to pay. Happy experimenting! ### **Coding Environment and Packages** Before embarking on this course, you need to ensure that you have the appropriate coding environment ready. Please make sure to use a Python version equal to, or later than **3.8.1**, which is the minimum requirement to utilize the LangChain library. You can set up your environment by choosing one of the following options: 1. Having a code editor installed on your computer. A popular coding environment is Visual Studio Code. 2. Using Python virtual environments to manage Python libraries. 3. Alternatively, you could use Google Colab notebooks. You will need the following packages to successfully execute the sample codes provided in each lesson. They can be installed using the `pip` package manager. ``` langchain==0.0.208 deeplake==3.6.5 openai==0.27.8 tiktoken==0.4.0 ``` While we strongly recommend installing the latest versions of these packages, please note that the codes have been tested with the versions specified in parentheses. as the `langchain` library is still evolving rapidly, we suggest to install a specific version of it, while installing the latest versions of the other libraries. You can do that with the following command: `pip install langchain==0.0.208 deeplake openai tiktoken`. Moreover, specific lessons may require the installation of additional packages, which will be explicitly mentioned. The following code will demonstrate how to install a package using pip. ```bash pip install deeplake # Or: (to install an specific version) # pip install deeplake==3.6.5 ``` <aside> 💡 If you encounter any issues while installing the packages, don't hesitate to reach out to us via Activeloop's [Slack channel](https://slack.activeloop.ai/) or the [live chat](https://www.activeloop.ai/) on the website. We are here to assist you. </aside> ### **Google Colab** Google Colaboratory, popularly known as Google Colab, is a *free cloud-based Jupyter notebook environment*. Data scientists and engineers widely use it to train machine learning and deep learning models using CPUs, GPUs, and TPUs. Google Colab comes with an array of features such as: - Free access to GPUs and TPUs for accelerated model training. - A web-based interface for a service running on a virtual machine, eliminating the need for local software installation. - Seamless integration with Google Drive and GitHub. To use Google Colab, all you need is a Google account. You can run terminal commands directly in notebook cells by appending an exclamation mark (!) before the command. Every notebook created in Google Colab gets stored in your Google Drive for easy access. A convenient way of using API keys in Colab involves: 1. Saving them in a file named `.env` on your Google Drive. Here’s how the file should be


Course Intro

# Course Intro
## Course Logistics
formatted for saving the Activeloop token and the OpenAI API key. ```python ACTIVELOOP_TOKEN=your_activeloop_token OPENAI_API_KEY=your_openai_key ``` 1. Mounting your Google Drive on your Colab instance. 2. Loading them as environment variables using the **`dotenv`** library, like in the following code. ```python from dotenv import load_dotenv load_dotenv('/content/drive/MyDrive/path/to/.env') ``` ### **Creating Python Virtual Environments** Python virtual environments offer an excellent solution for managing Python libraries and avoiding package conflicts. They create isolated environments for installing packages, ensuring that your packages and their dependencies are contained within that environment. This setup provides clean and isolated environments for your Python projects. Begin by executing the `python` command in your terminal to confirm that the Python version is either equal to or greater than 3.8.1. Then follow these steps to create a virtual environment: 1. Create a virtual environment using the command **`python -m venv my_venv_name`**. 2. Activate the virtual environment by executing **`source my_venv_name/bin/activate`**. 3. Install the required libraries and run the code snippets from the lessons within the virtual environment. 4. To deactivate the virtual environment, simply run **`deactivate`**.


Course Intro

# Course Intro
## The LLM and vector store toolkit
Building applications around Large Language Models like ChatGPT, GPT-4, or PALM-2 presents unique challenges. Understanding these challenges and how **Deep Lake** overcomes them is very important in the development of advanced AI applications. ### **The Power and Limitations of Large Language Models** LLMs are trained on huge amounts of text with the aim of learning the conditional distribution of words in a language. Doing so allows them to generalize and generate meaningful text without directly memorizing the training data. This means they can accurately recall widely disseminated information, such as historical events or popular cultural facts. However, the LLM's knowledge is restricted to its training set. So, suppose the model was trained on data up to 2021 and is asked about a company founded in 2023. In that case, it may generate a plausible but entirely fabricated description - a phenomenon known as "**hallucination**.” Managing hallucinations is tricky, especially in applications where accuracy and reliability are paramount, such as customer-service chatbots, knowledge-base assistants, or AI tutors. One promising strategy to mitigate hallucination is the use of retrievers in tandem with LLMs. A retriever fetches relevant information from a trusted knowledge base (like a search engine), and the LLM is then specifically prompted to rearrange the information without inventing additional details. LLMs' large context window sizes facilitate the inclusion of multiple documents in a single prompt. Models like GPT-4 and Claude can handle context windows of up to 32k and 100k tokens, respectively, equating to approximately 20k words or 40 pages of text. However, the cost of execution rises with the number of tokens used, hence the need for an efficient retriever to find the most relevant documents. ### **Building Efficient Retrievers with Deep Lake** Efficient retrievers are built using embedding models that map texts to vectors. These vectors are then stored in specialized databases called **vector stores**. This is where **Deep Lake** comes in. As a data lake that doubles as a vector store for multiple data types, Deep Lake provides several advantages: 1. **Multimodal**: Deep Lake can store items of diverse modalities - text, images, audio, and video - along with their vector representations. 2. **Serverless**: The serverless nature of Deep Lake allows for the creation and management of cloud datasets without the need for a dedicated database instance. This streamlines the setup process and accelerates project development. 3. **Data Loader**: Deep Lake makes creating a streaming data loader from the loaded dataset easy, which is particularly useful for fine-tuning machine learning models using frameworks like PyTorch and TensorFlow. 4. **Querying and Visualization**: Data can be queried and visualized easily from the web. In the context of LLM applications, Deep Lake provides a seamless way to store embeddings and their corresponding metadata. It enables hybrid searches on these embeddings and their attributes for efficient data retrieval. Moreover, as LangChain integrates with it, it facilitates the development and deployment of LLM-based applications. As a result, Deep Lake serves as a convenient serverless memory solution for LLM chains and agents, whether for storing relevant documents for question-answering tasks or storing images for guided image-generation tasks. In summary, **Deep Lake** equips developers with a powerful tool to tackle the challenges of creating LLM-based applications and enhance the capabilities of these transformative models. ![Untitled](Course%20Intro%20ae2e15cb2d164e8187badbe682dcb04d/Untitled.png) *Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries.*


# Intro to Prompt Engineering: Tips and Tricks
### Introduction Prompt engineering is a relatively new discipline that involves developing and optimizing prompts to use language models for various applications and research topics efficiently. It helps to understand the capabilities and limitations of LLMs better and is essential for many NLP tasks. We will provide practical examples to demonstrate the difference between good and bad prompts, helping you to understand the nuances of prompt engineering better. By the end of this lesson, you will have a solid foundation in the knowledge and strategies needed to create powerful prompts that enable LLMs to deliver accurate, contextually relevant, and insightful responses. ### **Role Prompting** Role prompting involves asking the LLM to assume a specific role or identity before performing a given task, such as acting as a copywriter. This can help guide the model's response by providing a context or perspective for the task. To work with role prompts, you could iteratively: 1. Specify the role in your prompt, e.g., "As a copywriter, create some attention-grabbing taglines for AWS services." 2. Use the prompt to generate an output from an LLM. 3. Analyze the generated response and, if necessary, refine the prompt for better results. **Examples:** In this example, the LLM is asked to act as a futuristic robot band conductor and suggest a song title related to the given theme and year. (A reminder to set your OpenAI API key in your environment variables using the `OPENAI_API_KEY` key) Remember to install the required packages with the following command: `pip install langchain==0.0.208 deeplake openai tiktoken`. ```python from langchain import PromptTemplate, LLMChain from langchain.llms import OpenAI # Before executing the following code, make sure to have # your OpenAI key saved in the “OPENAI_API_KEY” environment variable. # Initialize LLM llm = OpenAI(model_name="text-davinci-003", temperature=0) template = """ As a futuristic robot band conductor, I need you to help me come up with a song title. What's a cool song title for a song about {theme} in the year {year}? """ prompt = PromptTemplate( input_variables=["theme", "year"], template=template, ) # Create the LLMChain for the prompt llm = OpenAI(model_name="text-davinci-003", temperature=0) # Input data for the prompt input_data = {"theme": "interstellar travel", "year": "3030"} # Create LLMChain chain = LLMChain(llm=llm, prompt=prompt) # Run the LLMChain to get the AI-generated song title response = chain.run(input_data) print("Theme: interstellar travel") print("Year: 3030") print("AI-generated song title:", response) ``` ``` Theme: interstellar travel Year: 3030 AI-generated song title: "Journey to the Stars: 3030" ``` This is a good prompt for several reasons: - **Clear instructions:** The prompt is phrased as a clear request for help in generating a song title, and it specifies the context: "As a futuristic robot band conductor." This helps the LLM understand that the desired output should be a song title related to a futuristic scenario. - **Specificity:** The prompt asks for a song title that relates to a specific theme and a specific year, "{theme} in the year {year}." This provides enough context for the LLM to generate a relevant and creative output. The prompt can be adapted for different themes and years by using input variables, making it versatile and reusable. - **Open-ended creativity:** The prompt allows for open-ended creativity, as it doesn't limit the LLM to a particular format or style for the song title. The LLM can generate a diverse range of song titles based on the given theme and year. - **Focus on the task:** The prompt is focused solely on generating a song title, making it easier for the LLM to provide a suitable output without getting sidetracked by unrelated topics. These elements help the LLM understand the user's intention


# Intro to Prompt Engineering: Tips and Tricks
and generate a suitable response. ### Few Shot Prompting Few Shot Prompting In the next example, the LLM is asked to provide the emotion associated with a given color based on a few examples of color-emotion pairs: ```python from langchain import PromptTemplate, FewShotPromptTemplate, LLMChain from langchain.llms import OpenAI # Initialize LLM llm = OpenAI(model_name="text-davinci-003", temperature=0) examples = [ {"color": "red", "emotion": "passion"}, {"color": "blue", "emotion": "serenity"}, {"color": "green", "emotion": "tranquility"}, ] example_formatter_template = """ Color: {color} Emotion: {emotion}\n """ example_prompt = PromptTemplate( input_variables=["color", "emotion"], template=example_formatter_template, ) few_shot_prompt = FewShotPromptTemplate( examples=examples, example_prompt=example_prompt, prefix="Here are some examples of colors and the emotions associated with them:\n\n", suffix="\n\nNow, given a new color, identify the emotion associated with it:\n\nColor: {input}\nEmotion:", input_variables=["input"], example_separator="\n", ) formatted_prompt = few_shot_prompt.format(input="purple") # Create the LLMChain for the prompt chain = LLMChain(llm=llm, prompt=PromptTemplate(template=formatted_prompt, input_variables=[])) # Run the LLMChain to get the AI-generated emotion associated with the input color response = chain.run({}) print("Color: purple") print("Emotion:", response) ``` ``` Color: purple Emotion: creativity ``` This prompt provides **clear instructions** and few-shot examples to help the model understand the task. ### Bad Prompt Practices Now, let’s see some examples of prompting that are generally considered bad. Here’s an example of a too-vague prompt that **provides little context** or guidance for the model to generate a meaningful response. ```python from langchain import PromptTemplate template = "Tell me something about {topic}." prompt = PromptTemplate( input_variables=["topic"], template=template, ) prompt.format(topic="dogs") ``` ``` 'Tell me something about dogs.’ ``` ### **Chain Prompting** Chain Prompting refers to the practice of chaining consecutive prompts, where the output of a previous prompt becomes the input of the successive prompt. To use chain prompting with LangChain, you could: - Extract relevant information from the generated response. - Use the extracted information to create a new prompt that builds upon the previous response. - Repeat steps as needed until the desired output is achieved. `PromptTemplate` class makes constructing prompts with dynamic inputs easier. This is useful when creating a prompt chain that depends on previous answers. ```python from langchain import PromptTemplate, LLMChain from langchain.llms import OpenAI # Initialize LLM llm = OpenAI(model_name="text-davinci-003", temperature=0) # Prompt 1 template_question = """What is the name of the famous scientist who developed the theory of general relativity? Answer: """ prompt_question = PromptTemplate(template=template_question, input_variables=[]) # Prompt 2 template_fact = """Provide a brief description of {scientist}'s theory of general relativity. Answer: """ prompt_fact = PromptTemplate(input_variables=["scientist"], template=template_fact) # Create the LLMChain for the first prompt chain_question = LLMChain(llm=llm, prompt=prompt_question) # Run the LLMChain for the first prompt with an empty dictionary response_question = chain_question.run({}) # Extract the scientist's name from the response scientist = response_question.strip() # Create the LLMChain for the second prompt chain_fact = LLMChain(llm=llm, prompt=prompt_fact) # Input data for the second prompt input_data = {"scientist": scientist} # Run the LLMChain for the second prompt response_fact = chain_fact.run(input_data) print("Scientist:", scientist) print("Fact:", response_fact) ``` ``` Scientist: Albert Einstein Fact: Albert Einstein's theory of general relativity is a theory of gravitation that states that the gravitational force between two objects is a result of the curvature of spacetime caused by the presence of mass and energy. It explains the phenomenon of gravity as a result of the warping of space and time by matter and energy. ``` This prompt may generate a less informative or focused response than the previous example due to its more open-ended nature. **Bad Prompt Example:** ```python from langchain import PromptTemplate, LLMChain from langchain.llms import OpenAI # Initialize LLM llm = OpenAI(model_name="text-davinci-003", temperature=0) # Prompt 1 template_question = """What is the name of the famous scientist who developed the theory of general relativity? Answer: """ prompt_question = PromptTemplate(template=template_question,


# Intro to Prompt Engineering: Tips and Tricks
input_variables=[]) # Prompt 2 template_fact = """Tell me something interesting about {scientist}. Answer: """ prompt_fact = PromptTemplate(input_variables=["scientist"], template=template_fact) # Create the LLMChain for the first prompt chain_question = LLMChain(llm=llm, prompt=prompt_question) # Run the LLMChain for the first prompt with an empty dictionary response_question = chain_question.run({}) # Extract the scientist's name from the response scientist = response_question.strip() # Create the LLMChain for the second prompt chain_fact = LLMChain(llm=llm, prompt=prompt_fact) # Input data for the second prompt input_data = {"scientist": scientist} # Run the LLMChain for the second prompt response_fact = chain_fact.run(input_data) print("Scientist:", scientist) print("Fact:", response_fact) ``` ``` Scientist: Albert Einstein Fact: Albert Einstein was a vegetarian and an advocate for animal rights. He was also a pacifist and a socialist, and he was a strong supporter of the civil rights movement. He was also a passionate violinist and a lover of sailing. ``` This prompt may generate a less informative or focused response than the previous example due to its more open-ended nature. **An example of the unclear prompt:** ```python from langchain import PromptTemplate, LLMChain from langchain.llms import OpenAI # Initialize LLM llm = OpenAI(model_name="text-davinci-003", temperature=0) # Prompt 1 template_question = """What are some musical genres? Answer: """ prompt_question = PromptTemplate(template=template_question, input_variables=[]) # Prompt 2 template_fact = """Tell me something about {genre1}, {genre2}, and {genre3} without giving any specific details. Answer: """ prompt_fact = PromptTemplate(input_variables=["genre1", "genre2", "genre3"], template=template_fact) # Create the LLMChain for the first prompt chain_question = LLMChain(llm=llm, prompt=prompt_question) # Run the LLMChain for the first prompt with an empty dictionary response_question = chain_question.run({}) # Assign three hardcoded genres genre1, genre2, genre3 = "jazz", "pop", "rock" # Create the LLMChain for the second prompt chain_fact = LLMChain(llm=llm, prompt=prompt_fact) # Input data for the second prompt input_data = {"genre1": genre1, "genre2": genre2, "genre3": genre3} # Run the LLMChain for the second prompt response_fact = chain_fact.run(input_data) print("Genres:", genre1, genre2, genre3) print("Fact:", response_fact) ``` ``` Genres: jazz pop rock Fact: Jazz, pop, and rock are all genres of popular music that have been around for decades. They all have distinct sounds and styles, and have influenced each other in various ways. Jazz is often characterized by improvisation, complex harmonies, and syncopated rhythms. Pop music is typically more accessible and often features catchy melodies and hooks. Rock music is often characterized by distorted guitars, heavy drums, and powerful vocals. ``` In this example, the second prompt is constructed poorly. It asks to "tell me something about {genre1}, {genre2}, and {genre3} without giving any specific details." This prompt is unclear, as it asks for information about the genres but also states not to provide specific details. This makes it difficult for the LLM to generate a coherent and informative response. As a result, the LLM may provide a less informative or confusing answer. The first prompt asks for "some musical genres" **without specifying any criteria or context**, and the second prompt asks why the given genres are "unique" **without providing any guidance** on what aspects of uniqueness to focus on, such as their historical origins, stylistic features, or cultural significance. ### Chain of Thought Prompting Chain of Thought Prompting (CoT) is a technique developed to encourage large language models to explain their reasoning process, leading to more accurate results. By providing few-shot exemplars demonstrating the reasoning process, the LLM is guided to explain its reasoning when answering the prompt. This approach has been found effective in improving results on tasks like arithmetic, common sense, and symbolic reasoning. In the context of LangChain, CoT can be beneficial for several reasons. First, it can help break down complex tasks by assisting the LLM in decomposing a complex


# Intro to Prompt Engineering: Tips and Tricks
task into simpler steps, making it easier to understand and solve the problem. This is particularly useful for calculations, logic, or multi-step reasoning tasks. Second, CoT can guide the model through related prompts, helping generate more coherent and contextually relevant outputs. This can lead to more accurate and useful responses in tasks that require a deep understanding of the problem or domain. There are some limitations to consider when using CoT. One limitation is that it has been found to yield performance gains only when used with models of approximately 100 billion parameters or larger; smaller models tend to produce illogical chains of thought, which can lead to worse accuracy than standard prompting. Another limitation is that CoT may not be equally effective for all tasks. It has been shown to be most effective for tasks involving arithmetic, common sense, and symbolic reasoning. For other types of tasks, the benefits of using CoT might be less pronounced or even counterproductive. ### **Tips for Effective Prompt Engineering** - **Be specific** with your prompt: Provide enough context and detail to guide the LLM toward the desired output. - **Force conciseness** when needed. - **Encourage the model to explain its reasoning**: This can lead to more accurate results, especially for complex tasks. Keep in mind that prompt engineering is an iterative process, and it may require several refinements to obtain the best possible answer. As LLMs become more integrated into products and services, the ability to create effective prompts will be an important skill to have. **A well-structured prompt example:** ```python from langchain import FewShotPromptTemplate, PromptTemplate, LLMChain from langchain.llms import OpenAI # Initialize LLM llm = OpenAI(model_name="text-davinci-003", temperature=0) examples = [ { "query": "What's the secret to happiness?", "answer": "Finding balance in life and learning to enjoy the small moments." }, { "query": "How can I become more productive?", "answer": "Try prioritizing tasks, setting goals, and maintaining a healthy work-life balance." } ] example_template = """ User: {query} AI: {answer} """ example_prompt = PromptTemplate( input_variables=["query", "answer"], template=example_template ) prefix = """The following are excerpts from conversations with an AI life coach. The assistant provides insightful and practical advice to the users' questions. Here are some examples: """ suffix = """ User: {query} AI: """ few_shot_prompt_template = FewShotPromptTemplate( examples=examples, example_prompt=example_prompt, prefix=prefix, suffix=suffix, input_variables=["query"], example_separator="\n\n" ) # Create the LLMChain for the few-shot prompt template chain = LLMChain(llm=llm, prompt=few_shot_prompt_template) # Define the user query user_query = "What are some tips for improving communication skills?" # Run the LLMChain for the user query response = chain.run({"query": user_query}) print("User Query:", user_query) print("AI Response:", response) ``` ``` User Query: What are some tips for improving communication skills? AI Response: Practice active listening, be mindful of your body language, and be open to constructive feedback. ``` This prompt: - **Provides a clear context in the prefix**: The prompt states that the AI is a life coach providing insightful and practical advice. This context helps guide the AI's responses and ensures they align with the intended purpose. - **Uses examples** that demonstrate the AI's role and **the type of responses** it generates: By providing relevant examples, the AI can better understand the style and tone of the responses it should produce. These examples serve as a reference for the AI to generate similar responses that are consistent with the given context. - Separates examples and the actual query: This **allows the AI to understand the format it should follow**, ensuring a clear distinction between example conversations and the user's input. This separation helps the AI to focus on the current query and respond accordingly. - Includes a clear suffix that


# Intro to Prompt Engineering: Tips and Tricks
indicates where the user's input goes and where the AI should provide its response: The suffix acts as a cue for the AI, showing where the user's query ends and the AI's response should begin. This structure helps maintain **a clear and consistent format** for the generated responses. By using this well-structured prompt, the AI can understand its role, the context, and the expected response format, leading to more accurate and useful outputs. ### **Conclusion** This lesson explored various techniques for creating more effective prompts for large language models. By understanding and applying these tips and tricks, you'll be better equipped to craft powerful prompts that enable LLMs to deliver accurate, contextually relevant, and insightful responses. Always remember that prompt engineering is an iterative process that may require refinement to obtain the best possible results. In conclusion, prompt engineering is a powerful technique that can help to optimize language models for various applications and research topics. By creating good prompts, we can guide the model to deliver accurate, contextually relevant, and insightful responses. Role prompting and chain prompting are two techniques that can be used to create good prompts, and we have provided practical examples of each. On the other hand, we have also demonstrated bad prompt examples that don't provide enough context or guidance for the model to generate a meaningful response. By following the tips and tricks presented in this post, you can develop a solid foundation in prompt engineering and use language models for various tasks more effectively. In the next lesson, we’ll learn more about how to create prompt templates with LangChain. **RESOURCES:** [A Hands-on Guide to Prompt Engineering with ChatGPT and GPT-3](https://dev.to/mmz001/a-hands-on-guide-to-prompt-engineering-with-chatgpt-and-gpt-3-4127) [Prompt Engineering Tips and Tricks with GPT-3](https://blog.andrewcantino.com/blog/2021/04/21/prompt-engineering-tips-and-tricks/) [Prompt Engineering LLMs with LangChain and W&B](https://wandb.ai/a-sh0ts/langchain_callback_demo/reports/Prompt-Engineering-LLMs-with-LangChain-and-W-B--VmlldzozNjk1NTUw) --- You can find the code of this lesson in this online [Notebook](https://colab.research.google.com/drive/1JZRY4CO7A8t5LP_72jkqbuGliVcgsPQz?usp=sharing).


# LangChain & GPT-4 for Code Understanding: Twitter Algorithm
In this lesson we will explore how LangChain, Deep Lake, and GPT-4 can transform our understanding of complex codebases, such as Twitter's open-sourced recommendation algorithm. ### Introduction In this lesson we will explore how LangChain, Deep Lake, and GPT-4 can transform our understanding of complex codebases, such as Twitter's open-sourced recommendation algorithm. This approach enables us to ask any question directly to the source code, significantly speeding up the code comprehension. LangChain is essentially a wrapper that makes Large Language Models like GPT-4 more accessible and usable, providing a new way to build user interfaces. LangChain augments LLMs with memory and context, making it especially valuable for understanding codebases. Deep Lake, in the LangChain ecosystem, is a serverless, open-source, and multi-modal vector store. It stores both the embeddings and the original data with automatic version control, making it a crucial component in the process. The Conversational Retriever Chain is a system that interacts with the data stored in Deep Lake. It retrieves the most relevant code snippets and details based on user queries, using context-sensitive filtering and ranking. In this lesson, you'll learn how to index a codebase, store embeddings and code in Deep Lake, set up a Conversational Retriever Chain, and ask insightful questions to the codebase. ### The Workflow This guide involves understanding source code using LangChain in four steps: 1. Install necessary libraries like langchain, deeplake, openai and tiktoken, and authenticate with Deep Lake and OpenAI. 2. Optionally, index a codebase by cloning the repository, parsing the code, dividing it into chunks, and using OpenAI to perform indexing. 3. Establish a Conversational Retriever Chain by loading the dataset, setting up the retriever, and connecting to a language model like GPT-4 for question answering. 4. Query the codebase in natural language and retrieve answers. The guide ends with a demonstration of how to ask and retrieve answers to several questions about the indexed codebase. By the end of this lesson, you'll have a better understanding of how to use LangChain, Deep Lake, and GPT-4 to quickly comprehend any codebase. Plus, you'll gain insight into the inner workings of Twitter's recommendation algorithm. [Analysis of Twitter the-algorithm source code with LangChain, GPT4 and Activeloop's Deep Lake | 🦜🔗 Langchain](https://python.langchain.com/docs/use_cases/question_answering/how_to/code/twitter-the-algorithm-analysis-deeplake) [https://www.activeloop.ai/resources/lang-chain-gpt-4-for-code-understanding-twitter-algorithm/](https://www.activeloop.ai/resources/lang-chain-gpt-4-for-code-understanding-twitter-algorithm/) In the next lesson, you’ll see how to build an LLM-based recommender system for Disney songs.


Intro to LLMs and LangChain module

# Intro to LLMs and LangChain module
Having gained a solid understanding of the basic concepts of the LangChain library from the first module, it is now time to explore each component in greater detail through the upcoming modules. We start by introducing the most important part of the pipeline - the underlying models! This module will introduce the capabilities of different types of large language models and chat models in detail. It is followed by walking through a hands-on project to summarize news articles. It is worth noting that as we progress through subsequent modules and gain a deeper understanding of additional features, we will refine and enhance the mentioned project and embark on new projects. Below is the module outline, along with a brief description of the content covered in each lesson. - **Quick Intro to Large Language Models**: Introducing models like GPT-3, GPT-4, and ChatGPT while discussing their abilities in few-shot learning and demonstrating practical examples of text summarization and translation. We'll also address potential challenges such as hallucinations, biases, and the context size of LLMs. - **Building Applications Powered by LLMs with LangChain**: LangChain solves key challenges in building applications powered by Large Language Models (LLMs) and makes them more accessible. The lesson will start by covering the use of prompts in chat applications. We will also showcase examples of prompts from LangChain, such as those used in summarization or question-answering chains, highlighting the ease of prompt reuse and customization. - **Exploring the World of Language Models:** Fundamental distinctions exist between language models and chat models. Notably, chat models are trained to engage in conversations by considering previous messages. In contrast, language models respond to a prompt and rely solely on the information provided within it to answer a query. You will acquire the skills to define various types of prompts for simple applications using each available variation. - **Exploring Conversational Capabilities with GPT-4 and ChatGPT:** The ChatGPT application provides several benefits that enable it to hold meaningful conversations. During the lesson, you will learn how to pass previous messages to the model and observe how the model effectively utilizes and references these messages when required. - **Build a News Articles Summarizer:** This lesson is the first hands-on project of the course. We will set up the environment by installing the required libraries and loading access tokens. Next, we will download the contents of a news article and provide them as input to a ChatGPT instance equipped with the GPT-4 model, which will handle the summarization process efficiently. The lesson further explores different prompts to get desired styles. (e.g. a bullet-point list) - **Using the Open-Source GPT4All Model Locally:** While proprietary models like the GPT family are powerful choices, it is essential to note that there are limitations and restrictions when utilizing them. We will present an open-source model called GPT4ALL, which can be executed locally on your own system. In this lesson, we will delve into the inner workings of this model and demonstrate its seamless integration with the LangChain library, facilitating its user-friendly implementation. - **What other models can we use? Popular LLM models compared:** The integration of LangChain with numerous models and services opens up exciting new possibilities. In particular, combining various models and services is effortless, leveraging their respective strengths and addressing their limitations. You will see a comprehensive list of different models and their respective advantages and disadvantages. Please note that each model has its license, which may not necessarily cover specific situations. (e.g. commercial use) This module aims to provide you with a comprehensive understanding of the various models the LangChain library offers. We will explore multiple