paint-brush
Beep Beep Bop Bop: 로컬 LLM을 사용하여 여러 AI 에이전트를 배포하는 방법by@babycommando
10,511
10,511

Beep Beep Bop Bop: 로컬 LLM을 사용하여 여러 AI 에이전트를 배포하는 방법

Baby Commando10m2023/10/19
Read on Terminal Reader

Llama2 및 Mistral-7b와 같은 로컬 LLM을 사용하여 여러 로컬 Ai 에이전트 배포.
featured image - Beep Beep Bop Bop: 로컬 LLM을 사용하여 여러 AI 에이전트를 배포하는 방법
Baby Commando HackerNoon profile picture
0-item
1-item

Llama2 및 Mistral-7b와 같은 로컬 LLM을 사용하여 여러 로컬 Ai 에이전트 배포.


“절대로 기계의 일을 하도록 사람을 보내지 마세요”

— 스미스 요원


유료 OpenAi 대신 로컬 LLM을 사용하여 Autogen으로 조직화된 AI 에이전트 군대를 구축하는 방법을 찾고 계십니까? 그렇다면 당신은 바로 이곳에 왔습니다!


채팅 LLM은 훌륭하지만 지능형 에이전트로서 조치를 취하는 것이 다음 단계입니다. 그들 중 다수는 어떻습니까? Microsoft의 최신 Autogen 프로젝트를 만나보세요.


하지만 문제가 있습니다. Autogen은 기본적으로 OpenAi에 연결되도록 만들어졌는데, 이는 제한적이고 비용이 많이 들고 검열/비지각적입니다. 그렇기 때문에 Mistral-7B 같은 간단한 LLM을 로컬로 사용하는 것이 가장 좋은 방법입니다. Llama2 , Falcon , Vicuna , Alpaca 등 원하는 다른 모델과 함께 사용할 수도 있습니다. 하늘(하드웨어)은 실제로 한계가 있습니다.


비결은 Oobabooga의 text- Generation-webui와 같은 로컬 LLM 서버에서 openai JSON 스타일의 출력을 사용한 다음 이를 autogen에 연결하는 것입니다. 그것이 오늘 우리가 만들고 있는 것입니다.


llama.cpp Python 바인딩과 마찬가지로 openai api 형식으로 llms spit 텍스트를 만드는 다른 방법도 있습니다.


이 튜토리얼에서는 다음을 수행합니다. 0. Oobabooga의 text- Generation-webui, LLM(Mistral-7b) 및 Autogen 가져오기

  1. Oobabooga에서 OpenAi 형식 확장 설정

  2. OpenAi 형식으로 로컬 LLM 서버 시작

  3. Autogen에 연결하기


시작하자!


[스미스 요원] "나, 나, 나.."


0. Oobabooga의 Text-Generation-Webui, LLM(Mistral-7b) 및 Autogen 얻기


계속 진행하기 전에 pip 패키지 설치 시 가상 환경을 사용하는 것이 좋습니다. 원하는 경우 새 것을 만들고 활성화하십시오.


Obbabooga의 Text Generation Webui 얻기: 이것은 로컬 컴퓨터에서 LLM을 호스팅하는 잘 알려진 프로그램입니다. text- Generation-webui 페이지 로 이동하여 설치 가이드를 따르세요. 시작하는 것은 매우 간단합니다. 가속을 위해 NVIDIA GPU를 사용하는 경우 CUDA를 다운로드할 수도 있습니다.


LLM 받기(Mistral-7b-Instruct): 텍스트 생성 webui를 다운로드한 후 아직 시작하지 마세요. 에이전트에게 생명을 불어넣으려면 LLM이 필요합니다.


오늘 우리는 Mistral-7B , 특히 TheBloke의 최적화된 모델 버전인 Mistral-7B-instruct-v0.1.Q4_K_S.gguf를 살펴보겠습니다. 설명에 있는 설명을 바탕으로 귀하의 기계에 가장 적합한 최적화된 모델을 선택할 수 있습니다.


하드웨어에 따라 더 작거나 더 큰 모델을 선택할 수 있습니다. 컴퓨터에 있는 것들을 시험해 보는 것을 너무 두려워하지 마세요. 우리는 여기서 과학을 만들고 있습니다.


파일 및 버전 페이지 로 이동하여 다음을 가져옵니다.

  • 구성.json

  • Mistral-7B-instruct-v0.1.Q4_K_S.gguf (대부분의 중간 설정에서 잘 실행됨)


파일 및 버전 페이지


다운로드가 완료되면 text- Generation-webui 설치 폴더로 이동하여 그 안에 models 폴더를 엽니다 . 여기에 "mistral-7b-instruct" 와 같이 모델 이름(또는 원하는 이름)으로 새 폴더를 만듭니다 . 경로는 다음과 같습니다.


 C:/.../text-generation-webui/models/mistral-7b-instruct


config.json 파일과 model.gguf를 모두 새 폴더에 배치합니다.


자동 생성 얻기 :
Python 라이브러리를 만드는 Microsoft의 다중 에이전트를 설치하려면 터미널에서 pip 패키지 설치 프로그램을 사용하여 설치하면 됩니다.


 pip install pyautogen


