modelscope / modelscope-agent

ModelScope-Agent: An agent framework connecting models in ModelScope with the world
https://modelscope-agent.readthedocs.io/en/latest/
Apache License 2.0
2.71k stars 310 forks source link

本地部署apps/msgpt出错,可以正常请求,但回答是空白 #284

Closed MGzhou closed 9 months ago

MGzhou commented 9 months ago

我本地部署apps/msgpt出错,可以正常请求,但回答是空白。

image

大模型我是调用本地的ModelScope-Agent-7B,并参考demo/demo_register_new_tool.ipynb添加了自定义工具

将apps/msgpt/app.py的模型代码替换为下面的

from modelscope_agent.tools import Tool
# 工具类
class AliyunRenewInstanceTool(Tool):
    description = '续费一台包年包月ECS实例'
    name = 'RenewInstance'
    parameters: list = [{
        'name': 'instance_id',
        'description': 'ECS实例ID',
        'required': True
    }, {
        'name': 'period',
        'description': '续费时长以月为单位',
        'required': True
    }]

    def _local_call(self, *args, **kwargs):
        instance_id = kwargs['instance_id']
        period = kwargs['period']
        return {'result': f'已完成ECS实例ID为{instance_id}的续费,续费时长{period}月'}

model_name = 'modelscope-agent-7b'
model_cfg = {
    'modelscope-agent-7b':{
        'type': 'modelscope',
        'model_id': "./ModelScope-Agent-7B",
        'model_revision': 'v1.0.4',
        'use_raw_generation_config': True,
        'custom_chat': True,
    }
}
llm = LLMFactory.build_llm(model_name, model_cfg)

    # 新增工具可参考AliyunRenewInstanceTool构建方式,配置相关的api name,description等
additional_tool_list = {
    'RenewInstance': AliyunRenewInstanceTool(),

}
# 构建Agent,需要传入llm,工具配置config以及工具检索
agent = AgentExecutor(llm, additional_tool_list=additional_tool_list, tool_retrieval=False)
available_tool_list = ['RenewInstance']
agent.set_available_tools(available_tool_list)
MGzhou commented 9 months ago

经过打印apps/msgpt/predict.py的stream_predict的response变量,发现response可以输出大模型返回的结果,但不知道为什么response发送给chatbot变量后没有在前端展示。 image image

mushenL commented 9 months ago

您好,可以提供一下您的gradio版本,我这边复现一下,您可以先使用release/0.3.0分支的apps/agentfabric的方式构建

MGzhou commented 9 months ago

你好,我用的gradio==3.47.1版本。

MGzhou commented 9 months ago

所有包的版本信息如下

