Package: localagent
Local-Agent: A open implementation of GPT agentslocalagent empowers you to craft Large Language Model (LLM) Agents tailored to your needs, utilizing your own functions and tools alongsidelocal 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-5d7b69fbee06Table of ContentsLocal Agent: A tool for creating agents with local llms.Table of Contents🚀 Features📋 Requirements💾 Installation🔧 UsageSetup webui apiRunning agentsNative Code InterpreterAuto Knowledge RetrivalUsing different llms🔍 Custom tools🐦 Connect with Us on Twitter🚀 FeaturesCreate 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.📋 RequirementsPython 3.7 or laterOptional:HuggingFace API key💾 InstallationTo install Local-Agent, follow these steps:well, just,pip install localagent🔧 UsageUsing Agents with textgeneration webui.Create any kinda agent usingCreateAgentclass fromlocalagent.initialize_agentsSetup webui apiUse open LLMs in localagent usingtextgenerationwebui api.Clone textgen webui.git clone https://github.com/oobabooga/text-generation-webui.githeads up to main folder and run the following command to start the webui locally to download open models from huggingface.python3 server.pySelect capable model and download it. (This packagelocalagentis primarily usesopenchat-3.5model)Running agentsStart the llm with textgeneration webui asAPI. change directory to textgeneration webui and type the following commandpython3 server.py --api --api-blocking-port 5050 --model openchat_3.5.Q4_K_M.gguf --n-gpu-layers 20 --n_batch 512NOTE:The args such as--n-gpu-layersand--n_batchrequire GPU support.Create simple agent by typing the following commands.fromlocalagent.initialize_agentsimportCreateAgentagent=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)Using Agents with ollama.Installollamadownload any models from cli using ollama. You can download any model you want.ollama run dolphin2.2-mistralThat's all you need to setup for agents with ollama. Lets create a agent with it.fromlocalagent.initialize_agentsimportCreateAgentagent=CreateAgent(ollama_model_name='dolphin2.2-mistral')Native Code InterpreterYou 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:fromlocalagent.initialize_agentsimportCreateAgentagent=CreateAgent(webui_url='ws://127.0.0.1:5005/api/v1/stream',use_codeinterpreter=True,# That's itverbose=True)agent.go_flow('Checkout my ip address in the system.')Auto Knowledge RetrivalLot 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.fromlocalagent.initialize_agentsimportCreateAgentfromlocalagent.knowledge_baseimportKnowledgeBaseknowledge=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 variablesexport HUGGINGFACEHUB_API_TOKEN=hf_xxxxxxxxUsing different llmsworking with webui: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 512While creating the agent class, make sure that use have pass a correct human, assistant, and eos tokens. For example.fromlocalagent.initialize_agentsimportCreateAgentagent=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_='
user\n',assistant_='
assistant\n',eos_token='
',verbose=True)working with ollama:This example shows how to useOpenHermes 2.5with ollama!Make sure to pull the model before executing the code.fromlocalagent.initialize_agentsimportCreateAgentagent=CreateAgent(ollama_model_name='openhermes2.5-mistral',use_codeinterpreter=True,verbose=True,stream=True,system_="
system\n",human_='
user\n',assistant_='
assistant\n')Feel free to adjust thesystem_,human_,assistant_parameters depends upon the model.Custom toolsYou can able to build agents with your own tools.fromlocalagent.initialize_agentsimportCreateAgentdefsearch(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?')Let's create full-fledged AI assistant.importosfrommetaphor_pythonimportMetaphorfromlocalagentimportCreateAgentmetaphor=Metaphor(os.environ.get("METAPHOR_API_KEY"))defsearch(search_query:str)->dict:response=metaphor.search(search_query,num_results=1,use_autoprompt=True)returnf"{response.autoprompt_string}\n{str(response.get_contents())}"defupdate_memory(data:str):withopen("memory.txt","a")asf:f.write(data+'\n')returnf"Updated memory with{data}."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':'search_query','description':'Search for a keyword or phrase','required':True,'schema':{'type':'string'},}],"function":search},{'name_for_human':'Memory','name_for_model':'update_memory','description_for_model':'update_memory is a tool that helps to store important info in local permanent memory.','parameters':[{'name':'data','description':'Enter data to store such as user name, remainders etc.','required':True,'schema':{'type':'string'},}],"function":update_memory},]agent=CreateAgent(system_prompt="You are a personal assistant who has wide knowledge in world topics.",webui_url='ws://127.0.0.1:5005/api/v1/stream',tools=tools,use_codeinterpreter=True,)agent.go_flow('Check out my IP address.')🐦 Connect with Us on TwitterStay 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!