人工智能 | 搭建企业内部的大语言模型系统

大纲

开源大语言模型

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

  • 商业大模型,不支持私有部署
    • 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}'

在这里插入图片描述

推荐学习

【霍格沃兹测试开发】7天软件测试快速入门带你从零基础/转行/小白/就业/测试用例设计实战

【霍格沃兹测试开发】最新版!Web 自动化测试从入门到精通/ 电子商务产品实战/Selenium (上集)

【霍格沃兹测试开发】最新版!Web 自动化测试从入门到精通/ 电子商务产品实战/Selenium (下集)

【霍格沃兹测试开发】明星讲师精心打造最新Python 教程软件测试开发从业者必学(上集)

【霍格沃兹测试开发】明星讲师精心打造最新Python 教程软件测试开发从业者必学(下集)

【霍格沃兹测试开发】精品课合集/ 自动化测试/ 性能测试/ 精准测试/ 测试左移/ 测试右移/ 人工智能测试

【霍格沃兹测试开发】腾讯/ 百度/ 阿里/ 字节测试专家技术沙龙分享合集/ 精准化测试/ 流量回放/Diff

【霍格沃兹测试开发】Pytest 用例结构/ 编写规范 / 免费分享

【霍格沃兹测试开发】JMeter 实时性能监控平台/ 数据分析展示系统Grafana/Docker 安装

【霍格沃兹测试开发】接口自动化测试的场景有哪些?为什么要做接口自动化测试?如何一键生成测试报告?

【霍格沃兹测试开发】面试技巧指导/ 测试开发能力评级/1V1 模拟面试实战/ 冲刺年薪百万!

【霍格沃兹测试开发】腾讯软件测试能力评级标准/ 要评级表格的联系我

【霍格沃兹测试开发】Pytest 与Allure2 一键生成测试报告/ 测试用例断言/ 数据驱动/ 参数化

【霍格沃兹测试开发】App 功能测试实战快速入门/adb 常用命令/adb 压力测试

【霍格沃兹测试开发】阿里/ 百度/ 腾讯/ 滴滴/ 字节/ 一线大厂面试真题讲解,卷完拿高薪Offer !

【霍格沃兹测试开发】App自动化测试零基础快速入门/Appium/自动化用例录制/参数配置

【霍格沃兹测试开发】如何用Postman 做接口测试,从入门到实战/ 接口抓包(最新最全教程)


http://www.ppmy.cn/news/1525204.html

相关文章

【LeetCode】:面试题 16.05. 阶乘尾数

🎁个人主页:我们的五年 🔍系列专栏:C课程学习 🎉欢迎大家点赞👍评论📝收藏⭐文章 好久没有写文章了,今天碰见了一道有趣的题目,写下来分享一下。 🏆1.问题描…

【QT】系统-上

欢迎来到Cefler的博客😁 🕌博客主页:折纸花满衣 🏠个人专栏:QT 目录 👉🏻事件QWidget中常见的事件 👉🏻处理鼠标事件:leaveEvent和enterEvent👉&a…

简单代码实现视频转图片_py

目录 1.安装OpenCV 环境要求 安装命令 验证安装 2. OpenCV用法 3.实现程序 博主最近在研究深度学习,需要收集数据集进行处理,但一张张拍照真是太麻烦了 就想着,哎,能不能写一个程序,把视频转成图片不就行了&am…

tabBar设置底部导航栏

如果应用是一个多 tab 应用,可以通过 tabBar 配置项指定一级导航栏,以及 tab 切换时显示的对应页,简单来说就是像美团外卖下面的导航栏一样可以任意切换 1.首先创建三个页面,在页面里面可以写一些东西或者放一张图片方便区分。 2.…

http网络请求与下载进度

Http_request 目录 一、XMLHttpRequest 在使用 Fetch API 进行网络请求时,原生的 Fetch API 并不直接支持获取下载进度的功能,因为 Fetch API 主要是基于 Promise 的,它主要关注于请求的成功或失败,以及响应数据的处理&#xff…

微信小程序开发——比较两个数字大小

在这里我们使用的工具是 需要自行安装和配置。 在微信小程序中比较两个数字大小有以下几种方式: 一、普通条件判断 在小程序的.js 文件中,先定义两个数字,如let num1 5; let num2 3;。通过if - else if - else语句,根据num1与…

MVC设计模式与delegate,tablview,Appdelegate,SceneDelegate

一、MVC MVC就是Model(模型)、View(视图)、Controller(控制器) 例如上面的 excel表, 数据、数据结构就是模型Model 根据数据形成的直观的、用户能直接看见的柱形图是视图View 数据构成的表格…