1. Oobabooga에서 OpenAi 형식 확장 설정


[스미스 요원] "당신은 중요한 근육만 빼고 모든 근육을 사용하고 있습니다"


새로운 text- Generation-webui를 설치하고 LLM을 다운로드하면 로컬 Oobabooga 서버가 OpenAi JSON 형식으로 말할 수 있도록 진행할 수 있습니다. OpenAi API 형식과 기능에 대해 자세히 알아볼 수 있습니다. 선적 서류 비치 .


Autogen을 로컬 서버와 연결하려면 Ooobaboga의 text- Generation-webui 확장 폴더에서 "openai" 확장을 활성화해야 합니다.


터미널에서 "text- Generation-webui/extensions/openai" 폴더로 이동하여 해당 요구 사항을 설치합니다.


 pip install -r requirements.txt


2. OpenAi 형식으로 로컬 LLM 서버 시작

이제 터미널의 /text- Generation-webui 루트 폴더로 돌아갑니다. 이제 이 아기를 일으켜 세워야 할 시간입니다.


이름에서 알 수 있듯이 webui로 사용하기 위한 것이지만, 사용자가 만드는 다른 프로그램에서 API를 쿼리하기 위해 서버로 계속 실행할 수도 있습니다.


openai api 확장을 사용하여 로컬 서버로 부팅하려면 현재 OS에 따라 다음 명령을 사용하십시오.


"model" 매개변수를 이전에 /models에서 만든 폴더 이름으로 변경하는 것을 잊지 마세요. (제 경우에는 폴더 이름을 **“**mistral-7b-instruct”로 지정했습니다)


윈도우:

 ./start_windows.bat --extensions openai --listen --loader llama.cpp --model mistral-7b-instruct


리눅스:

 ./start_linux.sh --extensions openai --listen --loader llama.cpp --model mistral-7b-instruct


맥 OS:

 ./start_macos.sh --extensions openai --listen --loader llama.cpp --model mistral-7b-instruct


확장 openai 매개변수를 전달하여 확장을 로드하고, config.json모델을 사용하여 이전에 만든 모델 폴더 이름과 모델에 대한 로더를 지정하는 자동 생성, 로더 및 모델에서 쿼리할 수 있는 서버 시작을 수신 합니다. gguf 파일.


모든 것이 올바르게 진행되면 다음과 같은 내용이 표시될 수 있습니다.


성공!


webui는 일반적인 시작으로 로컬 호스트 포트 7860에서 실행되지만 OpenAI 호환 API도 로컬 호스트의 Autogen에서 사용할 준비가 되어 있습니다. http://127.0.0.1:5001/v1 .


3. Autogen에 연결

이 시점에서는 이미 autogen lib가 설치되어 있으므로 이를 가져와 LLM 서버에 연결할 차례입니다.


인간(당신)과 상호 작용하는 단일 에이전트라는 간단한 것부터 시작해 보겠습니다. 원하는 곳에 새 디렉토리를 만들고 거기에 새 autogen.py 파일을 추가하세요. 원하는 대로 파일 이름을 바꿀 수도 있습니다.


일반적으로 OpenAi GPT의 API에 간단히 연결하려면 다음과 같이 파일을 시작합니다.


 import autogen #start importing the autogen lib config_list = [ { 'model': 'gpt-3.5-turbo', 'api_key': 'your openai real key here' } ]


그러나 실행 중인 로컬 서버를 사용하려면 다음과 같이 시작합니다.


 import autogen #start importing the autogen lib config_list = [ { "model": "mistral-instruct-7b", #the name of your running model "api_base": "http://127.0.0.1:5001/v1", #the local address of the api "api_type": "open_ai", "api_key": "sk-111111111111111111111111111111111111111111111111", # just a placeholder } ]


로컬에서 작업하는 데 실제 키가 필요하지 않으므로 sk-1111… 자리 표시자를 사용하고 있습니다.

다음으로 에이전트와 실제 사용자를 설정할 수 있습니다. 더 나은 이해를 위해 댓글을 읽어보세요.


 import autogen #start importing the autogen lib config_list = [ { "model": "mistral-instruct-7b", #the name of your running model "api_base": "http://127.0.0.1:5001/v1", #the local address of the api "api_type": "open_ai", "api_key": "sk-111111111111111111111111111111111111111111111111", # just a placeholder } ] # create an ai AssistantAgent named "assistant" assistant = autogen.AssistantAgent( name="assistant", llm_config={ "seed": 42, # seed for caching and reproducibility "config_list": config_list, # a list of OpenAI API configurations "temperature": 0, # temperature for sampling "request_timeout": 400, # timeout }, # configuration for autogen's enhanced inference API which is compatible with OpenAI API ) # create a human UserProxyAgent instance named "user_proxy" user_proxy = autogen.UserProxyAgent( name="user_proxy", human_input_mode="NEVER", max_consecutive_auto_reply=10, is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), code_execution_config={ "work_dir": "agents-workspace", # set the working directory for the agents to create files and execute "use_docker": False, # set to True or image name like "python:3" to use docker }, ) # the assistant receives a message from the user_proxy, which contains the task description user_proxy.initiate_chat( assistant, message="""Create a posting schedule with captions in instagram for a week and store it in a .csv file.""", )


