Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Prompt Engineering 101: Beginner intro to LangC...

Lev Konstantinovskiy
April 19, 2023
500

Prompt Engineering 101: Beginner intro to LangChain, the shovel of our ChatGPT gold rush.

A modern AI start-up is a front-end developer plus a prompt engineer" is a popular joke on Twitter.
This talk is about LangChain, a Python open-source tool for prompt engineering. You can use it with completely open-source language models or ChatGPT. I will show you how to create a prompt and get an answer from LLM. As an example application, I will show a demo of an intelligent agent using web search and generating Python code to answer questions about this conference.

There is a gold rush to apply AI to anything nowadays. Anyone can do it, you no longer need to be a Machine Learning Engineer! Just write some prompts for ChatGPT.

There is a saying "During a gold rush - sell shovels". This talk is about a wonderful tool, LangChain, as easy to use as a good shovel.

This talk is about LangChain, a Python open-source tool for prompt engineering. You can use it with completely open-source language models or ChatGPT.

The project started 6 months ago and now has 25k Github stars and raised $10 mln. What is all this about?

This talk is a gentle introduction. It will show how to:
- create a simple prompt
- get an answer from a Large Language Model of your choice - local or API
- chain requests together to search the web, use Python REPL
- make LLM choose which tools to use for complex questions
- answer questions over a collection of long documents

As an example application, we will code an AI agent to answer "When is the PyCon DE & PyData Berlin 2023 conference? How many days are between that date and today?" using web search and Python REPL.

Lev Konstantinovskiy

April 19, 2023
Tweet

Transcript

  1. Collect Data Hire ML Building ML prototypes before LLMs was

    hard Label Data Build Model Serving Infra Product V1 Build Model
  2. Collect Data Hire ML Building ML products before LLMs Label

    Data Build Model Serving Infra Product V1 3rd Party LLM API Prompt Engineering After LLMs Integrate Context or Prop Data Label Data Product V1 Build Model Fine- Tune Continuous User Feedback Product V2 Product V3 Based on Diego Oppenheimer “DevTools for Language Models”
  3. Collect Data Hire ML Before LLMs life was hard Label

    Data Build Model Serving Infra Product V1 3rd Party LLM API Prompt Engineering After LLMs it is a bike ride to V1! And then it gets hard again Integrate Context or Prop Data Label Data Product V1 Build Model Fine- Tune Continuous User Feedback Product V2 Product V3 Based on Diego Oppenheimer “DevTools for Language Models”
  4. 3rd Party LLM API Prompt Engineering Integrate Context or Prop

    Data Label Data Product V1 Fine- Tune Continuous User Feedback Product V2 Product V3 🦜🔗Langchain During a Gold Rush, Sell Shovels!
  5. Code Example Answer the questions: When is the PyCon DE

    & PyData Berlin 2023 conference? How many days are between that date and today? You can use the internet and Python REPL Notebook in repo: https://github.com/tmylk/langchain- agent-qa/blob/main/AgentQA.ipynb
  6. Tool - Deterministic - Like - Python - Send an

    email LLM learns new tools very easily from short description in Prompt “Calculator: Useful for when you need to answer questions about math.” - Non-deterministic. Makes its’ own decisions. - Every time we call it, can get a different result. - Google Search results change - Underlying LLM is non-deterministic - “Agent-as-a-service" trend. Agent tools = load_tools([ "serpapi", "llm-math"], llm=my_llm) my_agent = initialize_agent( tools, my_llm, agent="zero-shot-react -description", verbose=True)
  7. Answer: The PyCon DE & PyData Berlin 2023 conference is

    on 16 January 12:00 CET and there are 45017 days between that date and today.
  8. Prompt Engineering is tricky Small change to prompt and tools

    - big change in result. Only works for a flimsy V1 of the product. See notebook. - Google + Python = wrong conference date, correct today’s date - Indexed Website + PythonMath = correct conference date(!), wrong todays date - Indexed Website + Python for dates = wrong conference date, correct today’s date - To-Do list generator = goes on a tangent about conference food
  9. Future of LangChain - TypeScript support on par with Python

    - Frontend dev skills are enough create an ML product V1 in 2023 - Don't worry. Python still needed for V2 and V3 - More new papers implemented in nice Python - Production support by LangChain Inc - More Agents, Document readers, Retrievals, Input and Output formats
  10. Thank you. Join a meetup to code Langchain together. Notebook

    in repo: https://github.com/tmylk/la ngchain-agent-qa/blob/main /AgentQA.ipynb