当前位置:   article > 正文

QAnything+Ollama搭建本地知识库_qanything ollama

qanything ollama

1、Ollama安装使用

参考我的另一篇博客:ollama + fastgpt 搭建免费本地知识库-CSDN博客

2、QAnything

概述:

QAnything (Question and Answer based on Anything) 是致力于支持任意格式文件或数据库的本地知识库问答系统,可断网安装使用。

您的任何格式的本地文件都可以往里扔,即可获得准确、快速、靠谱的问答体验。

目前已支持格式: PDF(pdf),Word(docx),PPT(pptx),XLS(xlsx),Markdown(md),电子邮件(eml),TXT(txt),图片(jpg,jpeg,png),CSV(csv),网页链接(html),更多格式,敬请期待...

纯Python环境安装:

  1. conda create -n qanything-python python=3.10
  2. conda activate qanything-python
  3. git clone -b qanything-python https://github.com/netease-youdao/QAnything.git
  4. cd QAnything
  5. pip install -e .

启动运行QAnything:

  1. # 本地已经启动了ollama,这里做个运行测试
  2. # 因为我的ollama里没有安装llama3模型,所以修改一下run_for_ollama_api_in_M1_mac.sh的参数。改成使用qwen2:latest模型
  3. #!/bin/bash
  4. #bash scripts/base_run.sh -s "M1mac" -w 4 -m 19530 -q 8777 -o -b 'http://localhost:11434/v1' -k 'ollama' -n 'llama3' -l '4096'
  5. bash scripts/base_run.sh -s "M1mac" -w 4 -m 19530 -q 8777 -o -b 'http://localhost:11434/v1' -k 'ollama' -n 'qwen2:latest' -l '4096'
  6. # 启动运行
  7. bash scripts/run_for_ollama_api_in_M1_mac.sh

报错了