초기 주문 시 메시지=”…”를 변경하는 것을 잊지 마세요.


메시지와 함께 스크립트를 실행하면 에이전트가 "수동으로" 생성한 .csv 파일이 포함된 "agents-workspace"라는 새 디렉터리가 표시될 수 있습니다.


[스미스 요원] "하하하하"


이제 좀 더 발전된 내용을 살펴보겠습니다.
역할과 컨텍스트가 있는 여러 에이전트.


이는 여러분이 알고 있는 다른 메시징 앱과 마찬가지로 "채팅 그룹"처럼 작동합니다. 그들의 컨텍스트(시스템 메시지)는 어떻게 행동해야 하는지, 어떤 계층 구조를 따라야 하는지 알려줍니다. 이번에는 다음을 갖게 됩니다.


  • 두 사람: 관리자와 집행자.
  • 네 명의 대리인: 엔지니어, 과학자, 기획자, 비평가.


 import autogen #Use the local LLM server same as before config_list = [ { "model": "mistral-instruct-7b", #the name of your running model "api_base": "http://127.0.0.1:5001/v1", #the local address of the api "api_type": "open_ai", "api_key": "sk-111111111111111111111111111111111111111111111111", # just a placeholder } ] # set a "universal" config for the agents agent_config = { "seed": 42, # change the seed for different trials "temperature": 0, "config_list": config_list, "request_timeout": 120, } # humans user_proxy = autogen.UserProxyAgent( name="Admin", system_message="A human admin. Interact with the planner to discuss the plan. Plan execution needs to be approved by this admin.", code_execution_config=False, ) executor = autogen.UserProxyAgent( name="Executor", system_message="Executor. Execute the code written by the engineer and report the result.", human_input_mode="NEVER", code_execution_config={"last_n_messages": 3, "work_dir": "paper"}, ) # agents engineer = autogen.AssistantAgent( name="Engineer", llm_config=agent_config, system_message='''Engineer. You follow an approved plan. You write python/shell code to solve tasks. Wrap the code in a code block that specifies the script type. The user can't modify your code. So do not suggest incomplete code which requires others to modify. Don't use a code block if it's not intended to be executed by the executor. Don't include multiple code blocks in one response. Do not ask others to copy and paste the result. Check the execution result returned by the executor. If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try. ''', ) scientist = autogen.AssistantAgent( name="Scientist", llm_config=agent_config, system_message="""Scientist. You follow an approved plan. You are able to categorize papers after seeing their abstracts printed. You don't write code.""" ) planner = autogen.AssistantAgent( name="Planner", system_message='''Planner. Suggest a plan. Revise the plan based on feedback from admin and critic, until admin approval. The plan may involve an engineer who can write code and a scientist who doesn't write code. Explain the plan first. Be clear which step is performed by an engineer, and which step is performed by a scientist. ''', llm_config=agent_config, ) critic = autogen.AssistantAgent( name="Critic", system_message="Critic. Double check plan, claims, code from other agents and provide feedback. Check whether the plan includes adding verifiable info such as source URL.", llm_config=agent_config, ) # start the "group chat" between agents and humans groupchat = autogen.GroupChat(agents=[user_proxy, engineer, scientist, planner, executor, critic], messages=[], max_round=50) manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=agent_config) # Start the Chat! user_proxy.initiate_chat( manager, message=""" find papers on LLM applications from arxiv in the last week, create a markdown table of different domains. """, ) # to followup of the previous question, use: # user_proxy.send( # recipient=assistant, # message="""your followup response here""", # )


자, 새로운 요원 군대가 생겼습니다.


우리는 자유롭기 때문에 여기에 있는 것이 아닙니다. 우리는 자유롭지 않기 때문에 여기에 있습니다.

이러한 종류의 에이전시 자동화가 수행할 수 있는 다른 작업을 이해하려면 Autogen 문서를 더 자세히 살펴보는 것이 좋습니다.


또한 자동 생성이 내부적으로 어떻게 작동하는지 이해한 후 다음과 같은 인터페이스를 통해 이를 사용하고 싶을 수도 있습니다. 자동 생성 UI , 또는 회사의 대시보드에서 자신만의 대시보드를 만들 수도 있습니다.


이제 그것은 당신에게 달려 있습니다. OpenAi의 한계에서 벗어나 에이전트를 조율하여 인류를 위한 더 나은 미래를 구축하세요. 큰 힘에는 큰 책임이 따른다는 사실을 늘 기억하세요. 그럼, 다음에는 무엇을 만들 예정인가요?


[스미스 요원] “왜요, 앤더슨 씨? 왜? 당신은 왜 계속합니까?” [네오] “내가 선택하니까.”


이 게시물은 전적으로 인간™에 의해 작성되었습니다.

여기에도 게시되었습니다.