240909-ChuanhuChatGPT集成Ollama的环境配置

A. 最终效果

B. 需求文件

  • requirements.txt (至少需要安装这个,具体参见官网)
  • requirements_advanced.txt (如果安装了Ollama,并且可以进行对话,可以不需要安装,具体参见官网)
  • requirements_succcess.txt(由于新旧版本版本不兼容,我这边在Ubuntu22.04条时候的最终版本,如下)
python 复制代码
aiofiles==23.2.1
aiohappyeyeballs==2.4.0
aiohttp==3.10.5
aiosignal==1.3.1
altair==5.4.1
annotated-types==0.7.0
anthropic==0.18.1
anyio==4.4.0
arxiv==2.1.3
async-timeout==4.0.3
attrs==24.2.0
backoff==2.2.1
backports.tarfile==1.2.0
beautifulsoup4==4.12.3
cachetools==5.5.0
certifi==2024.8.30
cffi==1.17.1
chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
commentjson==0.9.0
contourpy==1.3.0
cryptography==43.0.1
cycler==0.12.1
dataclasses-json==0.6.7
deepdiff==8.0.1
distro==1.9.0
docstring_parser==0.16
duckduckgo_search==6.2.8
emoji==2.12.1
et-xmlfile==1.1.0
exceptiongroup==1.2.2
faiss-cpu==1.7.4
fastapi==0.112.4
feedparser==6.0.11
ffmpy==0.4.0
filelock==3.16.0
filetype==1.2.0
fonttools==4.53.1
frozenlist==1.4.1
fsspec==2024.9.0
google-ai-generativelanguage==0.6.6
google-api-core==2.19.2
google-api-python-client==2.144.0
google-auth==2.34.0
google-auth-httplib2==0.2.0
google-cloud-aiplatform==1.65.0
google-cloud-bigquery==3.25.0
google-cloud-core==2.4.1
google-cloud-resource-manager==1.12.5
google-cloud-storage==2.18.2
google-crc32c==1.6.0
google-generativeai==0.7.2
google-resumable-media==2.7.2
google_search_results==2.4.2
googleapis-common-protos==1.65.0
googlesearch-python==1.2.5
gradio==4.26.0
gradio_client==0.15.1
greenlet==3.0.3
groq==0.11.0
grpc-google-iam-v1==0.13.1
grpcio==1.66.1
grpcio-status==1.48.2
h11==0.14.0
httpcore==1.0.5
httplib2==0.22.0
httpx==0.27.2
huggingface-hub==0.24.6
idna==3.8
importlib_resources==6.4.4
jaraco.context==6.0.1
Jinja2==3.1.4
joblib==1.4.2
jsonpatch==1.33
jsonpath-python==1.0.6
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
kiwisolver==1.4.7
langchain==0.1.14
langchain-community==0.0.38
langchain-core==0.1.52
langchain-openai==0.1.5
langchain-text-splitters==0.0.2
langchainhub==0.1.21
langdetect==1.0.9
langsmith==0.1.116
lark-parser==0.7.8
lxml==5.3.0
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==2.1.5
marshmallow==3.22.0
matplotlib==3.9.2
mdurl==0.1.2
more-itertools==10.5.0
multidict==6.0.5
mypy-extensions==1.0.0
narwhals==1.6.3
nest-asyncio==1.6.0
nltk==3.9.1
numexpr==2.10.1
numpy==1.26.4
olefile==0.47
ollama==0.3.2
openai==1.16.2
openpyxl==3.1.5
orderly-set==5.2.2
orjson==3.10.7
packaging==23.2
pandas==2.2.2
pandoc==2.4
pdfminer.six==20231228
pdfplumber==0.11.4
pillow==10.4.0
plumbum==1.8.3
ply==3.11
primp==0.5.5
proto-plus==1.24.0
protobuf==3.20.3
psutil==6.0.0
pyasn1==0.6.0
pyasn1_modules==0.4.0
pycparser==2.22
pydantic==2.5.2
pydantic_core==2.14.5
pydub==0.25.1
Pygments==2.18.0
pyparsing==3.1.4
pypdf==4.3.1
PyPDF2==3.0.1
pypdfium2==4.30.0
pypinyin==0.52.0
python-dateutil==2.9.0.post0
python-docx==1.1.2
python-iso639==2024.4.27
python-magic==0.4.27
python-multipart==0.0.9
python-oxmsg==0.0.1
pytz==2024.1
PyYAML==6.0.2
rapidfuzz==3.9.7
referencing==0.35.1
regex==2024.7.24
requests==2.32.3
requests-toolbelt==1.0.0
rich==13.8.0
rpds-py==0.20.0
rsa==4.9
ruff==0.6.4
semantic-version==2.10.0
sgmllib3k==1.0.0
shapely==2.0.6
shellingham==1.5.4
six==1.16.0
sniffio==1.3.1
socksio==1.0.0
soupsieve==2.6
SQLAlchemy==2.0.34
starlette==0.38.5
tabulate==0.9.0
tenacity==8.5.0
tiktoken==0.7.0
tokenizers==0.20.0
tomlkit==0.12.0
tqdm==4.66.5
typer==0.12.5
types-requests==2.32.0.20240907
typing-inspect==0.9.0
typing_extensions==4.12.2
tzdata==2024.1
ujson==5.10.0
unstructured==0.15.9
unstructured-client==0.25.7
uritemplate==4.1.1
urllib3==2.2.2
uvicorn==0.30.6
websocket-client==1.8.0
websockets==11.0.3
wikipedia==1.4.0
wolframalpha==5.1.3
wrapt==1.16.0
xmltodict==0.13.0
yarl==1.11.0

