opengpt is a open implementation of GPT agents by openai.
Project description
Local-Agent: A open implementation of GPT agents
localagent empowers you to craft Large Language Model (LLM) Agents tailored to your needs, utilizing your own functions and tools alongside local open LLMs. Unleash your creative ideas to effortlessly develop diverse agents with localagent. It seamlessly integrates with any openly available LLM and accommodates a wide range of tools, providing flexibility and ease of use.
Demo:
https://github.com/PrAsAnNaRePo/LocalAgent/assets/98259409/229b47df-226f-453c-81a6-5d7b69fbee06
Table of Contents
🚀 Features
- Create Agents with any tools and api calls.
- Comes with native code interpreter support.
- Also it allow to easlily work with document as Retrival-knowledge.
- Supports streaming and non-streaming generation.
📋 Requirements
Optional:
- HuggingFace API key
💾 Installation
To install Local-Agent, follow these steps:
well, just,
pip install localagent
🔧 Usage
- Create any kinda agent using
CreateAgent
class fromlocalagent.initialize_agents
Setup webui api
Use open LLMs in localagent using textgeneration webui api.
- Clone textgen webui.
git clone https://github.com/oobabooga/text-generation-webui.git
- heads up to main folder and run the following command to start the webui locally to download open models from huggingface.
python3 server.py
- Select capable model and download it. (This package
localagent
is primarily uses openchat-3.5 model)
Running agents
- Start the llm with textgeneration webui as API. change directory to textgeneration webui and type the following command
python3 server.py --api --api-blocking-port 5050 --model openchat_3.5.Q4_K_M.gguf --n-gpu-layers 20 --n_batch 512
NOTE:
The args such as --n-gpu-layers
and --n_batch
require GPU support.
- Create simple agent by typing the following commands.
from localagent.initialize_agents import CreateAgent
agent = CreateAgent(
webui_url='ws://127.0.0.1:5005/api/v1/stream', # copy and paste the url you got in the above step.
verbose=True
)
- To run the agent with streaming capablity pass the streaming uri (ends with stream in the url) or To run with non-streaming just pass the url starts with http (for example:
http://127.0.0.1:5050/api
)
Native Code Interpreter
You can able to create a new tool as a code-interpreter, but now its need in a lot places, so local-agent comes with it! here is the example:
from localagent.initialize_agents import CreateAgent
agent = CreateAgent(
webui_url='ws://127.0.0.1:5005/api/v1/stream',
use_codeinterpreter=True # That's it
verbose=True
)
agent.go_flow('Checkout my ip address in the system.')
Auto Knowledge Retrival
- Lot of agents need a knowledge of thier own company or whatever, So use can able to set multiple files as a knowledge for llm. The Agent decides when it needs the information in it.
from localagent.initialize_agents import CreateAgent
from localagent.knowledge_base import KnowledgeBase
knowledge = KnowledgeBase('/home/nnpy/Downloads/Retrival_files')
agent = CreateAgent(
webui_url='ws://127.0.0.1:5005/api/v1/stream',
system_prompt="I have given a study material for you to answer questions from that.",
knowledge_base=knowledge,
verbose=True
)
agent.go_flow('What is the 2nd Experiment?')
- You need Huggingface api key to work with knowledge retrival. follow the steps belo to set HF api token.
Setting up environment variables
export HUGGINGFACEHUB_API_TOKEN=hf_xxxxxxxx
Using different llms
- To use different llms, make sure you have downloaded the model in textgen webui.
- Use the command for the model you want to use:
python3 server.py --api --api-blocking-port 5050 --model <Model name here> --n-gpu-layers 20 --n_batch 512
- While creating the agent class, make sure that use have pass a correct human, assistant, and eos tokens. For example.
from localagent.initialize_agents import CreateAgent
agent = CreateAgent(
webui_url='ws://127.0.0.1:5005/api/v1/stream',
system_prompt="I have given a study material for you to answer questions from that.",
use_codeinterpreter=True,
human_ = '<|im_start|>user\n',
assistant_ = '<|im_start|>assistant\n',
eos_token = '<|im_end|>',
verbose=True
)
Custom tools
You can able to build agents with your own tools.
from localagent.initialize_agents import CreateAgent
def search(query): # arg name should be same as the parameter name in json.
# do the stuff.
return 'result' # return the result of the tools as a string.
tools = [
{
'name_for_human': 'google search',
'name_for_model': 'google_search',
'description_for_model':
'google Search is a general search engine that can be used to access the Internet, query encyclopedia knowledge, understand current affairs news, etc. Use this API only you are not familliar with the topic or any current trends',
'parameters': [{
'name': 'query',
'description': 'Search for a keyword or phrase',
'required': True,
'schema': {
'type': 'string'
},
}],
"function": search
}
]
agent = CreateAgent(
webui_url='ws://127.0.0.1:5005/api/v1/stream',
tools=tools,
verbose=True
)
agent.go_flow('when did openai was founded?')
🐦 Connect with Us on Twitter
Stay up-to-date with the latest news, updates, and insights about Local Agent by following our Twitter accounts. Engage with the developer and the AI's own account for interesting discussions, project updates, and more.
We look forward to connecting with you and hearing your thoughts, ideas, and experiences with Local Agent. Join us on Twitter and let's explore the future of AI together!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.