搭建企业内部的大语言模型系统

简介: 该内容主要介绍了开源大语言模型及其管理方法。首先对比了商业大模型(如ChatGPT)与支持私有部署的开源大模型(如Mistral、Meta Llama),强调了开源模型在安全和隐私方面的优势。接着详细列出了多种大语言模型管理工具,如HuggingFace、Ollama等,并展示了Ollama的快速部署和使用方法。此外,还介绍了大语言模型的应用前端,包括开源平台Ollama-chatbot、PrivateGPT等,以及它们的具体部署步骤和配置示例。最后提供了非私有OpenAI-powered部署方案及其API调用示例。

大纲

  • 开源大语言模型
  • 大语言模型管理
  • 私有大语言模型服务部署方案

开源大语言模型

担心安全与隐私?可私有部署的开源大模型

  • 商业大模型,不支持私有部署
    • ChatGPT
    • Claude
    • Google Gemini
    • 百度问心一言
  • 开源大模型,支持私有部署
    • Mistral
    • Meta Llama
    • ChatGLM
    • 阿里通义千问

常用开源大模型列表

image.png

开源大模型分支

image.png

大语言模型管理

大语言模型管理工具

  • HuggingFace 全面的大语言模型管理平台
  • Ollama 在本地管理大语言模型,下载速度超快
  • llama.cpp 在本地和云端的各种硬件上以最少的设置和最先进的性能实现 LLM 推理
  • GPT4All 一个免费使用、本地运行、具有隐私意识的聊天机器人。无需 GPU 或互联网

Ollama 速度最快的大语言模型管理工具

image.png

image.png

Ollama 的命令

ollama pull llama2
ollama list
ollama run llama2 "Summarize this file: $(cat README.md)"

ollama serve

curl http://localhost:11434/api/generate -d '{
  "model": "llama2",
  "prompt":"Why is the sky blue?"
}'
curl http://localhost:11434/api/chat -d '{
  "model": "mistral",
  "messages": [
    { "role": "user", "content": "why is the sky blue?" }
  ]
}'

image.png

大语言模型的前端

大语言模型的应用前端

  • 开源平台 ollama-chatbot、PrivateGPT、gradio
  • 开源服务 hugging face TGI、langchain-serve
  • 开源框架 langchain llama-index

#

ollama chatbot

docker run -p 3000:3000 ghcr.io/ivanfioravanti/chatbot-ollama:main
## http://localhost:3000

image.png

ollama chatbot

PrivateGPT

PrivateGPT 提供了一个 API,其中包含构建私有的、上下文感知的 AI 应用程序所需的所有构建块。该 API 遵循并扩展了 OpenAI API 标准,支持普通响应和流响应。这意味着,如果您可以在您的工具之一中使用 OpenAI API,则可以使用您自己的 PrivateGPT API,无需更改代码,并且如果您在本地模式下运行 privateGPT,则免费。

image.png

PrivateGPT 架构

  • FastAPI
  • LLamaIndex
  • 支持本地 LLM,比如 ChatGLM llama Mistral
  • 支持远程 LLM,比如 OpenAI Claud
  • 支持嵌入 embeddings,比如 ollama embeddings-huggingface
  • 支持向量存储,比如 Qdrant, ChromaDB and Postgres

PrivateGPT 环境准备

git clone https://github.com/imartinez/privateGPT
cd privateGPT
#不支持3.11之前的版本
python3.11 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip poetry

#虽然官网只说了要安装少部分的依赖,但是那些依赖管理不是那么完善,容易有遗漏
#所以我们的策略就是全都要。
poetry install --extras "ui llms-llama-cpp llms-openai llms-openai-like llms-ollama llms-sagemaker llms-azopenai embeddings-ollama embeddings-huggingface embeddings-openai embeddings-sagemaker embeddings-azopenai vector-stores-qdrant vector-stores-chroma vector-stores-postgres storage-nodestore-postgres"

#或者用这个安装脚本
#poetry install --extras "$(sed -n '/tool.poetry.extras/,/^$/p'  pyproject.toml | awk -F= 'NR>1{print $1}' | xargs)"

ollama 部署方式

ollama pull mistral
ollama pull nomic-embed-text
ollama serve

#官方这个依赖不够,还需要额外安装torch,所以尽量采用上面提到的全部安装的策略
poetry install --extras "ui llms-ollama embeddings-ollama vector-stores-qdrant"
PGPT_PROFILES=ollama poetry run python -m private_gpt

