Note
本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
JARVIS 的使命是探索通用人工智能(AGI),并将前沿研究成果带给整个社区。
server 模式下为 /tasks 和 /results 构建了 Web API。
inference_mode=hybrid 和 local_deployment=standard 构建)/tasks 和 /results 可访问 Stage #1 的中间结果:任务规划,以及 Stage #1-3:带执行结果的模型选择。见 此处。python awesome_chat.py --config configs/config.lite.yaml 即可体验。语言充当接口,使 LLM 能够连接众多 AI 模型以解决复杂的 AI 任务!
请参阅我们的论文:HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in HuggingFace, Yongliang Shen, Kaitao Song, Xu Tan, Dongsheng Li, Weiming Lu and Yueting Zhuang(前两位作者贡献相同)
我们介绍了一个协作系统,由 LLM 作为控制器 和 众多专家模型作为协作执行者(来自 HuggingFace Hub)组成。我们系统的工作流程包含四个阶段:
适用于 configs/config.default.yaml:
damo-vilab/text-to-video-ms-1.7bControlNetstable-diffusion-v1-5适用于 configs/config.lite.yaml:
配置 configs/config.lite.yaml 无需在本地下载和部署任何专家模型。不过,这意味着 Jarvis 仅限于在 HuggingFace Inference Endpoints 上稳定运行的模型。
请先在 server/configs/config.default.yaml 中将 openai.key 和 huggingface.token 替换为 你的个人 OpenAI Key 和 你的 Hugging Face Token,或分别将它们放入环境变量 OPENAI_API_KEY 和 HUGGINGFACE_ACCESS_TOKEN。然后运行以下命令:
# setup env
cd server
conda create -n jarvis python=3.8
conda activate jarvis
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
pip install -r requirements.txt
# download models. Make sure that `git-lfs` is installed.
cd models
bash download.sh # required when `inference_mode` is `local` or `hybrid`.
# run server
cd ..
python models_server.py --config configs/config.default.yaml # required when `inference_mode` is `local` or `hybrid`
python awesome_chat.py --config configs/config.default.yaml --mode server # for text-davinci-003
现在你可以通过 Web API 访问 Jarvis 的服务。
/hugginggpt --method POST,访问完整服务。/tasks --method POST,访问第 1 阶段的中间结果。/results --method POST,访问第 1-3 阶段的中间结果。例如:
# request
curl --location 'http://localhost:8004/tasks' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{
"role": "user",
"content": "based on pose of /examples/d.jpg and content of /examples/e.jpg, please show me a new image"
}
]
}'
# response
[{"args":{"image":"/examples/d.jpg"},"dep":[-1],"id":0,"task":"openpose-control"},{"args":{"image":"/examples/e.jpg"},"dep":[-1],"id":1,"task":"image-to-text"},{"args":{"image":"<GENERATED>-0","text":"<GENERATED>-1"},"dep":[1,0],"id":2,"task":"openpose-text-to-image"}]
我们提供了一个用户友好的网页。在以服务端模式启动 awesome_chat.py 后,你可以运行以下命令在浏览器中与 Jarvis 交互:
nodejs 和 npm。http://{LAN_IP_of_the_server}:{port}/ 设置为 web/src/config/index.ts 的 HUGGINGGPT_BASE_URL。ffmpeg。double click 切换到 ChatGPT!cd web
npm install
npm run dev
# Optional: Install ffmpeg
# This command need be executed without errors.
LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/ffmpeg -i input.mp4 -vcodec libx264 output.mp4
Gradio 演示现已托管在 Hugging Face Space 上。你也可以运行以下命令在本地启动演示:
python models_server.py --config configs/config.gradio.yaml
python run_gradio_demo.py --config configs/config.gradio.yaml
# or run the HF Space as a Docker image (Build with `inference_mode=hibrid` and `local_deployment=standard`)
docker run -it -p 7860:7860 --platform=linux/amd64 registry.hf.space/microsoft-hugginggpt:latest python app.py
你也可以在 CLI 模式下更轻松地运行 Jarvis:
cd server
python awesome_chat.py --config configs/config.default.yaml --mode cli
CLI 模式示例:
Welcome to Jarvis! A collaborative system that consists of an LLM as the controller and numerous expert models as collaborative executors. Jarvis can plan tasks, schedule Hugging Face models, generate friendly responses based on your requests, and help you with many things. Please enter your request (`exit` to exit).
[ User ]: Given a collection of image A: /examples/a.jpg, B: /examples/b.jpg, C: /examples/c.jpg, please tell me how many zebras in these picture?
[ Jarvis ]: Based on your request, I have used several models to process the images you provided. For the image A: /examples/a.jpg, I used the image-to-text model nlpconnect/vit-gpt2-image-captioning to generate the text "a cat sitting on a window sill looking out". Then I used the object-detection model facebook/detr-resnet-50 to generate the image with predicted box '/images/a3dc.jpg', which contains two objects with labels 'potted plant' and 'cat'. For the image B: /examples/b.jpg, I used the image-to-text model nlpconnect/vit-gpt2-image-captioning to generate the text "two zebras standing in a field of dry grass". Then I used the object-detection model facebook/detr-resnet-50 to generate the image with predicted box '/images/f5df.jpg', which contains three objects with labels 'zebra'. For the image C: /examples/c.jpg, I used the image-to-text model nlpconnect/vit-gpt2-image-captioning to generate the text "a zebra standing in a field of tall grass". Then I used the object-detection model facebook/detr-resnet-50 to generate the image with predicted box '/images/69c7.jpg', which contains one object with label 'zebra'. Finally, I used the canny-control model canny-control to generate the image '/images/7e18.png' based on the image /examples/f.jpg. Therefore, there are four zebras in these pictures. Is there anything else I can help you with?
[ User ]: Please answer all the named entities in the sentence: Iron Man is a superhero appearing in American comic books published by Marvel Comics. The character was co-created by writer and editor Stan Lee, developed by scripter Larry Lieber, and designed by artists Don Heck and Jack Kirby.
[ Jarvis ]: Sure, I understand your request. Based on the inference results of the models, I will answer your request step by step. Firstly, I used the token-classification model dslim/bert-base-NER to recognize the named entities in the sentence. The inference result is that the named entities are Iron Man, Stan Lee, Larry Lieber, Don Heck and Jack Kirby. Then, I used the question-answering model deepset/roberta-base-squad2 to answer your request. The inference result is that there is no output since the context cannot be empty. Therefore, I cannot make it. I hope this answer your request. Is there anything else I can help you with?
[ User ]: Please generate a canny image based on /examples/f.jpg
[ Jarvis ]: Sure. I have generated a canny image based on /examples/f.jpg. To do this, I first used the image-to-text model nlpconnect/vit-gpt2-image-captioning to generate the text description of the image, which is "a herd of giraffes and zebras grazing in a field". Then I used the canny-control model to generate the canny image of the original image, which is stored in the path "/images/1ea2.png". Finally, I used the canny-text-to-image model lllyasviel/sd-controlnet-canny to generate the canny image based on the text description and the canny image, which is stored in the path "/images/ba66.png". Do you need anything else?
服务端配置文件为 server/configs/config.default.yaml,部分参数如下所示:
model:LLM,当前支持 text-davinci-003。我们正在努力集成更多开源 LLM。inference_mode:推理端点(inference endpoints)模式
local:仅使用本地推理端点huggingface:仅使用 Hugging Face Inference Endpoints (无需本地推理端点)hybrid:同时使用 local 和 huggingfacelocal_deployment:本地部署模型的规模,适用于 local 或 hybrid 推理模式:
minimal (RAM>12GB, ControlNet only)standard (RAM>16GB, ControlNet + Standard Pipelines)full (RAM>42GB, All registered models)在个人笔记本电脑上,我们推荐使用 inference_mode: hybrid 和 local_deployment: minimal 的配置。但由于远程 Hugging Face Inference Endpoints 的不稳定性,在此设置下可用模型可能会受到限制。
项目包含一个 Dockerfile,为 NVIDIA Jetson 嵌入式设备. 该镜像提供加速版 ffmpeg、pytorch、torchaudio 和 torchvision 依赖。要构建 Docker 镜像,请确保默认 Docker 运行时设置为 'nvidia'. 预构建镜像见 https://hub.docker.com/r/toolboc/nv-jarvis.
#Build the docker image
docker build --pull --rm -f "Dockerfile.jetson" -t toolboc/nv-jarvis:r35.2.1
由于内存要求,JARVIS 需要在 Jetson AGX Orin 系列设备上运行(优先选择板载 64G RAM 的设备),并将配置选项设置为:
inference_mode: locallocal_deployment: standard建议通过从宿主机到容器的卷挂载提供模型和配置,如下方 docker run 步骤所示。你也可以取消注释 Dockerfile 中的 # Download local models 部分,以构建包含模型的容器。
# run the container which will automatically start the model server
docker run --name jarvis --net=host --gpus all -v ~/jarvis/configs:/app/server/configs -v ~/src/JARVIS/server/models:/app/server/models toolboc/nv-jarvis:r35.2.1
# (wait for model server to complete initialization)
# start awesome_chat.py
docker exec jarvis python3 awesome_chat.py --config configs/config.default.yaml --mode server
#start the web application (application will be acessible at http://localhost:9999)
docker exec jarvis npm run dev --prefix=/app/web
如果你在方法中觉得本工作有用,可以按如下方式引用论文:
@inproceedings{shen2023hugginggpt,
author = {Shen, Yongliang and Song, Kaitao and Tan, Xu and Li, Dongsheng and Lu, Weiming and Zhuang, Yueting},
booktitle = {Advances in Neural Information Processing Systems},
title = {HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in HuggingFace},
year = {2023}
}
@article{shen2023taskbench,
title = {TaskBench: Benchmarking Large Language Models for Task Automation},
author = {Shen, Yongliang and Song, Kaitao and Tan, Xu and Zhang, Wenqi and Ren, Kan and Yuan, Siyu and Lu, Weiming and Li, Dongsheng and Zhuang, Yueting},
journal = {arXiv preprint arXiv:2311.18760},
year = {2023}
}
@article{yuan2024easytool,
title = {EASYTOOL: Enhancing LLM-based Agents with Concise Tool Instruction},
author = {Siyu Yuan and Kaitao Song and Jiangjie Chen and Xu Tan and Yongliang Shen and Ren Kan and Dongsheng Li and Deqing Yang},
journal = {arXiv preprint arXiv:2401.06201},
year = {2024}
}