GithubHelp home page GithubHelp logo

mikejin5c / lagent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from internlm/lagent

0.0 0.0 0.0 124 KB

A lightweight framework for building LLM-based agents

License: Apache License 2.0

Python 100.00%

lagent's Introduction

docs PyPI license issue resolution open issues

English | 简体中文

👋 join us on Twitter, Discord and WeChat

## Introduction

Lagent is a lightweight open-source framework that allows users to efficiently build large language model(LLM)-based agents. It also provides some typical tools to augment LLM. The overview of our framework is shown below:

image

Major Features

  • Support multiple kinds of agents out of box. Lagent now supports ReAct, AutoGPT and ReWOO, which can drive the large language models(LLMs) for multiple trials of reasoning and function calling.

  • Extremely simple and easy to extend. The framework is quite simple with a clear structure. With only 20 lines of code, you are able to construct your own agent. It also supports three typical tools: Python interpreter, API call, and google search.

  • Support various large language models. We support different LLMs, including API-based (GPT-3.5/4) and open-source (LLaMA 2, InternLM) models.

Getting Started

Please see the overview for the general introduction of Lagent. Meanwhile, we provide extremely simple code for quick start. You may refer to examples for more details.

Installation

Install with pip (Recommended).

pip install lagent

Optionally, you could also build Lagent from source in case you want to modify the code:

git clone https://github.com/InternLM/lagent.git
cd lagent
pip install -e .

Run ReAct Web Demo

# You need to install streamlit first
# pip install streamlit
streamlit run examples/react_web_demo.py

Then you can chat through the UI shown as below image

Run a ReWOO agent with GPT-3.5

Below is an example for running ReWOO with GPT-3.5

from lagent.agents import ReWOO
from lagent.actions import ActionExecutor, GoogleSearch, LLMQA
from lagent.llms import GPTAPI

llm = GPTAPI(model_type='gpt-3.5-turbo', key=['Your OPENAI_API_KEY'])
search_tool = GoogleSearch(api_key='Your SERPER_API_KEY')
llmqa_tool = LLMQA(llm)

chatbot = ReWOO(
    llm=llm,
    action_executor=ActionExecutor(
        actions=[search_tool, llmqa_tool]),
)

response = chatbot.chat('What profession does Nicholas Ray and Elia Kazan have in common')
print(response.response)
>>> Film director.

Run a ReAct agent with InternLM

NOTE: If you want to run a HuggingFace model, please run pip install -e .[all] first.

from lagent.agents import ReAct
from lagent.actions import ActionExecutor, GoogleSearch, PythonInterpreter
from lagent.llms import HFTransformer

llm = HFTransformer('internlm/internlm-chat-7b-v1_1')
search_tool = GoogleSearch(api_key='Your SERPER_API_KEY')
python_interpreter = PythonInterpreter()

chatbot = ReAct(
    llm=llm,
    action_executor=ActionExecutor(
        actions=[search_tool, python_interpreter]),
)

response = chatbot.chat('若$z=-1+\sqrt{3}i$,则$\frac{z}{{z\overline{z}-1}}=\left(\ \ \right)$')
print(response.response)
>>> $-\\frac{1}{3}+\\frac{{\\sqrt{3}}}{3}i$

License

This project is released under the Apache 2.0 license.

lagent's People

Contributors

harold-lkk avatar zehuichen123 avatar mzr1996 avatar zwwwayne avatar hellock avatar lzhgrla 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.