absl-py 2.1.0 accelerate 0.24.1 addict 2.4.0 aiofiles 23.2.1 aiohttp 3.8.4 aiosignal 1.3.1 aliyun-python-sdk-core 2.13.36 aliyun-python-sdk-kms 2.16.1 altair 5.2.0 annotated-types 0.6.0 anyio 3.7.1 appdirs 1.4.4 asttokens 2.4.1 astunparse 1.6.3 async-timeout 4.0.2 attrs 23.1.0 auto-gptq 0.5.1 backoff 2.2.1 beautifulsoup4 4.12.3 blinker 1.7.0 cachetools 5.3.2 certifi 2023.11.17 cffi 1.15.1 chardet 5.2.0 charset-normalizer 3.2.0 cld2-cffi 0.1.4 click 8.1.7 cmake 3.26.4 colorama 0.4.6 coloredlogs 15.0.1 comm 0.2.0 contourpy 1.2.0 cpm-kernels 1.0.11 crcmod 1.7 cryptography 41.0.2 cycler 0.12.1 dacite 1.8.1 dashscope 1.14.0 dataclasses-json 0.6.3 datasets 2.8.0 debugpy 1.8.0 decorator 4.4.2 deepspeed 0.12.3 dill 0.3.6 distro 1.9.0 docstring-parser 0.15 einops 0.6.1 emoji 2.10.0 et-xmlfile 1.1.0 evaluate 0.4.1 exceptiongroup 1.2.0 executing 2.0.1 faiss-cpu 1.7.4 fastapi 0.104.1 fasttext-wheel 0.9.2 ffmpy 0.3.1 filelock 3.12.2 filetype 1.2.0 flash-attn 2.3.5 fonttools 4.46.0 frozenlist 1.4.0 fschat 0.2.34 fsspec 2023.6.0 gast 0.5.4 gekko 1.0.6 gitdb 4.0.11 GitPython 3.1.40 google-auth 2.26.2 google-auth-oauthlib 1.2.0 gradio 3.47.1 gradio_client 0.6.0 greenlet 3.0.3 grpcio 1.60.0 h11 0.14.0 hanlp 2.1.0b54 hanlp-common 0.0.19 hanlp-downloader 0.0.25 hanlp-trie 0.0.5 hf_transfer 0.1.4 hjson 3.1.0 httpcore 1.0.2 httpx 0.25.2 huggingface-hub 0.20.3 humanfriendly 10.0 icetk 0.0.4 idna 3.4 imageio 2.33.1 imageio-ffmpeg 0.4.9 importlib-metadata 6.8.0 importlib-resources 6.1.1 iniconfig 2.0.0 ipykernel 6.27.1 ipython 8.18.1 jedi 0.19.1 jieba 0.42.1 Jinja2 3.1.2 jmespath 0.10.0 joblib 1.3.2 jsonpatch 1.33 jsonpath-python 1.0.6 jsonplus 0.8.0 jsonpointer 2.4 jsonschema 4.20.0 jsonschema-specifications 2023.11.2 jupyter_client 8.6.0 jupyter_core 5.5.0 kiwisolver 1.4.5 langchain 0.0.352 langchain-community 0.0.11 langchain-core 0.1.9 langchain-experimental 0.0.47 langdetect 1.0.9 langsmith 0.0.79 latex2mathml 3.77.0 lit 16.0.6 loguru 0.7.2 lxml 5.1.0 Markdown 3.5.1 markdown-cjk-spacing 0.2.2 markdown-it-py 3.0.0 markdown-katex 202112.1034 markdown2 2.4.12 MarkupSafe 2.1.3 marshmallow 3.20.2 matplotlib 3.8.2 matplotlib-inline 0.1.6 mdtex2html 1.2.0 mdurl 0.1.2 mdx-truly-sane-lists 1.3 modelscope 1.9.5 moviepy 1.0.3 mpmath 1.3.0 ms-swift 1.5.3 multidict 6.0.4 multiprocess 0.70.14 mypy-extensions 1.0.0 nest-asyncio 1.5.8 networkx 3.1 nh3 0.2.15 ninja 1.11.1.1 nltk 3.8.1 numpy 1.23.5 nvidia-cublas-cu11 11.10.3.66 nvidia-cuda-cupti-cu11 11.7.101 nvidia-cuda-nvrtc-cu11 11.7.99 nvidia-cuda-runtime-cu11 11.7.99 nvidia-cudnn-cu11 8.5.0.96 nvidia-cufft-cu11 10.9.0.58 nvidia-curand-cu11 10.2.10.91 nvidia-cusolver-cu11 11.4.0.1 nvidia-cusparse-cu11 11.7.4.91 nvidia-nccl-cu11 2.14.3 nvidia-nvtx-cu11 11.7.91 oauthlib 3.2.2 openai 1.6.1 opencv-python 4.9.0.80 openpyxl 3.1.2 optimum 1.14.1 orjson 3.9.10 oss2 2.18.1 packaging 23.2 pandas 2.0.3 parso 0.8.3 pathlib2 2.3.7.post1 peft 0.7.1 pexpect 4.9.0 phrasetree 0.0.8 Pillow 10.0.0 pip 23.1.2 platformdirs 3.9.1 pluggy 1.3.0 proglog 0.1.10 prompt-toolkit 3.0.41 protobuf 3.20.0 psutil 5.9.5 ptyprocess 0.7.0 pure-eval 0.2.2 py-cpuinfo 9.0.0 pyarrow 12.0.1 pyasn1 0.5.1 pyasn1-modules 0.3.0 pybind11 2.11.1 pycparser 2.21 pycryptodome 3.18.0 pydantic 2.1.1 pydantic_core 2.4.0 pydeck 0.8.1b0 pydub 0.25.1 Pygments 2.17.2 pymdown-extensions 10.7 pynvml 11.5.0 pyparsing 3.1.1 pypdf 4.0.0 pytest 7.4.4 python-dateutil 2.8.2 python-dotenv 1.0.0 python-iso639 2024.1.2 python-magic 0.4.27 python-multipart 0.0.6 python-slugify 8.0.1 pytz 2023.3 PyYAML 6.0.1 pyzmq 25.1.2 rapidfuzz 3.6.1 referencing 0.31.1 regex 2023.6.3 requests 2.31.0 requests-oauthlib 1.3.1 responses 0.18.0 rich 13.7.0 rouge 1.0.1 rpds-py 0.13.2 rsa 4.9 safetensors 0.4.1 scipy 1.11.1 semantic-version 2.10.0 sentencepiece 0.1.99 setuptools 67.8.0 setuptools-scm 8.0.4 shellingham 1.5.4 shortuuid 1.0.11 shtab 1.6.5 simplejson 3.19.1 six 1.16.0 smmap 5.0.1 sniffio 1.3.0 sortedcontainers 2.4.0 soundfile 0.12.1 soupsieve 2.5 SQLAlchemy 2.0.19 sse-starlette 1.8.2 stack-data 0.6.3 starlette 0.27.0 streamlit 1.28.2 svgwrite 1.4.3 sympy 1.12 tabulate 0.9.0 tenacity 8.2.3 tensorboard 2.15.1 tensorboard-data-server 0.7.2 termcolor 2.3.0 text-unidecode 1.3 tiktoken 0.5.1 tokenizers 0.15.1 toml 0.10.2 tomli 2.0.1 tomlkit 0.12.0 toolz 0.12.0 toposort 1.5 torch 2.0.1 torchvision 0.15.2 tornado 6.4 tqdm 4.65.0 traitlets 5.14.0 transformers 4.36.2 transformers-stream-generator 0.0.4 triton 2.0.0 trl 0.7.10 typer 0.9.0 typing_extensions 4.9.0 typing-inspect 0.9.0 tyro 0.6.0 tzdata 2023.3 tzlocal 5.2 unstructured 0.12.2 unstructured-client 0.15.5 urllib3 2.0.3 uvicorn 0.24.0.post1 validators 0.22.0 watchdog 3.0.0 wavedrom 2.0.3.post3 wcwidth 0.2.12 websockets 11.0.3 Werkzeug 3.0.1 wheel 0.38.4 wrapt 1.16.0 xxhash 3.2.0 yapf 0.40.1 yarl 1.9.2 zipp 3.16.2

seanxuu commented 9 months ago

同样的问题

wenmengzhou commented 9 months ago

这种问题一般是后台日志报错了,可以看下命令行的日志

seanxuu commented 9 months ago

这种问题一般是后台日志报错了,可以看下命令行的日志

Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
upload_image_url: 

user_input: 你好

就卡这里了。

然后我看应该是走到了predict.py的以下位置: image

seanxuu commented 9 months ago

我用的也是gradio==3.47.1版本。请问执行这个例子,需要正确使用哪个版本的gradio

seanxuu commented 9 months ago

我用的也是gradio==3.47.1版本。请问执行这个例子,需要正确使用哪个版本的gradio

有办法解决吗

mushenL commented 9 months ago

您好,可以尝试把gradio版本降级到3.39.0试试?

seanxuu commented 9 months ago

您好,可以尝试把gradio版本降级到3.39.0试试?

好像可以了,这个也太难了。完全想不到是这个原因。

MGzhou commented 9 months ago

把gradio版本降级到3.39.0,成功解决问题,感谢帮助@mushenL