C. 环境配置

json 复制代码
{
    // 各配置具体说明,见 [https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程#配置-configjson]

    //== API 配置 ==
    // ⭐️ 这里填写的Ollama
    "openai_api_key": "Ollama", // 你的 OpenAI API Key,一般必填,若空缺则需在图形界面中填入API Key
    "google_genai_api_key": "", // 你的 Google Gemini API Key ,用于 Google Gemini 对话模型
    "xmchat_api_key": "", // 你的 xmchat API Key,用于 XMChat 对话模型
    "minimax_api_key": "", // 你的 MiniMax API Key,用于 MiniMax 对话模型
    "minimax_group_id": "", // 你的 MiniMax Group ID,用于 MiniMax 对话模型
    "midjourney_proxy_api_base": "https://xxx/mj", // 你的 https://github.com/novicezk/midjourney-proxy 代理地址
    "midjourney_proxy_api_secret": "", // 你的 MidJourney Proxy API Secret,用于鉴权访问 api,可选
    "midjourney_discord_proxy_url": "", // 你的 MidJourney Discord Proxy URL,用于对生成对图进行反代,可选
    "midjourney_temp_folder": "./tmp", // 你的 MidJourney 临时文件夹,用于存放生成的图片,填空则关闭自动下载切图(直接显示MJ的四宫格图)
    "spark_appid": "", // 你的 讯飞星火大模型 API AppID,用于讯飞星火大模型对话模型
    "spark_api_key": "", // 你的 讯飞星火大模型 API Key,用于讯飞星火大模型对话模型
    "spark_api_secret": "", // 你的 讯飞星火大模型 API Secret,用于讯飞星火大模型对话模型
    "claude_api_secret":"",// 你的 Claude API Secret,用于 Claude 对话模型
    "ernie_api_key": "",// 你的文心一言在百度云中的API Key,用于文心一言对话模型
    "ernie_secret_key": "",// 你的文心一言在百度云中的Secret Key,用于文心一言对话模型
    "ollama_host": "", // 你的 Ollama Host,用于 Ollama 对话模型
    "huggingface_auth_token": "", // 你的 Hugging Face API Token,用于访问有限制的模型
    "groq_api_key": "", // 你的 Groq API Key,用于 Groq 对话模型(https://console.groq.com/)

    //== Azure ==
    "openai_api_type": "openai", // 可选项:azure, openai
    "azure_openai_api_key": "", // 你的 Azure OpenAI API Key,用于 Azure OpenAI 对话模型
    "azure_openai_api_base_url": "", // 你的 Azure Base URL
    "azure_openai_api_version": "2023-05-15", // 你的 Azure OpenAI API 版本
    "azure_deployment_name": "", // 你的 Azure OpenAI Chat 模型 Deployment 名称
    "azure_embedding_deployment_name": "", // 你的 Azure OpenAI Embedding 模型 Deployment 名称
    "azure_embedding_model_name": "text-embedding-ada-002", // 你的 Azure OpenAI Embedding 模型名称

    //== 基础配置 ==
    "language": "auto", // 界面语言,可选"auto", "zh_CN", "en_US", "ja_JP", "ko_KR", "sv_SE", "ru_RU", "vi_VN"
    "users": [], // 用户列表,[["用户名1", "密码1"], ["用户名2", "密码2"], ...]
    "local_embedding": false, //是否在本地编制索引
    "hide_history_when_not_logged_in": false, //未登录情况下是否不展示对话历史
    "check_update": true, //是否启用检查更新
    "default_model": "Ollama", // 默认模型
    "chat_name_method_index": 2, // 选择对话名称的方法。0: 使用日期时间命名;1: 使用第一条提问命名,2: 使用模型自动总结
    "bot_avatar": "default", // 机器人头像,可填写本地或网络图片链接,或者"none"(不显示头像)
    "user_avatar": "default", // 用户头像,可填写本地或网络图片链接,或者"none"(不显示头像)

    //== API 用量 ==
    "show_api_billing": false, //是否显示OpenAI API用量(启用需要填写sensitive_id)
    "sensitive_id": "", // 你 OpenAI 账户的 Sensitive ID,用于查询 API 用量
    "usage_limit": 120, // 该 OpenAI API Key 的当月限额,单位:美元,用于计算百分比和显示上限
    "legacy_api_usage": false, // 是否使用旧版 API 用量查询接口(OpenAI现已关闭该接口,但是如果你在使用第三方 API,第三方可能仍然支持此接口)

    //== 川虎助理设置 ==
    "GOOGLE_CSE_ID": "", //谷歌搜索引擎ID,用于川虎助理Pro模式,获取方式请看 https://stackoverflow.com/questions/37083058/programmatically-searching-google-in-python-using-custom-search
    "GOOGLE_API_KEY": "", //谷歌API Key,用于川虎助理Pro模式
    "WOLFRAM_ALPHA_APPID": "", //Wolfram Alpha API Key,用于川虎助理Pro模式,获取方式请看 https://products.wolframalpha.com/api/
    "SERPAPI_API_KEY": "", //SerpAPI API Key,用于川虎助理Pro模式,获取方式请看 https://serpapi.com/

    //== 文档处理与显示 ==
    "latex_option": "default", // LaTeX 公式渲染策略,可选"default", "strict", "all"或者"disabled"
    "advance_docs": {
        "pdf": {
            "two_column": false, // 是否认为PDF是双栏的
            "formula_ocr": true // 是否使用OCR识别PDF中的公式
        }
    },

    //== 高级配置 ==
    // 是否多个API Key轮换使用
    "multi_api_key": false,
    "hide_my_key": false, // 如果你想在UI中隐藏 API 密钥输入框,将此值设置为 true
    // "available_models": ["GPT3.5 Turbo", "GPT4 Turbo", "GPT4 Vision"], // 可用的模型列表,将覆盖默认的可用模型列表
    // "extra_models": ["模型名称3", "模型名称4", ...], // 额外的模型,将添加到可用的模型列表之后
    // "api_key_list": [
    //     "sk-xxxxxxxxxxxxxxxxxxxxxxxx1",
    //     "sk-xxxxxxxxxxxxxxxxxxxxxxxx2",
    //     "sk-xxxxxxxxxxxxxxxxxxxxxxxx3"
    // ],
    // 自定义OpenAI API Base
    // "openai_api_base": "https://api.openai.com",
    // 自定义使用代理(请替换代理URL)
    // "https_proxy": "http://127.0.0.1:1079",
    // "http_proxy": "http://127.0.0.1:1079",
    // 自定义端口、自定义ip(请替换对应内容)
    "server_name": "0.0.0.0",
    "server_port": 7860,
    // 如果要share到gradio,设置为true
    // "share": false,
    //如果不想自动打开浏览器,设置为false
    //"autobrowser": false
    // ⭐️ 用户界面中将会显示的模型
    "available_models": ["qwen2:7b", "llama3.1:8b"], 
	
	// ⭐️ 手动添加的Ollama模型,api_host与model_name需要和Ollama对应上
    "extra_model_metadata": { //
        "qwen2:7b": {
            "model_name": "qwen2:7b",
            "description": "An expert of mean jokes, who answers all user questions in a humorous and mean way.",
            "model_type": "OpenAIVision",
            "multimodal": false,
            // "api_host": "http://localhost:11434/v1/chat/completions",
            "api_host": "http://localhost:11434",
            "token_limit": 4096,
            "max_generation": 4096,
            "system": "You are an expert of mean jokes. You Answer all user questions in a humorous and mean way, pretending you are Elon Musk.",
            "placeholder": {
                "logo": "https://wallpaperaccess.com/full/9170621.png",
                "slogan": "I am NOT politically correct",
                "question_1": "How can I get X Premium+?",
                "question_2": "Roast me pls",
                "question_3": "What's the true nature of the universe",
                "question_4": "Ai is biased",
            }
        },
        
        "llama3.1:8b": {
            "model_name": "llama3.1:8b",
            "description": "An expert of mean jokes, who answers all user questions in a humorous and mean way.",
            "model_type": "OpenAIVision",
            "multimodal": false,
            // "api_host": "http://localhost:11434/v1/chat/completions",
            "api_host": "http://localhost:11434",
            "token_limit": 4096,
            "max_generation": 4096,
            "system": "You are an expert of mean jokes. You Answer all user questions in a humorous and mean way, pretending you are Elon Musk.",
            "placeholder": {
                "logo": "https://wallpaperaccess.com/full/9170621.png",
                "slogan": "I am NOT politically correct",
                "question_1": "How can I get X Premium+?",
                "question_2": "Roast me pls",
                "question_3": "What's the true nature of the universe",
                "question_4": "Ai is biased",
            }
        },
    },
    
}