假期学习-- iOS 通知详解

iOS 通知详解 数据结构 从我们之前使用通知的流程和代码来看,通知其实就是一个单例,方便随时访问。 NSNotificationCenter:消息中心 这个单例类中主要定义了两个表,一个存储所有注册通知信息的表的结构体,一个保存…

模版方法模式template method

学习笔记,原文链接 https://refactoringguru.cn/design-patterns/template-method 超类中定义了一个算法的框架, 允许子类在不修改结构的情况下重写算法的特定步骤。 上层接口有默认实现的方法和子类需要自己实现的方法

神经网络学习笔记——如何设计、实现并训练一个标准的前馈神经网络

1.从零设计并训练一个神经网络https://www.bilibili.com/video/BV134421U77t/?spm_id_from333.337.search-card.all.click&vd_source0b1f472915ac9cb9cdccb8658d6c2e69 一、如何设计、实现并训练一个标准的前馈神经网络,用于手写数字图像的分类,重…

【SpringBoot3】面向切面 AspectJ AOP 使用详解

文章目录 一、AspectJ介绍二、简单使用步骤1、引入依赖2、定义一个Aspect3、开启AOP支持 三、AOP 核心概念四、切点(Pointcut)1. execution2. within3. this & target4. args & args5. within & target & annotation 五、通知&#xff0…

Unix时间戳与C语言的time.h库函数

目录 Unix时间戳介绍 UTC/GMT 时间与秒计数器转换代码 time.h库函数 Unix时间戳介绍 Unix 时间戳(Unix Timestamp)定义为从UTC/GMT的1970年1月1日0时0分0秒开始所经过的秒数,不考虑闰秒 时间戳存储在一个秒计数器中,秒计数器…

15.5 创建监控控制平面的service

本节重点介绍 : k8s中service的作用和类型创建k8s控制平面的service 给prometheus采集用, 类型clusterIp kube-schedulerkube-controller-managerkube-etcd service的作用 Kubernetes Service定义了这样一种抽象: Service是一种可以访问 Pod逻辑分组…

MATLAB求解0-1线性规划问题的详细分析

引言 0-1线性规划是整数规划中的一种特殊形式,它广泛应用于资源分配、工厂选址、投资组合优化、物流运输等多个领域。0-1线性规划的特点是,决策变量只能取0或1的离散值,通常用于描述“是-否”决策问题。随着计算机技术的发展,数学…

《仙境传说RO:新启航》游戏攻略:VMOS云手机提升装备获取辅助!自由交易,辅助挂机操作!

在《仙境传说RO:新启航》中,想要快速提升战斗力并获取顶级装备,玩家需要熟练掌握多种获取资源与提升角色的途径。为了让玩家更加轻松地享受游戏,VMOS云手机推出了专属定制版云手机,内置游戏安装包,不需要重…

【c++实现】统计上升四元组

🌈个人主页:Yui_ 🌈Linux专栏:Linux 🌈C语言笔记专栏:C语言笔记 🌈数据结构专栏:数据结构 🌈C专栏:C 文章目录 1. 题目描述2. 解释3. DP前缀和枚举 1. 题目描…

使用 nvm 管理 node 版本:如何在 macOS 和 Windows 上安装使用nvm

🔥 个人主页:空白诗 文章目录 一、引言二、nvm的安装与基本使用2.1 macOS安装nvm2.1.1 使用 curl 安装2.1.2 使用 Homebrew 安装 2.2 Windows安装nvm2.2.1 下载 nvm-windows2.2.2 安装 nvm-windows 2.3 安装node2.4 切换node版本 三、常见问题及解决方案…

graphQL 参数使用报错问题

query{getMembers(sid:0,nodeId:"ns6;i7896"){methods} } //报错 "message": "Field \"methods\" of type \"[UaMethod]\" must have a selection of subfields. Did you mean \"methods { ... }\"?",这个错误信…

观众登记2025中国(深圳)国际智能手机供应链展览会

时间:2024年4月9-11日 地点:深圳会展中心 ◆展会背景background: 近年来,国内手机品牌在全球市场上的影响力不断增强,华为、OPPO、VIVO和小米等…

实战案例(2)防火墙+二交换机VLAN组网

案例二:防火墙充当三层交换机与路由器角色功能进行组网 拿到这样的拓扑后,首先要了解好客户的需求,然后根据需求进行划分 比如客户那边有监控跟办公网络,可以通过VLAN划分不同的区域,然后二层交换机对接终端的口划入到…