GithubHelp home page GithubHelp logo

dasiths / llm-plan-and-execute-knowledge-provider-mesh Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 99 KB

Extending the abilities of GPT4 using LangChain Plan and Execute agent to introduce a "knowledge provider" concept.

Home Page: https://dasith.me

License: MIT License

Shell 1.52% Python 98.48%
agent api azure-openai gpt4 llm openai openai-functions rest plan-and-execute

llm-plan-and-execute-knowledge-provider-mesh's Introduction

๐Ÿ”— Knowledge Provider Mesh

This exercise demonstrates how to use the "Plan and Execute" agent type from LangChain to consume "knowledge provider" APIs.

A "knowledge provider" is a wrapper around an existing API or data source that exposes that to the Agent in a curated fashion. (i.e. Prompt hints, input error etc in a human readable fashion.)

Alternatively, you can use a raw (not wrapped) API directly but it may need to have simple inputs and outputs to make it a viable option. The SerpAPI is a good example.

๐Ÿ’ก Why Do We Need This

This is an experiment to show that you can use GPT4 with Plan and Execute agent type to work with "existing" APIs and data sources. This means you can start integrating the LLM with existing information systems. The LLM is powerful enough to understand where to go for the data and connect different disparate sources of data to formulate an answer than spans many domains within the same org or different orgs.

While "slow", this demonstrates the true power of the LLM. The responses and steps are not deterministic but the final answers are mostly are accurate for it to be useful in many scenarios.

๐Ÿ”ง How It Works

This examples uses the catalog.py script to load the catalog.json file which contains information about the knowledge providers. Those are then fed into the Plan and Execute agent as "tools".

The plumbing happens in the knowledge_provider.py file. It creates the required wrapping around the LangChain base tool to intercept and handle the call to the API endpoint.

We have 2 knowledge providers available. One returns a hardcoded value for weather based on a date. The other returns information about Hardy stores. Note: The Hardy store information isn't complete and the find_closest_store function returns a hardcoded mock response each time regardless of what suburb is passed in.

The agent also has a tool which allows it to ask you questions during the planned run if it needs further clarification. The user input prompt will come up on the terminal where you ran the agent from.

๐Ÿค– Plan And Execute

These are the papers and information which this experiment was inspired from.

LangChain PlanAndExecute: https://python.langchain.com/docs/modules/agents/agent_types/plan_and_execute

โŒจ๏ธ How To Run It

  1. Create a .env file based on the .env.sample file and populate the values. I have only tested it with gpt-4-32k so your milage may vary with GPT 3.5 based models.

  2. First run the 2 knowledge providers.

    python3 ./store_and_stock_app.py
    python3 ./weather_app.py
  3. Then, run the agent.

    streamlit run ./agents_example.py

    Use the browser app running on localhost:8501 to provide user input and view results.

๐Ÿ“– Notes

  • The "knowledge provider" description in the catalog.json provide important information to the LLM on how it should generate input.
  • The actual "knowledge provider" (API wrapper) itself sends helpful information with the result and human readable error messages when things don't go right. This allows the LLM to understand and dynamically change its plan if required. Or ask for the user to provide further input.

๐Ÿ”ฌ Example Dump From Run

Plan

> Entering new PlanAndExecute chain...

steps=[
        Step(value='Identify the location of Heathmont.'),
        Step(value='Identify the locations of all Hardy stores.'),
        Step(value='Calculate the distance from Heathmont to each Hardy store.'),
        Step(value='Sort the Hardy stores by distance from Heathmont.'),
        Step(value='Select the three closest Hardy stores.'),
        Step(value='Check the inventory of each of these stores for the Ryobi One Plus 18V Drill.'),
        Step(value='Record the quantity of the Ryobi One Plus 18V Drill available at each store.'),
        Step(value='Given the above steps taken, please respond to the users original question with the three closest Hardy stores to Heathmont that have the Ryobi One Plus 18V Drill and the quantity available at each store.\n')
    ]

User Input

Example User Input

Output

Example Result

llm-plan-and-execute-knowledge-provider-mesh's People

Contributors

dasiths avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.