首页 > 其他分享 >搭建企业内部的大语言模型系统

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

时间:2024-09-10 16:13:28浏览次数:1  
标签:语言 模型 poetry private openai gpt model ollama 搭建

大纲

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

开源大语言模型

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

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

大语言模型的前端

大语言模型的应用前端

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

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

}'

标签:语言,模型,poetry,private,openai,gpt,model,ollama,搭建
From: https://www.cnblogs.com/hogwarts/p/18406632

相关文章

  • pydantic 和 sqlalchemy 之间的模型转换
    字段dict#Assuming`session`isyourSQLAlchemysessionuser_instance=session.query(User).first()#ConverttoPydanticmodeldapter=TypeAdapter(User,UserPydantic)user_pydantic=adapter.to_pydantic(user_instance)#也可以UserPydantic.model_validate......
  • Llama Factory :百种以上语言模型的统一高效微调框架
    人工智能咨询培训老师叶梓转载标明出处大模型适应到特定下游任务时,传统的全参数微调方法成本高昂,因此,研究者们一直在探索更高效的微调技术。由北京航空航天大学和北京大学的研究团队提出了一个名为LlamaFactory的统一框架,旨在解决大模型高效微调的问题。该框架整合了一系列......
  • C语言程序设计——数组(二)
    一、字符数组1.1字符数组的定义定义方法与数组(一)介绍的类似。用来存放字符数据的数组是字符数组。字符数组中的一个元素存放一个字符。1.2字符数组的初始化对字符数组初始化,最容易理解的方式是逐个字符赋给数组中各元素。注:①如果在定义字符数组时不进行初始化,则数组中各......
  • C语言程序设计(循环控制)
    一、概述在许多问题中需要用到循环控制。循环结构是结构化程序设计的基本结构之一,它和顺序结构、选择结构共同作为各种复杂程序的基本构造单元。二、goto语句以及用goto语句构成循环goto语句为无条件转向语句,它的一般形式为goto语句标号;语句标号用标识符表示,它的定名规......
  • 【Py/Java/C++三种语言OD独家2024E卷真题】20天拿下华为OD笔试之【回溯】2024E-字符串
    可上欧弟OJ系统练习华子OD、大厂真题绿色聊天软件戳od1441了解算法冲刺训练(备注【CSDN】否则不通过)文章目录相关推荐阅读题目描述与示例题目描述输入描述输出描述示例一输入输出说明示例二输入输出说明解题思路代码pythonjavacpp时空复杂度华为OD算法/大厂面......
  • 【大模型-RAG】RAG最佳实践论文及项目解读
    文章目录论文概述RAG工作流程核心代码解读软件架构查询引擎构建数据加载与索引创建微调嵌入模型项目应用结论在人工智能领域,大型语言模型(LLMs)因其强大的文本生成能力而备受关注。然而,这些模型在生成信息时可能会产生过时的信息或编造事实。为了解决这一问题,检索增强生成(Retrieva......
  • LG AI 研究中心开源 EXAONEPath:通过285M Patch级预训练模型变革组织病理学图像分析,实
    基于LGAIResearch在AI语言模型方面的显著成就,特别是推出EXAONE3.0之后,EXAONEPath的开发代表了另一个重要的里程碑。这标志着EXAONE在数字病理学这一关键医学诊断领域的一次重大转型,通过解决全幻灯片图像(WSI)在病理学中的复杂挑战以及提高病理图像处理效率,EXAONEPath广泛应用......
  • timm库中最强的各类模型,图像分类
    vit_base_patch16_224链接:https://huggingface.co/timmtimmTop-20ImageNet-1kModelstimm/eva02_large_patch14_448.mim_m38m_ft_in22k_in1k  ......
  • AI模型对制造型企业的财务工作有哪些帮助?
    AI模型对制造型企业的财务工作影响根据本人对AI模型的理解,还有自身多年财务工作的经历,这两者之间能否做一些融合和关联,结合相关文献,大概有以下几点浅见:数据处理与分析方面自动化数据录入利用光学字符识别(OCR)技术结合AI算法,将纸质财务票据(如发票、收据、采购单等)快速准......
  • 【程序员指南】如何挑选合适的AI模型解决各类问题?
    在AI技术日新月异的今天,程序员需要不断了解和掌握这些技术,以便更高效地解决问题。本文将深入探讨几种主流的AI模型,包括GPT-4o-mini、GPT-3.5、GPT-4、GPT4o、Claude-3.5-Sonnet、GeminiPro、以及针对中文场景优化的月之暗面和文心一言4.0,还有知识库丰富的通义千问Plus。我......