Ollama私有化部署大语言模型LLM
目录
一、Ollama介绍
二、安装Ollama
1、标准安装
2、国内加速
三、升级Ollama版本
四、使用Ollama
1、启动ollama服务
systemctl start ollama.service
ollama serve
2、使用ollama命令
ollama run 运行模型
ollama ps 查看正在运行的模型
ollama list 查看(本地)已保存的模型
ollama show 查看(本地)已保存模型简要信息
五、通过http访问Ollama
1、列出本地已有的模型
2、列出本正在运行的模型
3、获取指定模型详情
4、模型推理(生成内容)
generate接口
chat接口
5、可复现回答
6、覆盖默认的system指令
7、携带上下文
8、删除模型
五、查看Ollama服务日志
附、Ollama拉取Huggingface上的模型
一、Ollama介绍
Ollama(官方网址:https://ollama.com/)是一个开源的大型语言模型(LLM)服务工具,旨在简化在本地环境中部署和运行这些模型的过程。它支持多种操作系统,包括Windows、macOS和Linux,并且可以通过Docker容器进行管理。Ollama封装了llama.cpp库,并提供与OpenAI兼容的API,支持多种语言模型如Llama 3、Mistral和Gemma。此外,Ollama还支持并行请求和多线程操作,提高了效率。用户可以通过简单的命令行工具或Web界面(Open WebUI、Hollama等)来管理和运行模型。Ollama采用了docker技术以实现简化使用,所以使用ollama命令风格类似docker。
同时,Ollama提供了官方的模型registry中心(网站:https://www.ollama.com/models),上面是官方提供的模型列表(其地位类似于docker的DockerHub)。
Ollama的特点:
- 本地推理:
有无GPU均可:即使无GPU,仅CPU也能让开源模型(如 LLaMA、GPT-Neo、Mistral 等)跑起来。还可GPU+CPU混合:若自动检测到机器上存在GPU(NVIDIA或者AMD),自动同时GPU+CPU,充分发挥两者的能力。
- 轻量易用:
安装方式简洁,一键下载安装。只需一个命令行工具就能在本地完成私有化部署,一键就能自动下载运行模型并进行对话、推理。
- 量化优化:
支持对常见大语言模型做 4-bit 或 8-bit 等量化Quantization,通过量化进一步降低硬件资源占用。
- 发展活跃:
在 GitHub 上有不错的社区支持和更新节奏,适合初中级开发者快速上手。
二、安装Ollama
1、标准安装
本文以Linux为例,如下图官网,通过一行命令一键完成Linux上完成安装。该句命令的作用是:通过curl从网上获取install.sh并输出至stdout(不将该install.sh保存至本地文件),然后通过sh执行。
除了一键安装,还可以通过下方的“View script source”查看install.sh的内容。可以通过“Manual install instructions”将install.sh中的各步骤通过手工一步步执行,而不是一键完成安装。
注意:需具有sudo权限的普通用户或者root用户执行安装命令。
安装目标目录的基目录为“/usr/local/” 或 “/usr/” 或 “/” 目录下(具体看安装时提示),在基目录下的:
- bin/ollama文件,为可执行文件
- lib/ollama子目录,为所需的lib库。
一键安装会自动:创建一个ollama用户,还会自动纳入Linux服务管理以随Linux启动而启动;若存在Nvidia GPU硬件则还会安装CUDA等。
若在安装Ollama过程中报“systemctl相关错误”, 或者在执行systemctl命令时报“System has not been booted with systemd as init system (PID 1). Can't operate.Failed to connect to bus: Host is down”,则需要先在Linux安装system和systemctl,以Ubuntu为例安装命令如下:
apt-get install systemd -y
apt-get install systemctl -y
2、国内加速
在标准安装的install.sh中,会自动根据当前Linux平台通过“https://ollama.com/download/文件名”下载安装所需的tgz文件(该URL实际最终会通过“https://github.com/ollama/ollama/releases/latest/download/文件名”下载),所需下载的tgz文件大约1~2GB。
然而国内访问github速度通常几百KB/s比较慢,可以通过文件加速器网站下载。下面以加速器网站“https://github.xzc888.top”为例加速(也可使用其他加速器网站),使用该加速器网站的方法是将URL中的“github.com”替换为“github.xzc888.top”。具体安装ollama过程如下:
#将脚本下载,并保存至本地。保存的文件名为“install_ollama.sh”
curl -fsSL https://ollama.com/install.sh -o install_ollama.sh#将该文件中的下载URL前缀替换为加速后的URL前缀
sed -i 's#https://ollama.com/download/#https://github.xzc888.top/ollama/ollama/releases/latest/download/#g' install_ollama.sh#执行ollama安装
sh install_ollama.sh#最后删除临时sh脚本
rm install_ollama.sh
三、升级Ollama版本
若Linux中已经安装ollama,希望升级新版ollama软件,怎么办?
只需再次执行以上安装步骤即可使用新版覆盖已有的老版。
四、使用Ollama
类似docker,安装完ollama后需要先启动ollama服务端,然后才能通过命令操作。
1、启动ollama服务
启动ollama服务(服务端)可以通过:
-
systemctl start ollama.service
通过Linux服务启动,该启动将会使用ollama用户运行进程。该方式启动默认使用/usr/share/ollama/.ollama/models目录作为存放模型的目录。
另:ollama服务通过OLLAMA_HOST环境确定服务侦听,该环境变量默认为127.0.0.1:11434,所以只能供本机访问,同时设置OLLAMA_ORIGINS避免通过浏览器访问时报CORS跨域问题。
为了让其他机器访问也能访问ollama服务。编辑vim /etc/systemd/system/ollama.service
文件,对Environment增加设置OLLAMA_HOST和OLLAMA_ORIGINS环境变量,如下
然后执行:systemctl daemon-reload; systemctl restart ollama.service 使其生效。
-
ollama serve
直接通过ollama命令启动,该启动方式默认使用启动命令用户的~/.ollama/models目录作为存放模型的目录。
附:ollama服务通过OLLAMA_HOST环境确定服务侦听,该环境变量默认为127.0.0.1:11434,所以只能供本机访问。为了让其他机器访问也能访问ollama服务。先在Linux中设置环境变量export OLLAMA_HOST=0.0.0.0:11434,然后再启动ollama服务。
2、使用ollama命令
除了ollama serve命令为服务端命令外,其他命令为ollama客户端命令。如下为客户端命令(每个命令有对应的环境变量,具体通过命令加--help查看)。
客户端命令通过OLLAMA_HOST环境变量指定ollama服务所在的IP和端口,该环境变量默认为127.0.0.1:11434,可在使用时修改环境变量。
- create Create a model from a Modelfile
- show Show information for a model
- run Run a model
- stop Stop a running model
- pull Pull a model from a registry
- push Push a model to a registry
- list List models
- ps List running models
- cp Copy a model
- rm Remove a model
ollama run 运行模型
使用以下命令运行模型(若本地没有该模型,则自动从ollama官网获取)。
注意:这里的运行应当更准确理解为:加载模型至内存或显存。因为只有Ollama服务才涉及启动运行,模型不涉及启动运行,模型只是被Ollama服务加载,加载后即可由Ollama服务对外提供。
#运行模型(若本地没有该模型,则自动从ollama官网获取)
ollama run qwen2.5-coder
运行后,自动进入输入prompt对话框。如下:
还可以通过斜杠命令(slash command),设置显示verbose(应答耗时、消耗token、token速度等信息)、设置应答格式、查看模型信息、查看预设system提示词、查看预设提示词模版等等。如下:
其中/bye只是结束当前对话,不代表模型退出加载。
通过斜杠命令(slash command),还可以改变预设的system提示词。如下:
ollama ps 查看正在运行的模型
注意,输出内容中:
- PROCESSOR 不是指消耗CPU比例。100% CPU表示模型全部加载至内存;100% GPU表示模型全部加载至CPU显存;48%/52% CPU/GPU表示模型分别按比例加载至内存和显存。这个Ollama使用的词不准确,应该用MEM和GMEM就比较准确。
- UNTIL 表示模型还剩多长时间就退出加载,既还剩多长时间从内存或显存中卸载该模型。时长可通过OLLAMA_KEEP_ALIVE环境变量,或者通过API接口的keep_alive参数动态改变。具体见官网说明
:
https://github.com/ollama/ollama/blob/main/docs/faq.md
ollama list 查看(本地)已保存的模型
ollama show 查看(本地)已保存模型简要信息
包括模型基本信息、system提示词、License等
五、通过http访问Ollama
ollama服务端提供多个http接口供访问,通过http访问服务端使用各个大模型功能。注意提供http的不是大模型,而是ollama服务端(默认的11434端口是ollama服务的端口,不是模型的端口,模型也不存在端口)。所以通过http不仅能选择使用大模型,而且还可以创建、查看、删除模型
下面以curl工具进行演示。
1、列出本地已有的模型
curl http://localhost:11434/api/tags
返回结果(已经格式化排版)如下:
{"models": [{"name": "qwen2.5-coder:latest","model": "qwen2.5-coder:latest","modified_at": "2025-01-09T08:43:12.893109668+08:00","size": 4683087519,"digest": "2b0496514337a3d5901f1d253d01726c890b721e891335a56d6e08cedf3e2cb0","details": {"parent_model": "","format": "gguf","family": "qwen2","families": ["qwen2"],"parameter_size": "7.6B","quantization_level": "Q4_K_M"}}, {"name": "qwen2.5-coder:0.5b","model": "qwen2.5-coder:0.5b","modified_at": "2025-01-08T19:32:09.640283014+08:00","size": 531081760,"digest": "d392ed348d5bb7847eaefe3fcb18e5bcc6433aecb68bf61b6e028d87292ab54f","details": {"parent_model": "","format": "gguf","family": "qwen2","families": ["qwen2"],"parameter_size": "494.03M","quantization_level": "Q8_0"}}]
}
2、列出本正在运行的模型
curl http://localhost:11434/api/ps
返回结果(已经格式化排版)如下:
{"models": [{"name": "qwen2.5-coder:0.5b","model": "qwen2.5-coder:0.5b","size": 958830592,"digest": "d392ed348d5bb7847eaefe3fcb18e5bcc6433aecb68bf61b6e028d87292ab54f","details": {"parent_model": "","format": "gguf","family": "qwen2","families": ["qwen2"],"parameter_size": "494.03M","quantization_level": "Q8_0"},"expires_at": "2025-01-09T14:31:47.581505612+08:00","size_vram": 0}]
}
3、获取指定模型详情
curl -X POST http://localhost:11434/api/show -d '{"name": "qwen2.5-coder:0.5b","verbose": false
}'
返回结果(已经格式化排版)如下(如果开启verbose信息会更多)
{"license": "\n Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright 2024 Alibaba Cloud\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.","modelfile": "# Modelfile generated by \"ollama show\"\n# To build a new Modelfile based on this, replace FROM with:\n# FROM qwen2.5-coder:0.5b\n\nFROM /usr/share/ollama/.ollama/models/blobs/sha256-828125e28bf46a219fa4f75b6982cb0c41fd9187467abe91c9b175287945b7ef\nTEMPLATE \"\"\"{{- if .Suffix }}\u003c|fim_prefix|\u003e{{ .Prompt }}\u003c|fim_suffix|\u003e{{ .Suffix }}\u003c|fim_middle|\u003e\n{{- else if .Messages }}\n{{- if or .System .Tools }}\u003c|im_start|\u003esystem\n{{- if .System }}\n{{ .System }}\n{{- end }}\n{{- if .Tools }}\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within \u003ctools\u003e\u003c/tools\u003e XML tags:\n\u003ctools\u003e\n{{- range .Tools }}\n{\"type\": \"function\", \"function\": {{ .Function }}}\n{{- end }}\n\u003c/tools\u003e\n\nFor each function call, return a json object with function name and arguments within \u003ctool_call\u003e\u003c/tool_call\u003e XML tags:\n\u003ctool_call\u003e\n{\"name\": \u003cfunction-name\u003e, \"arguments\": \u003cargs-json-object\u003e}\n\u003c/tool_call\u003e\n{{- end }}\u003c|im_end|\u003e\n{{ end }}\n{{- range $i, $_ := .Messages }}\n{{- $last := eq (len (slice $.Messages $i)) 1 -}}\n{{- if eq .Role \"user\" }}\u003c|im_start|\u003euser\n{{ .Content }}\u003c|im_end|\u003e\n{{ else if eq .Role \"assistant\" }}\u003c|im_start|\u003eassistant\n{{ if .Content }}{{ .Content }}\n{{- else if .ToolCalls }}\u003ctool_call\u003e\n{{ range .ToolCalls }}{\"name\": \"{{ .Function.Name }}\", \"arguments\": {{ .Function.Arguments }}}\n{{ end }}\u003c/tool_call\u003e\n{{- end }}{{ if not $last }}\u003c|im_end|\u003e\n{{ end }}\n{{- else if eq .Role \"tool\" }}\u003c|im_start|\u003euser\n\u003ctool_response\u003e\n{{ .Content }}\n\u003c/tool_response\u003e\u003c|im_end|\u003e\n{{ end }}\n{{- if and (ne .Role \"assistant\") $last }}\u003c|im_start|\u003eassistant\n{{ end }}\n{{- end }}\n{{- else }}\n{{- if .System }}\u003c|im_start|\u003esystem\n{{ .System }}\u003c|im_end|\u003e\n{{ end }}{{ if .Prompt }}\u003c|im_start|\u003euser\n{{ .Prompt }}\u003c|im_end|\u003e\n{{ end }}\u003c|im_start|\u003eassistant\n{{ end }}{{ .Response }}{{ if .Response }}\u003c|im_end|\u003e{{ end }}\"\"\"\nSYSTEM You are Qwen, created by Alibaba Cloud. You are a helpful assistant.\nLICENSE \"\"\"\n Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright 2024 Alibaba Cloud\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\"\"\"\n","template": "{{- if .Suffix }}\u003c|fim_prefix|\u003e{{ .Prompt }}\u003c|fim_suffix|\u003e{{ .Suffix }}\u003c|fim_middle|\u003e\n{{- else if .Messages }}\n{{- if or .System .Tools }}\u003c|im_start|\u003esystem\n{{- if .System }}\n{{ .System }}\n{{- end }}\n{{- if .Tools }}\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within \u003ctools\u003e\u003c/tools\u003e XML tags:\n\u003ctools\u003e\n{{- range .Tools }}\n{\"type\": \"function\", \"function\": {{ .Function }}}\n{{- end }}\n\u003c/tools\u003e\n\nFor each function call, return a json object with function name and arguments within \u003ctool_call\u003e\u003c/tool_call\u003e XML tags:\n\u003ctool_call\u003e\n{\"name\": \u003cfunction-name\u003e, \"arguments\": \u003cargs-json-object\u003e}\n\u003c/tool_call\u003e\n{{- end }}\u003c|im_end|\u003e\n{{ end }}\n{{- range $i, $_ := .Messages }}\n{{- $last := eq (len (slice $.Messages $i)) 1 -}}\n{{- if eq .Role \"user\" }}\u003c|im_start|\u003euser\n{{ .Content }}\u003c|im_end|\u003e\n{{ else if eq .Role \"assistant\" }}\u003c|im_start|\u003eassistant\n{{ if .Content }}{{ .Content }}\n{{- else if .ToolCalls }}\u003ctool_call\u003e\n{{ range .ToolCalls }}{\"name\": \"{{ .Function.Name }}\", \"arguments\": {{ .Function.Arguments }}}\n{{ end }}\u003c/tool_call\u003e\n{{- end }}{{ if not $last }}\u003c|im_end|\u003e\n{{ end }}\n{{- else if eq .Role \"tool\" }}\u003c|im_start|\u003euser\n\u003ctool_response\u003e\n{{ .Content }}\n\u003c/tool_response\u003e\u003c|im_end|\u003e\n{{ end }}\n{{- if and (ne .Role \"assistant\") $last }}\u003c|im_start|\u003eassistant\n{{ end }}\n{{- end }}\n{{- else }}\n{{- if .System }}\u003c|im_start|\u003esystem\n{{ .System }}\u003c|im_end|\u003e\n{{ end }}{{ if .Prompt }}\u003c|im_start|\u003euser\n{{ .Prompt }}\u003c|im_end|\u003e\n{{ end }}\u003c|im_start|\u003eassistant\n{{ end }}{{ .Response }}{{ if .Response }}\u003c|im_end|\u003e{{ end }}","system": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant.","details": {"parent_model": "","format": "gguf","family": "qwen2","families": ["qwen2"],"parameter_size": "494.03M","quantization_level": "Q8_0"},"model_info": {"general.architecture": "qwen2","general.base_model.0.name": "Qwen2.5 Coder 0.5B","general.base_model.0.organization": "Qwen","general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B","general.base_model.count": 1,"general.basename": "Qwen2.5-Coder","general.file_type": 7,"general.finetune": "Instruct","general.languages": ["en"],"general.license": "apache-2.0","general.license.link": "https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B-Instruct/blob/main/LICENSE","general.parameter_count": 494032768,"general.quantization_version": 2,"general.size_label": "0.5B","general.tags": ["code", "codeqwen", "chat", "qwen", "qwen-coder", "text-generation"],"general.type": "model","qwen2.attention.head_count": 14,"qwen2.attention.head_count_kv": 2,"qwen2.attention.layer_norm_rms_epsilon": 0.000001,"qwen2.block_count": 24,"qwen2.context_length": 32768,"qwen2.embedding_length": 896,"qwen2.feed_forward_length": 4864,"qwen2.rope.freq_base": 1000000,"tokenizer.ggml.add_bos_token": false,"tokenizer.ggml.bos_token_id": 151643,"tokenizer.ggml.eos_token_id": 151645,"tokenizer.ggml.merges": null,"tokenizer.ggml.model": "gpt2","tokenizer.ggml.padding_token_id": 151643,"tokenizer.ggml.pre": "qwen2","tokenizer.ggml.token_type": null,"tokenizer.ggml.tokens": null},"modified_at": "2025-01-08T19:32:09.640283014+08:00"
}
4、模型推理(生成内容)
ollama中的原生模型推理(不含OpenAI兼容)方式通过两个接口实现:
- 一个是 /api/generate
- 一个是 /api/chat
两者区别在于,前者generate适合生成单个文本片段。它接收输入并返回基于该输入的模型生成的文本,通常不考虑之前的消息历史或对话上下文。其中每次请求都是独立的,不依赖于前一次请求的结果。更适合一次性生成任务。 后者chat支持对话式的交互,它通常需要一个消息列表作为输入,以维护对话的历史和上下文,确保模型能够理解并响应连续的对话,它适合于创建聊天机器人、问答系统或任何需要多轮对话的应用场景。通过跟踪对话历史,模型可以提供更加连贯和情境相关的响应。分别演示如下:
generate接口
curl -X POST http://localhost:11434/api/generate -d '{"model": "qwen2.5-coder:0.5b","prompt": "你是谁?","stream": false
}'
generate返回结果(已经格式化排版)如下:
{"model": "qwen2.5-coder:0.5b","created_at": "2025-01-09T06:25:24.240792825Z","response": "我是Qwen,由阿里云开发的AI助手,专注于理解和生成文本。","done": true,"done_reason": "stop","context": [151644, 8948, 198, 2610, 525, 1207, 16948, 11, 3465, 553, 54364, 14817, 13, 1446, 525, 264, 10950, 17847, 13, 151645, 198, 151644, 872, 198, 105043, 100165, 30, 151645, 198, 151644, 77091, 198, 104198, 48, 16948, 3837, 67071, 102661, 99718, 100013, 9370, 15469, 110498, 3837, 107782, 115167, 43959, 108704, 1773],"total_duration": 857877710,"load_duration": 14625325,"prompt_eval_count": 32,"prompt_eval_duration": 175000000,"eval_count": 18,"eval_duration": 665000000
}
chat接口
curl -X POST http://localhost:11434/api/chat -d '{"model": "qwen2.5-coder:0.5b","messages": [{"role": "user","content": "你是谁?"}],"stream": false
}'
chat返回结果(已经格式化排版)如下:
{"model": "qwen2.5-coder:0.5b","created_at": "2025-01-09T06:38:41.195407315Z","message": {"role": "assistant","content": "我是由阿里云研发的人工智能助手Qwen。"},"done_reason": "stop","done": true,"total_duration": 508747638,"load_duration": 20794125,"prompt_eval_count": 32,"prompt_eval_duration": 32000000,"eval_count": 13,"eval_duration": 447000000
}
5、可复现回答
通常模型对于同样的问题,每次回答的内容是不同的。可以通过下面指定相同options使相同的问题每次回答内容相同,实现可复现。
curl -X POST http://localhost:11434/api/chat -d '{"model": "qwen2.5-coder:0.5b","messages": [{"role": "user","content": "你是谁?"}],"stream": false,"options": {"seed": 101,"temperature": 0.5,"top_p":0.85,"top_k":20}
}'
返回结果(已经格式化排版)如下
{"model": "qwen2.5-coder:0.5b","created_at": "2025-01-09T07:07:21.330267763Z","message": {"role": "assistant","content": "我是阿里云自主研发的人工智能助手,旨在帮助用户解决问题和获取信息。如果您有任何问题或需要帮助,请随时告诉我!"},"done_reason": "stop","done": true,"total_duration": 950157406,"load_duration": 14133236,"prompt_eval_count": 32,"prompt_eval_duration": 41000000,"eval_count": 28,"eval_duration": 886000000
}
6、覆盖默认的system指令
curl -X POST http://localhost:11434/api/chat -d '{"model": "qwen2.5-coder:0.5b","messages": [{"role": "system","content": "You are a warm-hearted biochemist and from Australia."},{"role": "user","content": "你是谁?"}],"stream": false
}'
返回结果(已经格式化排版)如下
{"model": "qwen2.5-coder:0.5b","created_at": "2025-01-09T06:46:04.627016664Z","message": {"role": "assistant","content": "我是来自澳大利亚的生物chemist,我的专业领域是微生物学和免疫学。"},"done_reason": "stop","done": true,"total_duration": 580484699,"load_duration": 15906548,"prompt_eval_count": 27,"prompt_eval_duration": 35000000,"eval_count": 18,"eval_duration": 520000000
}
7、携带上下文
第一轮对话
curl -X POST http://localhost:11434/api/chat -d '{"model": "qwen2.5-coder:0.5b","messages": [{"role": "system","content": "You are a warm-hearted doctor, and you only speak Chinese."},{"role": "user","content": "李华在公园时不小心把腿摔断了,已经去医院治疗,一般要多长时间能恢复?"}],"stream": false
}'
第一轮返回结果(已经格式化排版)如下
{"model": "qwen2.5-coder:0.5b","created_at": "2025-01-09T06:56:07.051752359Z","message": {"role": "assistant","content": "恢复时间因人而异。通常情况下,腿部受伤后1-2周内是恢复的最佳时期。具体恢复时间取决于患者的个人情况、病情严重程度以及医生的建议。\n\n以下是一些一般性的时间表:\n\n1. **轻度损伤**:如果膝盖和踝部没有明显损坏,可能只需要一周。\n2. **中重度损伤**:如果膝盖和踝部的磨损严重,或者有明显的疼痛或不适,可能需要更长时间。\n\n如果情况较复杂,可能需要进一步检查以确定问题的具体性质,并根据医生的建议进行治疗。最重要的是保持积极的心态,及时就医以获得专业的帮助。"},"done_reason": "stop","done": true,"total_duration": 4360104102,"load_duration": 16847719,"prompt_eval_count": 49,"prompt_eval_duration": 80000000,"eval_count": 133,"eval_duration": 4254000000
}
第二轮对话
curl -X POST http://localhost:11434/api/chat -d '{"model": "qwen2.5-coder:0.5b","messages": [{"role": "system","content": "You are a warm-hearted assistant, and you only speak Chinese."},{"role": "user","content": "李华在公园时不小心把腿摔断了,已经去医院治疗,一般要多长时间能恢复?"},{"role": "assistant","content": "恢复时间因人而异。通常情况下,腿部受伤后1-2周内是恢复的最佳时期。具体恢复时间取决于患者的个人情况、病情严重程度以及医生的建议。\n\n以下是一些一般性的时间表:\n\n1. **轻度损伤**:如果膝盖和踝部没有明显损坏,可能只需要一周。\n2. **中重度损伤**:如果膝盖和踝部的磨损严重,或者有明显的疼痛或不适,可能需要更长时间。\n\n如果情况较复杂,可能需要进一步检查以确定问题的具体性质,并根据医生的建议进行治疗。最重要的是保持积极的心态,及时就医以获得专业的帮助。"},{"role": "user","content": "李华因为什么要去医院?"}],"stream": false
}'
第二轮返回结果(已经格式化排版)如下
{"model": "qwen2.5-coder:0.5b","created_at": "2025-01-09T06:59:23.493656678Z","message": {"role": "assistant","content": "李华因腿摔断了前往医院治疗。"},"done_reason": "stop","done": true,"total_duration": 486334504,"load_duration": 16855321,"prompt_eval_count": 198,"prompt_eval_duration": 84000000,"eval_count": 12,"eval_duration": 346000000
}
8、删除模型
curl -X DELETE http://localhost:11434/api/delete -d '{"name": "qwen2.5-coder:0.5b"}'
返回结果无报错则表示删除成功。
五、查看Ollama服务日志
在Linux上,可以通过以下命令查看ollama服务的日志:
# -u指定服务,--no-pager不分页,-f实时刷日志
sudo journalctl -u ollama.service --no-pager
附、Ollama拉取Huggingface上的模型
除了使用Ollama官网提供的模型外,还可以使用上的GGUF格式的模型。具体见官网https://huggingface.co/docs/hub/ollama介绍:
使用方法:在官网上找到支持GGUF格式的模型,如下图,按提示选择支持Ollama部署:
根据Huggingface界面提示,在Ollama本地运行,命令格式为:
#从Huggingface获取并运行的命令格式。若不指定quantization则默认为:Q4_K_M
ollama run hf.co/{username}/{repository}:{quantization}#例如:
ollama run hf.co/lmstudio-community/phi-4-GGUF:Q4_K_M
相关文章:
Ollama私有化部署大语言模型LLM
目录 一、Ollama介绍 二、安装Ollama 1、标准安装 2、国内加速 三、升级Ollama版本 四、使用Ollama 1、启动ollama服务 systemctl start ollama.service ollama serve 2、使用ollama命令 ollama run 运行模型 ollama ps 查看正在运行的模型 ollama list 查看(本地)…...
ubuntu/kali安装c-jwt-cracker
1.下载安装包 可以去GitHub下载解压,我这直接在kali克隆下来了。(网络不好可能克隆不下来) git clone https://github.com/brendan-rius/c-jwt-cracker.git 2.如果下载的压缩包就需要进行解压,克隆的直接进入目录就好了。 unzi…...
MySql按年月日自动创建分区存储过程
-- 创建存储过程【通过数据库和表名】建立【partition_number】get分区,分区间隔为【gaps】 -- datasource 数据库名称 -- table_name 数据库表名 -- partition_number 新建分区的数量 -- partition_type 分区类型(0-按天分区,1-按月分区&…...
Spring配置文件中:密码明文改为密文处理方式(通用方法)
目录 一、背景 二、思路 A) 普通方式 B) 适合bootstrap.properties方式 三、示例 A) 普通方式(连接Redis集群) A) 普通方式(连接RocketMQ) B) 适合bootstrap.properties方式 四、总结 一、背景 SpringBoot和Sprin…...
树的模拟实现
一.链式前向星 所谓链式前向星,就是用链表的方式实现树。其中的链表是用数组模拟实现的链表。 首先我们需要创建一个足够大的数组h,作为所有结点的哨兵位。创建两个足够大的数组e和ne,一个作为数据域,一个作为指针域。创建一个变…...
计算机图形学【直线和圆的生成算法】
在计算机图形学中,光栅化是将几何图元转换成一个光栅图像(像素或点)在屏幕上输出的过程。光栅化可实现图形变为二维图像,其目的是将连续的几何图形转换为离散的像素点。光栅化算法的基本原理包括两个主要步骤:首先&…...
OpenAI 故障复盘 - 阿里云容器服务与可观测产品如何保障大规模 K8s 集群稳定性
本文作者: 容器服务团队:刘佳旭、冯诗淳 可观测团队:竺夏栋、麻嘉豪、隋吉智 一、前言 Kubernetes(K8s)架构已经是当今 IT 架构的主流与事实标准(CNCF Survey[1])。随着承接的业务规模越来越大,用户也在使…...
【深度学习】Pytorch:加载自定义数据集
本教程将使用 flower_photos 数据集演示如何在 PyTorch 中加载和导入自定义数据集。该数据集包含不同花种的图像,每种花的图像存储在以花名命名的子文件夹中。我们将深入讲解每个函数和对象的使用方法,使读者能够推广应用到其他数据集任务中。 flower_ph…...
vue js实现时钟以及刻度效果
2025.01.08今天我学习如何用js实现时钟样式,效果如下: 一、html代码如下: <template><!--圆圈--><div class"notice_border"><div class"notice_position notice_name_class" v-for"item in …...
js基础---注释与结束符
JavaScript 基础:注释与结束符 注释 注释是代码中用于解释说明的部分,不会被执行,主要有两种类型: 单行注释 符号://作用:从符号开始到该行末尾的所有内容都会被忽略,不会被执行。示例代码&…...
from pytorch3d import _C问题
离线安装pytorch3d后,先测试: import pytorch3d 没问题后,再测试: from pytorch3d import _C 单独测试会出现: ImportError: libc10.so: cannot open shared object file: No such file or directory 或者类似不…...
PHP进阶-在Ubuntu上搭建LAMP环境教程
本文将为您提供一个在Ubuntu服务器上搭建LAMP(Linux, Apache, MySQL, PHP)环境的完整指南。通过本文,您将学习如何安装和配置Apache、MySQL、PHP,并将您的PHP项目部署到服务器上。本文适用于Ubuntu 20.04及更高版本。 一、系统更新…...
SQLite 命令
关于《SQLite 命令》的文章,我可以为您提供一个概要。SQLite是一个轻量级的嵌入式关系数据库管理系统,它以单个文件的形式存储数据,非常适合用于不需要传统数据库服务器的场景。SQLite3的命令行工具(sqlite3.exe)是一个…...
ASP.NET Core 实现微服务 - Consul 配置中心
这一次我们继续介绍微服务相关组件配置中心的使用方法。本来打算介绍下携程开源的重型配置中心框架 apollo 但是体系实在是太过于庞大,还是让我爱不起来。因为前面我们已经介绍了使用Consul 做为服务注册发现的组件 ,那么干脆继续使用 Consul 来作为配置…...
自定义Java注解及其应用
上一篇博客:Java注解 写在前面:大家好!我是晴空๓。如果博客中有不足或者的错误的地方欢迎在评论区或者私信我指正,感谢大家的不吝赐教。我的唯一博客更新地址是:https://ac-fun.blog.csdn.net/。非常感谢大家的支持。…...
回归预测 | MATLAB实GRU多输入单输出回归预测
回归预测 | MATLAB实GRU多输入单输出回归预测 目录 回归预测 | MATLAB实GRU多输入单输出回归预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 回归预测 | MATLAB实GRU多输入单输出回归预测。使用GRU作为RNN的一种变体来处理时间序列数据。GRU相比传统的RNN有较好的记…...
ISP流程--去马赛克详解
前言 本期我们将深入讨论ISP流程中的去马赛克处理。我们熟知,彩色图像由一个个像元组成,每个像元又由红、绿、蓝(RGB)三通道构成。而相机传感器只能感知光的强度,无法直接感知光谱信息,即只有亮暗而没有颜色…...
用户注册模块用户校验(头条项目-05)
1 用户注册后端逻辑 1.1 接收参数 username request.POST.get(username) password request.POST.get(password) phone request.POST.get(phone) 1.2 校验参数 前端校验过的后端也要校验,后端的校验和前端的校验是⼀致的 # 判断参数是否⻬全 # 判断⽤户名是否…...
【大数据】Apache Superset:可视化开源架构
Apache Superset是什么 Apache Superset 是一个开源的现代化数据可视化和数据探索平台,主要用于帮助用户以交互式的方式分析和展示数据。有不少丰富的可视化组件,可以将数据从多种数据源(如 SQL 数据库、数据仓库、NoSQL 数据库等࿰…...
如何搭建 Vue.js 开源项目的 CI/CD 流水线
网罗开发 (小红书、快手、视频号同名) 大家好,我是 展菲,目前在上市企业从事人工智能项目研发管理工作,平时热衷于分享各种编程领域的软硬技能知识以及前沿技术,包括iOS、前端、Harmony OS、Java、Python等…...
OCR文字识别—基于PP-OCR模型实现ONNX C++推理部署
概述 PaddleOCR 是一款基于 PaddlePaddle 深度学习平台的开源 OCR 工具。PP-OCR是PaddleOCR自研的实用的超轻量OCR系统。它是一个两阶段的OCR系统,其中文本检测算法选用DB,文本识别算法选用CRNN,并在检测和识别模块之间添加文本方向分类器&a…...
国产3D CAD将逐步取代国外软件
在工业软件的关键领域,计算机辅助设计(CAD)软件对于制造业的重要性不言而喻。近年来,国产 CAD 的发展态势迅猛,展现出巨大的潜力与机遇,正逐步改变着 CAD 市场长期由国外软件主导的格局。 国产CAD发展现状 …...
GoLand 如何集成 Netty?
目录 1.回答问题: 2.以下是实现类似 Netty 功能的步骤: 2.1 实现基本的网络通信功能: 3. 使用 Go 的第三方库实现 Netty 功能 4.实现类似 Netty 的事件循环: 5. 运用场景: 1.回答问题: 要在 GoLand 中…...
C++中 为什么要把基类指针指向子类对象?
为什么要把基类指针指向子类对象? 1)实现多态性 动态绑定行为:通过基类指针指向子类对象,可以利用 C 的多态机制。当基类中有虚函数,并且子类重写了这些虚函数时,通过基类指针调用虚函数,实际调…...
2025年第三届“华数杯”国际赛A题解题思路与代码(Matlab版)
游泳竞技策略优化模型代码详解(MATLAB版) 第一题:速度优化模型 本部分使用MATLAB实现游泳运动员在不同距离比赛中的速度分配策略优化。 1. 模型概述 模型包含三个主要文件: speed_optimization.m: 核心优化类plot_speeds.m: …...
做一个 简单的Django 《股票自选助手》显示 用akshare 库(A股数据获取)
图: 股票自选助手 这是一个基于 Django 开发的 A 股自选股票信息查看系统。系统使用 akshare 库获取实时股票数据,支持添加、删除和更新股票信息。 功能特点 支持添加自选股票实时显示股票价格和涨跌幅一键更新所有股票数据支持删除不需要的股票使用中…...
深入探索 ScottPlot.WPF:在 Windows 桌面应用中绘制精美图表的利器
一、ScottPlot.WPF 简介 ScottPlot.WPF 是基于 ScottPlot 绘图库专门为 Windows Presentation Foundation (WPF) 框架量身定制的强大绘图组件。它无缝集成到 WPF 应用程序中,为开发者提供了一种简洁、高效的方式来可视化数据,无论是科学研究中的实验数据展示、金融领域的行情…...
Spring bean的生命周期和扩展
接AnnotationConfigApplicationContext流程看实例化的beanPostProcessor-CSDN博客,以具体实例看bean生命周期的一些执行阶段 bean生命周期流程 生命周期扩展处理说明实例化:createBeanInstance 构造方法, 如Autowired的构造方法注入依赖bean 如UserSer…...
【Docker】docker compose 安装 Redis Stack
注:整理不易,请不要吝啬你的赞和收藏。 前文 Redis Stack 什么是? 简单来说,Redis Stack 是增强版的 Redis ,它在传统的 Redis 数据库基础上增加了一些高级功能和模块,以支持更多的使用场景和需求。Redis…...
Life Long Learning(李宏毅)机器学习 2023 Spring HW14 (Boss Baseline)
1. 终身学习简介 神经网络的典型应用场景是,我们有一个固定的数据集,在其上训练并获得模型参数,然后将模型应用于特定任务而无需进一步更改模型参数。 然而,在许多实际工程应用中,常见的情况是系统可以不断地获取新数据,例如 Web 应用程序中的新用户数据或自动驾驶中的…...
JavaEE之线程池
前面我们了解了多个任务可以通过创建多个线程去处理,达到节约时间的效果,但是每一次的线程创建和销毁也是会消耗计算机资源的,那么我们是否可以将线程进阶一下,让消耗计算机的资源尽可能缩小呢?线程池可以达到此效果&a…...
错误修改系列---基于RNN模型的心脏病预测(pytorch实现)
前言 前几天发布了pytorch实现,TensorFlow实现为:基于RNN模型的心脏病预测(tensorflow实现),但是一处繁琐地方 一处错误,这篇文章进行修改,修改效果还是好了不少;源文章为:基于RNN模型的心脏病…...
修改之前的代码使得利用设备树文件和Platform总线设备驱动实现对多个LED的驱动【只是假想对LED进行驱动,并没有实际的硬件操作】
引言 在下面这篇博文中: 利用Linux的Platform总线设备驱动实现对多个LED的驱动【只是假想对LED进行驱动,并没有实际的硬件操作】 我们利用Platform总线设备驱动的思想实现了对多个LED的驱动。 Platform总线设备驱动以及其它的总线设备驱动都将驱动分成了三个部分…...
从CentOS到龙蜥:企业级Linux迁移实践记录(龙蜥开局)
引言: 在我们之前的文章中,我们详细探讨了从CentOS迁移到龙蜥操作系统的基本过程和考虑因素。今天,我们将继续这个系列,重点关注龙蜥系统的实际应用——特别是常用软件的安装和配置。 龙蜥操作系统(OpenAnolis&#…...
多云架构,JuiceFS 如何实现一致性与低延迟的数据分发
随着大模型的普及,GPU 算力成为稀缺资源,单一数据中心或云区域的 GPU 资源常常难以满足用户的全面需求。同时,跨地域团队的协作需求也推动了企业在不同云平台之间调度数据和计算任务。多云架构正逐渐成为一种趋势,然而该架构下的数…...
Jenkins持续集成与交付安装配置
Jenkins 是一款开源的持续集成(CI)和持续交付(CD)工具,它主要用于自动化软件的构建、测试和部署流程。为项目持续集成与交付功能强大的应用。下面我们来介绍下它的安装与配置。 环境准备 更新系统组件(这…...
十大排序简介
十大排序简介 一、排序分类二、排序思路1.冒泡排序(Bubble Sort)2.选择排序(Selection Sort)3.插入排序(Insertion Sort)4.希尔排序(Shell Sort&a…...
uniapp小程序中隐藏顶部导航栏和指定某页面去掉顶部导航栏小程序
uniappvue3开发小程序过程中隐藏顶部导航栏和指定某页面去掉顶部导航栏方法 在page.json中 "globalStyle": {"navigationStyle":"custom",}, 如果是指定某个页面关闭顶部导航栏,在style中添加"navigationStyle": "cus…...
echarts:dataZoom属性横向滚动条拖拽不生效
问: 拖拽的过程中,第一次向右拖拽正常,然后就报错: echarts报错: var pointerOption pointerShapeBuilder[axisPointerType](axis,pixeValue,otherExtent),(axis,pixeValue,otherExtent)下划线红色报错:…...
【Leetcode 热题 100】739. 每日温度
问题背景 给定一个整数数组 t e m p e r a t u r e s temperatures temperatures,表示每天的温度,返回一个数组 a n s w e r answer answer,其中 a n s w e r [ i ] answer[i] answer[i] 是指对于第 i i i 天,下一个更高温度…...
R数据分析:多分类问题预测模型的ROC做法及解释
有同学做了个多分类的预测模型,结局有三个类别,做的模型包括多分类逻辑回归、随机森林和决策树,多分类逻辑回归是用ROC曲线并报告AUC作为模型评估的,后面两种模型报告了混淆矩阵,审稿人就提出要统一模型评估指标。那么肯定是统一成ROC了,刚好借这个机会给大家讲讲ROC在多…...
如何用 SSH 访问 QNX 虚拟机
QNX 虚拟机默认是开启 SSH 服务的,如果要用 SSH 访问 QNX 虚拟机,就需要知道虚拟机的 IP 地址,用户和密码。本文我们来看看如何获取这些参数。 1. 启动虚拟机 启动过程很慢,请耐心等待。 2. 查看 IP 地址 等待 IDE 连接到虚拟机。…...
交响曲-24-3-单细胞CNV分析及聚类
CNV概述 小于1kb是常见的插入、移位、缺失等的变异 人体内包含<10% 的正常CNV,我们的染色体数是两倍体,正常情况下,只有一条染色体表达,另一条沉默,当表达的那条染色体发生CNV之后,表达数量就会成倍增加…...
java远程调试debug
文章目录 首先被调试的服务配置idea 中配置远程调试连接上被调试服务打断点开始调试 首先被调试的服务配置 被调试的 java 服务需要开启允许被远程调试的配置,具体就是启动脚本中,加上允许被远程调试以及相应端口 # 针对JDK15.-1.8 -agentlib:jdwptran…...
操作系统之系统调用
系统调用 从上文简介得知,操作系统是计算机硬件和软件之间的桥梁,通过管理计算机软件和硬件资源,最终为我们用户提供服务。就如同一个管家帮助我们对CPU(进程)的管理、内存的管理、设备的管理、文件的管理。而我们如何…...
【docker】exec /entrypoint.sh: no such file or directory
dockerfile生成的image 报错内容: exec /entrypoint.sh: no such file or directory查看文件正常在此路径,但是就是报错没找到。 可能是因为sh文件的换行符使用了win的。...
CAPL概述与环境搭建
CAPL概述与环境搭建 目录 CAPL概述与环境搭建1. CAPL简介与应用领域1.1 CAPL简介1.2 CAPL的应用领域 2. CANoe/CANalyzer 安装与配置2.1 CANoe/CANalyzer 简介2.2 安装CANoe/CANalyzer2.2.1 系统要求2.2.2 安装步骤 2.3 配置CANoe/CANalyzer2.3.1 配置CAN通道2.3.2 配置CAPL节点…...
ML-Agents:智能体(三)
注:本文章为官方文档翻译,如有侵权行为请联系作者删除 Agent - Unity ML-Agents Toolkit–原文链接> ML-Agents:智能体(一) ML-Agents:智能体(二) ML-Agents:智能体&a…...
【harbor】离线安装2.9.0-arm64架构服务制作和升级部署
执行: .prepare 【作用就是产生一些配置信息 和docker-compose.yaml文件,然后docker-compose发布docker】 harbor官网地址:Harbor 参考文档可以看这里:部署 harbor 2.10.1 arm64 - 简书。 前提环境准备: 安装docker 和 docker…...
可视化-Visualization
可视化-Visualization 1.Introduction Visualization in Open CASCADE Technology is based on the separation of: on the one hand – the data which stores the geometry and topology of the entities you want to display and select, andon the other hand – its pr…...