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

news/2024/9/19 15:37:56/文章来源:https://www.cnblogs.com/hogwarts/p/18406632

大纲

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

开源大语言模型

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

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

常用开源大模型列表

开源大模型分支

大语言模型管理

大语言模型管理工具

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

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

Ollama 的命令

ollama pull llama2
ollama list
ollama run llama2 "Summarize this file: $(cat README.md)"ollama servecurl 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?" }]
}'

大语言模型的前端

大语言模型的应用前端

  • 开源平台 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

ollama chatbot

PrivateGPT

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

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: ollamamax_new_tokens: 512context_window: 3900temperature: 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: ollamaollama:llm_model: mistralembedding_model: nomic-embed-textapi_base: http://localhost:11434tfs_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: qdrantqdrant:path: local_data/private_gpt/qdrant

启动


PGPT_PROFILES=ollama poetry run python -m private_gptpoetry 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)

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 modelmax_new_tokens: 512context_window: 3900tokenizer: mistralai/Mistral-7B-Instruct-v0.2llamacpp:prompt_style: "mistral"llm_hf_repo_id: TheBloke/Mistral-7B-Instruct-v0.2-GGUFllm_hf_model_file: mistral-7b-instruct-v0.2.Q4_K_M.ggufembedding:mode: huggingfacehuggingface:embedding_hf_model_name: BAAI/bge-small-en-v1.5vectorstore:database: qdrantqdrant: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: openaiembedding:mode: openaiopenai: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}'

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/795009.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

115. 不同的子序列(leetcode)

https://leetcode.cn/problems/distinct-subsequences/submissions/563375885/ 这题比较有难度,具体不太好想到,需要以是否选择s[i]来划分子集这位描述的很清楚,不做过多赘述 class Solution {public int numDistinct(String s, String t) {// f[i][j]表示s中前i个字符中选择,有…

0.1+0.2 != 0.3 (Java为例)

1. 小数的二进制表示 以10.625为例。整数部分进行除2取余的操作,10的二进制为1010。小数部分进行乘2取整操作,直到小数部分为0或达到需要的精度:0.625*2=1.25 取整数1,小数部分0.25继续计算 0.25*2=0.5 取整数0,小数部分0.5继续计算 0.5*2=1.0 取整数1,小数部分为0,停止…

信创领域认证,来自工信部人才交流中心的PostgreSQL培训班

在国家大力发展信创软件和数据库行业的背景下,PostgreSQL 具有多方面的优势和机遇,具体体现在以下几个方面: 1. 技术优势契合信创需求: PostgreSQL 数据库是一个功能强大、性能稳定、可扩展性强的开源对象关系数据库系统,支持多种数据类型(如数组、JSON、XML 等),方便存储…

Salesforce职业规划:原厂,甲方,乙方,从业者应该如何选择?

Salesforce生态系统蓬勃发展,对不同角色的需求量不断增加。需求方包括使用Salesforce的最终用户(甲方)、实施Salesforce的咨询公司、为Salesforce创建应用程序的AppExchange公司(或ISV),当然还有Salesforce原厂。 Salesforce最终用户(甲方) 2020年,Salesforce的客户数…

3SRB5016-ASEMI三相整流桥3SRB5016

3SRB5016-ASEMI三相整流桥3SRB5016编辑:ll 3SRB5016-ASEMI三相整流桥3SRB5016 型号:3SRB5016 品牌:ASEMI 封装:3SRB-5 批号:2024+ 现货:50000+ 最大重复峰值反向电压:1600V 最大正向平均整流电流(Vdss):50A 功率(Pd):大功率 芯片个数:5 引脚数量:5 安装方式:直插 类…

34-样式迁移

类似于加了一层滤镜基于CNN的样式迁移:如下对于合成图片X,我们希望它的内容和输入的内容图片,放入同一个CNN,在某一个卷积层上,输出的与内容有关的特征能够匹配 同时,,对于样式图片,我们希望合成图片X,和样式图片放入同一个CNN,在某一个卷积层上,输出的与样式有关的…

STM32-ADC外设

1.通道 .规则通道 .注入通道 2.规则序列寄存器 配置通道的采样顺序 3.ADC周期4.ADC转换方式 *单次转换:adc每次只采集某个通道的一个点,如果需要再次采集,就需要重新使能。 *连续转换:adc采集某个通道一个点,转换完成后,再采集第二点。依次类推 4.扫描模式 *单次扫描模式…

SignalR跨域问题解决

本文来自博客园,作者:WantRemake,转载请注明原文链接:https://www.cnblogs.com/SmallChen/p/18406437

字符串类

常用类String基础知识String类的特性String类是一个final类,不能被继承 String类底层是一个final修饰的字符数组,表示不可变的字符序列(final char value[ ]) String的不可变性:当String值改变时,会在常量池中创建新的字符串字符串-创建字面量方式创建 String s1="a…

AI答案之书解来为你解决难题

本文由 ChatMoney团队出品介绍说明 “答案之书智能体”是您贴心的智慧伙伴,随时准备为您解答生活中的种种困惑。无论您在工作中遭遇瓶颈,还是在情感世界里迷失方向,亦或是对个人成长感到迷茫,它都能倾听您的心声,并给予准确且富有启发的回应。 它并非简单地给出答案,而是…

解锁生活密码,AI答案之书解决复杂难题

本文由 ChatMoney团队出品介绍说明 “答案之书智能体”是您贴心的智慧伙伴,随时准备为您解答生活中的种种困惑。无论您在工作中遭遇瓶颈,还是在情感世界里迷失方向,亦或是对个人成长感到迷茫,它都能倾听您的心声,并给予准确且富有启发的回应。 它并非简单地给出答案,而是…

STM32F7外设FMC控制LCD显示屏

STM32F7外设FMC控制LCD显示屏, 显示屏的点阵LCD控制器(Dot Matrix LCD Controller/Driver)是ST7066U。 配置 在CubeMX中选择图 1 根据实际情况选择,Bank几,LCD片选引脚。图 2 FMC原理 对于FMC如何控制LCD,我的理解: FMC能自动发送数据读写RAM,通过FMC读写LCD的显存就可以…