setting-ollama.yaml

server:
  env_name: ${
   
   APP_ENV:ollama}

llm:
  mode: ollama
  max_new_tokens: 512
  context_window: 3900
  temperature: 0.1 #The temperature of the model. Increasing the temperature will make the model answer more creatively. A value of 0.1 would be more factual. (Default: 0.1)

embedding:
  mode: ollama

ollama:
  llm_model: mistral
  embedding_model: nomic-embed-text
  api_base: http://localhost:11434
  tfs_z: 1.0 ## Tail free sampling is used to reduce the impact of less probable tokens from the output. A higher value (e.g., 2.0) will reduce the impact more, while a value of 1.0 disables this setting.
  top_k: 40 ## Reduces the probability of generating nonsense. A higher value (e.g. 100) will give more diverse answers, while a lower value (e.g. 10) will be more conservative. (Default: 40)
  top_p: 0.9 ## Works together with top-k. A higher value (e.g., 0.95) will lead to more diverse text, while a lower value (e.g., 0.5) will generate more focused and conservative text. (Default: 0.9)
  repeat_last_n: 64 ## Sets how far back for the model to look back to prevent repetition. (Default: 64, 0 = disabled, -1 = num_ctx)
  repeat_penalty: 1.2 ## Sets how strongly to penalize repetitions. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient. (Default: 1.1)

vectorstore:
  database: qdrant

qdrant:
  path: local_data/private_gpt/qdrant

启动


PGPT_PROFILES=ollama poetry run python -m private_gpt

poetry run python -m private_gpt
02:36:06.928 [INFO    ] private_gpt.settings.settings_loader - Starting application with profiles=['default', 'ollama']
02:36:46.567 [INFO    ] private_gpt.components.llm.llm_component - Initializing the LLM in mode=ollama
02:36:47.405 [INFO    ] private_gpt.components.embedding.embedding_component - Initializing the embedding model in mode=ollama
02:36:47.414 [INFO    ] llama_index.core.indices.loading - Loading all indices.
02:36:47.571 [INFO    ]         private_gpt.ui.ui - Mounting the gradio UI, at path=/
02:36:47.620 [INFO    ]             uvicorn.error - Started server process [72677]
02:36:47.620 [INFO    ]             uvicorn.error - Waiting for application startup.
02:36:47.620 [INFO    ]             uvicorn.error - Application startup complete.
02:36:47.620 [INFO    ]             uvicorn.error - Uvicorn running on http://0.0.0.0:8001 (Press CTRL+C to quit)

image.png

PrivateGPT UI

local 部署模式


#todo: 需要安装llama-cpp,每个平台的安装方式都不同,参考官方文档

poetry run python scripts/setup
PGPT_PROFILES=local poetry run python -m private_gpt

setting-local.yaml

server:
  env_name: ${
   
   APP_ENV:local}

llm:
  mode: llamacpp
  ## Should be matching the selected model
  max_new_tokens: 512
  context_window: 3900
  tokenizer: mistralai/Mistral-7B-Instruct-v0.2

llamacpp:
  prompt_style: "mistral"
  llm_hf_repo_id: TheBloke/Mistral-7B-Instruct-v0.2-GGUF
  llm_hf_model_file: mistral-7b-instruct-v0.2.Q4_K_M.gguf

embedding:
  mode: huggingface

huggingface:
  embedding_hf_model_name: BAAI/bge-small-en-v1.5

vectorstore:
  database: qdrant

qdrant:
  path: local_data/private_gpt/qdrant

非私有 OpenAI-powered 部署

poetry install --extras "ui llms-openai embeddings-openai vector-stores-qdrant"
PGPT_PROFILES=openai poetry run python -m private_gpt

setting-openai.yaml

server:
  env_name: ${
   
   APP_ENV:openai}

llm:
  mode: openai

embedding:
  mode: openai

openai:
  api_key: ${
   
   OPENAI_API_KEY:}
  model: gpt-3.5-turbo

openai 风格的 API 调用

  • The API is built using FastAPI and follows OpenAI's API scheme.
  • The RAG pipeline is based on LlamaIndex.
