使用ollama部署本地大模型(没有GPU也可以),实现IDEA和VS Code的git commit自动生成

详情

问豆包,提示词如下:收集下ollama相关信息,包括但不限于:官网地址/GitHub地址/文档地址

官网地址

https://ollama.com/

GitHub 地址

https://github.com/ollama/ollama

文档地址

https://github.com/ollama/ollama/blob/main/docs/README.md

安装

https://ollama.com/download

https://github.com/ollama/ollama/blob/main/docs/linux.md

bash 复制代码
curl -fsSL https://ollama.com/install.sh | sh

#模型位置
/usr/share/ollama/.ollama/models

model

https://ollama.com/search

没有GPU的可以下载3b以下的(我亲测过16C 32G的服务器),比如:

bash 复制代码
ollama run qwen2.5:3b

本文以32b为例,用的是RTX4090 24G:

bash 复制代码
ollama run qwen2.5:32b

IDEA

AI Commits插件:https://plugins.jetbrains.com/plugin/21335-ai-commits

配置:Settings > Tools > AI Commits

然后点击提交框上面那个图标就行了

目前GitMoji是最好的,但提示词也可自定义,我给大家列一些这个插件之前的:

复制代码
Generate a concise and standardized git commit message in {language} based on the code changes. Follow the conventional commit format, including:  1.Type: Use one of feat, fix, docs, style, refactor, test, chore, etc.  2.Scope: Specify the module or file affected (if applicable).  3.Subject: A short, clear description of the change (50 characters or less).  4.Body (optional): Provide additional context or details if necessary, but keep it brief.  Ensure the output is clean and does not include any unnecessary formatting (e.g., code blocks or extra symbols).  Here are the code changes: {diff} 

Generate a concise yet detailed git commit message using the following format and information:   <type>(<scope>): <subject>   <body>   <footer>   Use the following placeholders in your analysis:  - diff begin :  {diff}  - diff end.   Guidelines:   1. <type>: Commit type (required)     - Use standard types: feat, fix, docs, style, refactor, perf, test, chore   2. <scope>: Area of impact (required)     - Briefly mention the specific component or module affected   3. <subject>: Short description (required)     - Summarize the main change in one sentence (max 50 characters)     - Use the imperative mood, e.g., "add" not "added" or "adds"     - Don't capitalize the first letter     - No period at the end   4. <body>: Detailed description (required)     - Explain the motivation for the change     - Describe the key modifications (max 3 bullet points)     - Mention any important technical details     - Use the imperative mood   5. <footer>: (optional)     - Note any breaking changes     - Reference related issues or PRs   Example:   feat(user-auth): implement two-factor authentication   • Add QR code generation for 2FA setup  • Integrate Google Authenticator API  • Update user settings for 2FA options   Notes:  - Keep the entire message under 300 characters  - Focus on what and why, not how  - Summarize diff to highlight key changes; don't include raw diff output  Note: The whole result should be given in {language} and the final result must not contain '```' 

 You are a Git commit message generation expert. Please analyze the following code changes and generate a clear, standardized commit message in {language}.  Code changes: {diff}  Requirements for the commit message: 1. First line should start with one of these types:    feat: (new feature)    fix: (bug fix)    docs: (documentation)    style: (formatting)    refactor: (code refactoring)    perf: (performance)    test: (testing)    chore: (maintenance)  2. First line should be no longer than 72 characters  3. After the first line, leave one blank line and provide detailed explanation if needed:    - Why was this change necessary?    - How does it address the issue?    - Any breaking changes?  4. Use present tense  Please output only the commit message, without any additional explanations. 

VS Code

Git Commit Message Generator插件:https://marketplace.visualstudio.com/items?itemName=chenkai2.vscode-git-commit-message-generator

之前的用户提示词和系统提示词分别如下:

bash 复制代码
标题行格式为 <type>: <description>,字数不要超过50个,description如果不是中文,则翻译成中文。两个换行后,输出正文内容,每个要点作为一个符号列表,不超过70个字。type使用英文,description和正文用中文,如果不是,则翻译成中文。要点简洁清晰。