D. 问题解决

  • 在运行代码的时候会报错,主要是安装包版本不兼容的问题
  • 我这边在先后执行玩下面的操作后,可以正常运行代码
bash 复制代码
pip install --upgrade gradio
pip install gradio==4.26.0
pip install gradio==4.29.0

E. 参考文献

相关推荐
掘金者阿豪1 小时前
把业务数据变成共享仪表盘:Metabase可视化与远程访问实践
前端·后端
kyriewen1 小时前
折腾了半年 AI 编程工作流,最后发现效率瓶颈是桌上那块屏幕
前端·javascript·ai编程
蜗牛前端2 小时前
codex 全流程开发上线的高颜值礼簿小程序
前端·微信小程序
大龄秃头程序员2 小时前
我在图文流 App 里落地双层缓存、弱网降级与 OOM 治理
前端
老王以为2 小时前
React Renderer 分离的多平台架构
前端·react native·react.js
hunterandroid2 小时前
Kotlin Coroutines 与 Flow:让异步任务更清晰
前端
Bigger3 小时前
从零搭建 AI 代码审查服务:一份前端也能看懂的 Python 学习笔记
前端·ci/cd·ai编程
lichenyang4533 小时前
JSAPI、NAPI、Biz、Imp:ASCF Demo 如何真正调用系统能力和 C++ 能力
前端
lichenyang4534 小时前
IPC、JSVM、UIThread、libuv:ASCF 架构图里最容易混的几个词
前端
匹诺曹i3674 小时前
docx 报表进 OpenClaw 本地 RAG:memory 索引实践与 6 个坑
ollama