报错信息如下:

  1. (base) ➜ QAnything git:(qanything-python) ✗ bash scripts/run_for_ollama_api_in_M1_mac.sh
  2. 即将启动后端服务,启动成功后请复制[http://0.0.0.0:8777/qanything/]到浏览器进行测试。
  3. 运行qanything-server的命令是:
  4. CUDA_VISIBLE_DEVICES=0 python3 -m qanything_kernel.qanything_server.sanic_api --host 0.0.0.0 --port 8777 --model_size 7B --use_openai_api --openai_api_base http://localhost:11434/v1 --openai_api_key ollama --openai_api_model_name llama3 --openai_api_context_length 4096 --workers 4
  5. LOCAL DATA PATH: /Users/renlibin/PythonProjects/QAnything/QANY_DB/content
  6. LOCAL_RERANK_REPO: maidalun/bce-reranker-base_v1
  7. LOCAL_EMBED_REPO: maidalun/bce-embedding-base_v1
  8. 2024-06-28 17:34:14,614 - modelscope - INFO - PyTorch version 2.1.2 Found.
  9. 2024-06-28 17:34:14,614 - modelscope - INFO - Loading ast index from /Users/renlibin/.cache/modelscope/ast_indexer
  10. 2024-06-28 17:34:14,614 - modelscope - INFO - No valid ast index found from /Users/renlibin/.cache/modelscope/ast_indexer, generating ast index from prebuilt!
  11. 2024-06-28 17:34:14,691 - modelscope - INFO - Loading done! Current index file version is 1.13.0, with md5 f0dca17f6b67762919fb8486c6f931f5 and a total number of 972 components indexed
  12. use_cpu: False
  13. use_openai_api: True
  14. The server is starting on port: 8777
  15. onnxruntime 1.18.0 已经安装。
  16. 2024-06-28 17:34:15,469 使用openai api llama3 无需下载大模型
  17. Traceback (most recent call last):
  18. File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/runpy.py", line 196, in _run_module_as_main
  19. return _run_code(code, main_globals, None,
  20. File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/runpy.py", line 86, in _run_code
  21. exec(code, run_globals)
  22. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/qanything_server/sanic_api.py", line 164, in <module>
  23. from .handler import *
  24. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/qanything_server/handler.py", line 1, in <module>
  25. from qanything_kernel.core.local_file import LocalFile
  26. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/core/local_file.py", line 5, in <module>
  27. from qanything_kernel.utils.loader.my_recursive_url_loader import MyRecursiveUrlLoader
  28. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/__init__.py", line 4, in <module>
  29. from .self_pdf_loader import PdfLoader
  30. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/self_pdf_loader.py", line 3, in <module>
  31. from qanything_kernel.utils.loader.pdf_to_markdown.core.parser import PdfParser
  32. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/parser/__init__.py", line 3, in <module>
  33. from .pdf_parser import HuParser as PdfParser, PlainParser
  34. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/parser/pdf_parser.py", line 18, in <module>
  35. from qanything_kernel.utils.loader.pdf_to_markdown.core.nlp import huqie
  36. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/nlp/__init__.py", line 4, in <module>
  37. from . import huqie
  38. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/nlp/huqie.py", line 4, in <module>
  39. import datrie
  40. ImportError: dlopen(/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so, 0x0002): tried: '/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (no such file), '/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))
  41. (base) ➜ QAnything git:(qanything-python) ✗ bash scripts/run_for_ollama_api_in_M1_mac.sh
  42. 即将启动后端服务,启动成功后请复制[http://0.0.0.0:8777/qanything/]到浏览器进行测试。
  43. 运行qanything-server的命令是:
  44. CUDA_VISIBLE_DEVICES=0 python3 -m qanything_kernel.qanything_server.sanic_api --host 0.0.0.0 --port 8777 --model_size 7B --use_openai_api --openai_api_base http://localhost:11434/v1 --openai_api_key ollama --openai_api_model_name qwen2 --openai_api_context_length 4096 --workers 4
  45. LOCAL DATA PATH: /Users/renlibin/PythonProjects/QAnything/QANY_DB/content
  46. LOCAL_RERANK_REPO: maidalun/bce-reranker-base_v1
  47. LOCAL_EMBED_REPO: maidalun/bce-embedding-base_v1
  48. 2024-06-28 17:38:17,124 - modelscope - INFO - PyTorch version 2.1.2 Found.
  49. 2024-06-28 17:38:17,124 - modelscope - INFO - Loading ast index from /Users/renlibin/.cache/modelscope/ast_indexer
  50. 2024-06-28 17:38:17,150 - modelscope - INFO - Loading done! Current index file version is 1.13.0, with md5 f0dca17f6b67762919fb8486c6f931f5 and a total number of 972 components indexed
  51. use_cpu: False
  52. use_openai_api: True
  53. The server is starting on port: 8777
  54. onnxruntime 1.18.0 已经安装。
  55. 2024-06-28 17:38:17,274 使用openai api qwen2 无需下载大模型
  56. Traceback (most recent call last):
  57. File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/runpy.py", line 196, in _run_module_as_main
  58. return _run_code(code, main_globals, None,
  59. File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/runpy.py", line 86, in _run_code
  60. exec(code, run_globals)
  61. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/qanything_server/sanic_api.py", line 164, in <module>
  62. from .handler import *
  63. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/qanything_server/handler.py", line 1, in <module>
  64. from qanything_kernel.core.local_file import LocalFile
  65. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/core/local_file.py", line 5, in <module>
  66. from qanything_kernel.utils.loader.my_recursive_url_loader import MyRecursiveUrlLoader
  67. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/__init__.py", line 4, in <module>
  68. from .self_pdf_loader import PdfLoader
  69. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/self_pdf_loader.py", line 3, in <module>
  70. from qanything_kernel.utils.loader.pdf_to_markdown.core.parser import PdfParser
  71. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/parser/__init__.py", line 3, in <module>
  72. from .pdf_parser import HuParser as PdfParser, PlainParser
  73. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/parser/pdf_parser.py", line 18, in <module>
  74. from qanything_kernel.utils.loader.pdf_to_markdown.core.nlp import huqie
  75. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/nlp/__init__.py", line 4, in <module>
  76. from . import huqie
  77. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/nlp/huqie.py", line 4, in <module>
  78. import datrie
  79. ImportError: dlopen(/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so, 0x0002): tried: '/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (no such file), '/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))
  80. (base) ➜ QAnything git:(qanything-python) ✗ clear
  81. (base) ➜ QAnything git:(qanything-python) ✗ bash scripts/run_for_ollama_api_in_M1_mac.sh
  82. 即将启动后端服务,启动成功后请复制[http://0.0.0.0:8777/qanything/]到浏览器进行测试。
  83. 运行qanything-server的命令是:
  84. CUDA_VISIBLE_DEVICES=0 python3 -m qanything_kernel.qanything_server.sanic_api --host 0.0.0.0 --port 8777 --model_size 7B --use_openai_api --openai_api_base http://localhost:11434/v1 --openai_api_key ollama --openai_api_model_name qwen2:latest --openai_api_context_length 4096 --workers 4
  85. LOCAL DATA PATH: /Users/renlibin/PythonProjects/QAnything/QANY_DB/content
  86. LOCAL_RERANK_REPO: maidalun/bce-reranker-base_v1
  87. LOCAL_EMBED_REPO: maidalun/bce-embedding-base_v1
  88. 2024-06-28 17:38:56,804 - modelscope - INFO - PyTorch version 2.1.2 Found.
  89. 2024-06-28 17:38:56,804 - modelscope - INFO - Loading ast index from /Users/renlibin/.cache/modelscope/ast_indexer
  90. 2024-06-28 17:38:56,830 - modelscope - INFO - Loading done! Current index file version is 1.13.0, with md5 f0dca17f6b67762919fb8486c6f931f5 and a total number of 972 components indexed
  91. use_cpu: False
  92. use_openai_api: True
  93. The server is starting on port: 8777
  94. onnxruntime 1.18.0 已经安装。
  95. 2024-06-28 17:38:56,951 使用openai api qwen2:latest 无需下载大模型
  96. Traceback (most recent call last):
  97. File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/runpy.py", line 196, in _run_module_as_main
  98. return _run_code(code, main_globals, None,
  99. File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/runpy.py", line 86, in _run_code
  100. exec(code, run_globals)
  101. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/qanything_server/sanic_api.py", line 164, in <module>
  102. from .handler import *
  103. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/qanything_server/handler.py", line 1, in <module>
  104. from qanything_kernel.core.local_file import LocalFile
  105. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/core/local_file.py", line 5, in <module>
  106. from qanything_kernel.utils.loader.my_recursive_url_loader import MyRecursiveUrlLoader
  107. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/__init__.py", line 4, in <module>
  108. from .self_pdf_loader import PdfLoader
  109. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/self_pdf_loader.py", line 3, in <module>
  110. from qanything_kernel.utils.loader.pdf_to_markdown.core.parser import PdfParser
  111. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/parser/__init__.py", line 3, in <module>
  112. from .pdf_parser import HuParser as PdfParser, PlainParser
  113. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/parser/pdf_parser.py", line 18, in <module>
  114. from qanything_kernel.utils.loader.pdf_to_markdown.core.nlp import huqie
  115. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/nlp/__init__.py", line 4, in <module>
  116. from . import huqie
  117. File "/Users/renlibin/PythonProjects/QAnything/qanything_kernel/utils/loader/pdf_to_markdown/core/nlp/huqie.py", line 4, in <module>
  118. import datrie
  119. ImportError: dlopen(/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so, 0x0002): tried: '/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (no such file), '/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datrie.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

由报错信息可知,启动用到的库datrie下载了个'x86_64'版本的,而我的电脑是Mac M1 arm架构的,需要的是'arm64'的库。

解决方案:

  1. # 卸载datrie库
  2. pip uninstall datrie
  3. # 重新安装arm架构的datrie库
  4. ARCHFLAGS="-arch arm64" pip install datrie --compile --no-cache-dir

解决问题参考:

macos - M1 mac: mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e') - python - Ask Different

重新运行,问题解决!

点击“返回对话”。问问题测试,给出了回答和信息来源,搞定。

参考:

README_zh.md · 网易有道/QAnything - Gitee.com

QAnything/README_zh.md at qanything-python · netease-youdao/QAnything · GitHub

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/949459
推荐阅读
相关标签
  

闽ICP备14008679号