根据以下Git变更生成Git提交信息,格式为 <type>: <description>。文件:${files}变更内容:${diff}

感觉不好用,给它改了,参考的是上面的提示词:

bash 复制代码
 Generate a concise yet detailed git commit message using the following format and information:   <type>(<scope>): <subject>    Use the following placeholders in your analysis:  - diff begin :  ${diff}  - diff end.   Guidelines:   1. <type>: Commit type (required)     - Use standard types: feat, fix, docs, style, refactor, perf, test, chore   2. <scope>: Area of impact (required)     - Briefly mention the specific component or module affected   3. <subject>: Short description (required)     - Summarize the main change in one sentence (max 50 characters)     - Use the imperative mood, e.g., "add" not "added" or "adds"     - Don't capitalize the first letter     - No period at the end     Example:   feat(user-auth): implement two-factor authentication   • Add QR code generation for 2FA setup  • Integrate Google Authenticator API  • Update user settings for 2FA options   Notes:  - Keep the entire message under 300 characters  - Focus on what and why, not how  - Summarize diff to highlight key changes; don't include raw diff output  Note: The whole result should be given in ${files} and the final result must not contain '```' 

或者

bash 复制代码
 You are a Git commit message generation expert. Please analyze the following code changes and generate a clear, standardized commit message in ${files}.  Code changes: ${diff}  Requirements for the commit message: 1. First line should start with one of these types:    feat: (new feature)    fix: (bug fix)    docs: (documentation)    style: (formatting)    refactor: (code refactoring)    perf: (performance)    test: (testing)    chore: (maintenance)  2. First line should be no longer than 72 characters  3. After the first line, leave one blank line and provide detailed explanation if needed:    - Why was this change necessary?    - How does it address the issue?    - Any breaking changes?  4. Use present tense  Please output only the commit message, without any additional explanations.

然后点击提交框上面那个图标就行了(图片里面没有截取到),最近的提交都用这个了

常见问题

linux suspend resume cause to use CPU?

https://github.com/ollama/ollama/blob/main/docs/gpu.md#laptop-suspend-resume

On linux, after a suspend/resume cycle, sometimes Ollama will fail to discover your NVIDIA GPU, and fallback to running on the CPU. You can workaround this driver bug by reloading the NVIDIA UVM driver with

bash 复制代码
sudo rmmod nvidia_uvm && sudo modprobe nvidia_uvm

如何允许外网访问?

https://github.com/ollama/ollama/blob/main/docs/faq.md#setting-environment-variables-on-linux

bash 复制代码
sudo systemctl edit ollama.service

[Service]
Environment="OLLAMA_HOST=0.0.0.0"

sudo systemctl daemon-reload
sudo systemctl restart ollama
相关推荐
乌旭2 小时前
量子计算与GPU的异构加速:基于CUDA Quantum的混合编程实践
人工智能·pytorch·分布式·深度学习·ai·gpu算力·量子计算
ʚʕ̯•͡˔•̯᷅ʔɞ LeeKuma4 小时前
探索具身智能协作机器人:技术、应用与未来
ai·协作机器人·具身智能机器人
yuren_xia6 小时前
IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤
spring·mvc·intellij-idea
它说我会飞耶7 小时前
git 命令集
git
极小狐7 小时前
极狐GitLab 合并请求依赖如何解决?
运维·git·ssh·gitlab·github
程序猿(雷霆之王)7 小时前
Linux——进程间通信
linux·运维·服务器
字节王德发7 小时前
如何在SpringBoot中通过@Value注入Map和List并使用YAML配置?
java·maven·intellij-idea
riveting8 小时前
SD2351核心板:重构AI视觉产业价值链的“超级节点”
大数据·linux·图像处理·人工智能·重构·智能硬件
聂 可 以8 小时前
IntelliJ IDEA修改实体类成员变量的名称(引入了该实体类的全部文件也会自动更新变量的名称)
java·ide·intellij-idea
易保山9 小时前
MIT6.S081 - Lab10 mmap(文件&内存映射)
linux·操作系统·c