curl -X POST http://localhost:8000/v1/completions \
     -H "Content-Type: application/json" \
     -d '{
  "prompt": "string",
  "stream": true

}'
相关文章
|
2月前
|
人工智能 自然语言处理 算法
如何利用DeepSeek赋能工作:解锁高效与创新的新路径
在信息爆炸的时代,人工智能(AI)正以前所未有的速度改变工作方式。DeepSeek作为AI领域的新兴力量,通过自然语言处理和大数据分析,助力职场人士提升效率与创新能力。从内容创作到数据分析,再到自动化流程,DeepSeek提供全方位支持。同时,生成式人工智能认证(GAI认证)为个人职业发展赋能,提升竞争力、拓宽道路并促进跨领域合作。DeepSeek与GAI认证相辅相成,共同塑造未来职场新面貌。
|
3月前
|
人工智能
RAG没有银弹!四级难度,最新综述覆盖数据集、解决方案,教你LLM+外部数据的正确使用姿势
在人工智能领域,大型语言模型(LLM)结合外部数据展现出强大能力,尤其检索增强生成(RAG)和微调技术备受关注。然而,不同专业领域的有效部署仍面临挑战,如准确检索数据、理解用户意图等。综述文章《Retrieval Augmented Generation (RAG) and Beyond》提出RAG任务分类方法,将用户查询分为四个级别,并探讨了外部数据集成的三种形式:上下文、小型模型和微调。文章提供了宝贵见解和实用指导,帮助更好地利用LLM潜力解决实际问题。论文链接:https://arxiv.org/abs/2409.14924
134 6
|
6月前
|
人工智能 分布式计算 数据可视化
大模型私有化部署全攻略:硬件需求、数据隐私、可解释性与维护成本挑战及解决方案详解,附示例代码助你轻松实现企业内部AI应用
【10月更文挑战第23天】随着人工智能技术的发展,企业越来越关注大模型的私有化部署。本文详细探讨了硬件资源需求、数据隐私保护、模型可解释性、模型更新和维护等方面的挑战及解决方案,并提供了示例代码,帮助企业高效、安全地实现大模型的内部部署。
1114 2
|
5月前
|
监控 数据可视化 数据挖掘
构建知识共享文化:提升团队整体能力
在数字化时代,企业管理面临新挑战。板栗看板通过可视化管理、数据驱动决策和强化团队协作,帮助企业高效管理资源、优化流程、提升团队合作,成为企业管理者的重要工具。本文探讨其核心价值及应用方法。
|
9月前
|
Web App开发 人工智能 运维
无缝融入,即刻智能[1]:MaxKB知识库问答系统,零编码嵌入第三方业务系统,定制专属智能方案,用户满意度飙升
【8月更文挑战第1天】无缝融入,即刻智能[1]:MaxKB知识库问答系统,零编码嵌入第三方业务系统,定制专属智能方案,用户满意度飙升
无缝融入,即刻智能[1]:MaxKB知识库问答系统,零编码嵌入第三方业务系统,定制专属智能方案,用户满意度飙升
|
10月前
|
API 运维
开发与运维工具问题之开源的大语言模型能够自由与外部工具交互如何解决
开发与运维工具问题之开源的大语言模型能够自由与外部工具交互如何解决
68 2
|
10月前
|
人工智能 领域建模
应用工程化架构问题之AI计算机中的大模型评估体系发生变化如何解决
应用工程化架构问题之AI计算机中的大模型评估体系发生变化如何解决
|
存储 API 数据库
信息系统架构模型
信息系统架构模型
205 1
|
12月前
|
人工智能 文字识别 自然语言处理
准确高效的TextIn文档解析:一项开发痛点的解决方案
企业在构建知识库问答系统时面临挑战,尤其是处理扫描文档和手写内容。传统OCR工具和开源方法在准确性和速度上不足。专业长文档解析成为关键,其中TextIn平台的文档解析服务脱颖而出。该服务能快速将PDF转为Markdown,提高处理速度和准确性,尤其适合处理复杂布局的长文档。通过实际测试,TextIn能有效增强LLM问答系统的性能,解决无法正确解析的问题。目前TextIn处于内测阶段,提供每周7000页的免费试用额度,开发者可通过其官网或“合研社”公众号了解更多信息和获取接口文档。
|
机器学习/深度学习 算法 API
视觉智能平台常见问题之算法私有化部署交付给公司内部运行如何解决
视觉智能平台是利用机器学习和图像处理技术,提供图像识别、视频分析等智能视觉服务的平台;本合集针对该平台在使用中遇到的常见问题进行了收集和解答,以帮助开发者和企业用户在整合和部署视觉智能解决方案时,能够更快地定位问题并找到有效的解决策略。
157 1