AI自動生成Git提交信息-git AI Commit

在現代軟件開發中,編寫清晰且一致的Git提交信息對于維護項目歷史和促進團隊協作至關重要。然而,為每次變更手動撰寫描述性提交信息可能耗時,尤其是處理復雜差異或大型項目時。AI Commit 是一個利用AI分析Git差異并生成符合Conventional Commits規范的提交信息的Python腳本。本文將介紹其工作原理、核心功能以及如何優化您的開發流程。
在這里插入圖片描述

什么是AI Commit?

AI Commit 是一個Python工具,通過分析暫存的Git變更(git diff --cached)并利用大型語言模型(LLM)生成簡潔、上下文相關的提交信息。它集成了外部API(如阿里云的Qwen模型),能夠識別代碼變更類型(功能添加、錯誤修復、重構等),并生成符合規范的提交信息,確保項目歷史清晰易懂。

核心功能

1. 智能差異分析

腳本解析Git差異,提取關鍵信息:

  • 文件變更:識別新增、修改和刪除的文件。
  • 變更類型:檢測重構、功能添加、錯誤修復、文檔更新或配置變更。
  • 優先文件分析:重點關注重要文件類型(如.py.js.java)。
  • 變更范圍:判斷變更影響單個文件、模塊或多個項目部分。

對于大型差異或多文件項目,AI Commit生成簡潔摘要,保留關鍵細節。

2. 上下文感知的提交信息

AI Commit根據變更類型生成符合Conventional Commits規范的提交信息,例如:

  • 文檔更新:使用docs:前綴(例:docs: 更新README中的安裝說明)。
  • 測試變更:使用test:前綴(例:test: 添加用戶認證單元測試)。
  • 錯誤修復:使用fix:前綴(例:fix: 修復數據解析中的空指針異常)。
  • 新功能:使用feat:前綴(例:feat: 實現用戶配置文件API端點)。
  • 代碼重構:使用refactor:前綴(例:refactor: 將工具函數提取到獨立模塊)。
  • 配置變更:使用chore:config:前綴(例:chore: 更新package.json中的依賴)。

這確保提交信息與工具如semantic-release兼容,便于生成變更日志。

3. 支持新項目初始化

腳本能檢測新項目的初始提交(例如包含README.mdpackage.json.gitignore等文件),生成類似init: 初始化項目結構的提交信息。

4. 處理大型差異

對于超過8000字符或涉及10個以上文件的差異,AI Commit通過以下方式進行智能處理:

  • 按文件類型分組(例:5個.py文件,2個.js文件)。
  • 提取關鍵變更,如函數或類定義。
  • 提供分層摘要,包含變更類型、主要語言和范圍。

5. 健壯的錯誤處理

腳本處理多種錯誤情況,包括:

  • Git命令缺失或無效。
  • API請求失敗(如超時或HTTP錯誤)。
  • 環境變量(如QWEN_API)缺失。
  • 無效或空差異。

提供清晰的錯誤信息,便于開發者排查問題。

工作流程

以下是腳本的工作流程圖,使用Mermaid展示:

git diff --cached
大型差異
小型差異
成功
失敗
獲取Git暫存差異
差異是否有效?
輸出無暫存更改提示
分析差異
提取文件變更和模式
生成摘要
提取關鍵變更
生成上下文感知提示
調用LLM API
提取提交信息
輸出錯誤信息
執行git commit
提交成功
  1. 獲取差異:運行git diff --cached獲取暫存變更。
  2. 分析差異:解析文件變更、添加/刪除行數及模式。
  3. 摘要生成:對于大型差異,生成簡潔摘要或提取關鍵變更。
  4. 生成提示:根據變更類型創建上下文感知的提示。
  5. 調用API:將差異或摘要發送至LLM API生成提交信息。
  6. 執行提交:使用git commit -m <message>提交。

示例代碼

以下是核心代碼片段,展示如何分析差異并生成提交信息:

def analyze_diff(diff):"""分析diff內容,返回文件變更摘要"""lines = diff.split('\n')files_info = {'new_files': [],'modified_files': [],'deleted_files': [],'total_additions': 0,'total_deletions': 0}current_file = Nonefor line in lines:if line.startswith('diff --git'):match = re.search(r'a/(.*?) b/(.*?)$', line)if match:current_file = match.group(2)elif line.startswith('new file mode'):if current_file:files_info['new_files'].append(current_file)elif line.startswith('deleted file mode'):if current_file:files_info['deleted_files'].append(current_file)elif line.startswith('index') and current_file:if current_file not in files_info['new_files'] and current_file not in files_info['deleted_files']:files_info['modified_files'].append(current_file)elif line.startswith('+') and not line.startswith('+++'):files_info['total_additions'] += 1elif line.startswith('-') and not line.startswith('---'):files_info['total_deletions'] += 1return files_infodef get_commit_message(request_body):"""調用 API 生成提交信息"""headers = {"Authorization": f"Bearer {API_KEY}","Content-Type": "application/json"}try:response = requests.post(API_URL, headers=headers, json=request_body, timeout=REQUEST_TIMEOUT)response.raise_for_status()return response.json()except requests.exceptions.Timeout:print(f"[ERROR] API 請求超時 ({REQUEST_TIMEOUT} 秒)。")return None

示例使用

假設您在一個Python項目中暫存了變更并運行腳本,輸出可能如下:

[INFO] 請求體內容:
{"model": "qwen-plus-latest","temperature": 0.3,"messages": [{"role": "system","content": "你是一個專業程序員。這是新功能相關的變更,請生成符合 conventional commits 規范的提交信息,使用 'feat:' 前綴。僅返回一行,不要解釋。"},{"role": "user","content": "新增文件: src/api.py, tests/test_api.py; +50 -0 行"}]
}[INFO] 生成的提交信息:feat: 添加用戶認證API端點
[OK] 已提交。

生成的提交信息清晰、規范,準確反映變更內容。

開始使用

依賴

  • Python 3.6+。
  • Git安裝并在PATH中可用。
  • 兼容的LLM服務API密鑰(如阿里云Qwen)。
  • 設置環境變量QWEN_API

安裝

  1. 保存腳本為ai_commit.py
  2. 設置API密鑰:export QWEN_API=your_api_key
  3. 暫存變更:git add .
  4. 運行腳本:python ai_commit.py

配置

  • API_URL:默認https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
  • MODEL_NAME:默認qwen-plus-latest
  • MAX_DIFF_SIZE:限制差異大小為8000字符。
  • PRIORITY_FILE_EXTENSIONS:優先處理的文件類型(如.py.js)。

實用小工具

App Store 截圖生成器、應用圖標生成器 、在線圖片壓縮和 Chrome插件-強制開啟復制-護眼模式-網頁亂碼設置編碼
乖貓記賬,AI智能分類的聊天記賬。


完整代碼

# coding: utf-8
import os
import subprocess
import requests
import json
import re
from collections import defaultdict# ==================== 配置常量 ====================
API_KEY = os.environ.get("QWEN_API")
if not API_KEY:print("[ERROR] QWEN_API environment variable not set. Please set it before running the script.")exit(1)API_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"
MODEL_NAME = "qwen-plus-latest"
REQUEST_TIMEOUT = 15
MAX_DIFF_SIZE = 8000
MAX_FILES_FOR_DETAIL = 10# 優先分析的文件類型
PRIORITY_FILE_EXTENSIONS = ['.py', '.js', '.ts', '.jsx', '.tsx', '.vue', '.dart','.java', '.cpp', '.c', '.go', '.rs', '.php', '.rb'
]# 語言映射
LANGUAGE_MAP = {'.py': 'Python', '.js': 'JavaScript', '.ts': 'TypeScript','.jsx': 'React', '.tsx': 'TypeScript React', '.vue': 'Vue','.java': 'Java', '.cpp': 'C++', '.c': 'C', '.go': 'Go','.rs': 'Rust', '.php': 'PHP', '.rb': 'Ruby', '.dart': 'Dart'
}# ==================== Git 操作函數 ====================
def get_git_diff():"""獲取 Git staged 變更"""try:result = subprocess.run(['git', 'diff', '--cached'],stdin=subprocess.DEVNULL,stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True,encoding='utf-8',check=True)return result.stdoutexcept subprocess.CalledProcessError as e:print(f"[ERROR] 獲取 Git diff 失敗: {e}")if e.stderr:print(f"[ERROR] Stderr: {e.stderr.strip()}")return Noneexcept FileNotFoundError:print("[ERROR] Git 命令未找到。請確保 Git 已安裝并在您的 PATH 中。")return Nonedef git_commit(message):"""執行 Git 提交"""try:subprocess.run(['git', 'commit', '-m', message], encoding='utf-8', check=True)print("[OK] 已提交。")except subprocess.CalledProcessError as e:print(f"[ERROR] Git commit 失敗: {e}")if e.stderr:print(f"[ERROR] Stderr: {e.stderr.strip()}")if e.stdout:print(f"[ERROR] Stdout: {e.stdout.strip()}")except FileNotFoundError:print("[ERROR] Git 命令未找到。請確保 Git 已安裝并在您的 PATH 中。")# ==================== Diff 分析函數 ====================
def analyze_diff(diff):"""分析diff內容,返回文件變更摘要"""lines = diff.split('\n')files_info = {'new_files': [],'modified_files': [],'deleted_files': [],'total_additions': 0,'total_deletions': 0}current_file = Nonefor line in lines:if line.startswith('diff --git'):match = re.search(r'a/(.*?) b/(.*?)$', line)if match:current_file = match.group(2)elif line.startswith('new file mode'):if current_file:files_info['new_files'].append(current_file)elif line.startswith('deleted file mode'):if current_file:files_info['deleted_files'].append(current_file)elif line.startswith('index') and current_file:if current_file not in files_info['new_files'] and current_file not in files_info['deleted_files']:files_info['modified_files'].append(current_file)elif line.startswith('+') and not line.startswith('+++'):files_info['total_additions'] += 1elif line.startswith('-') and not line.startswith('---'):files_info['total_deletions'] += 1return files_infodef extract_key_changes(diff):"""提取diff中的關鍵變更,優先保留重要文件和函數簽名"""lines = diff.split('\n')key_sections = []current_section = []current_file = Noneis_priority_file = Falsefunction_changes = []for line in lines:if line.startswith('diff --git'):if current_section and is_priority_file:key_sections.extend(current_section[:50])current_section = [line]match = re.search(r'b/(.*?)$', line)if match:current_file = match.group(1)file_ext = os.path.splitext(current_file)[1]is_priority_file = file_ext in PRIORITY_FILE_EXTENSIONSelif line.startswith('@@'):current_section.append(line)elif is_priority_file:current_section.append(line)if line.startswith(('+', '-')):if re.search(r'(def |function |class |interface |struct |enum )', line):function_changes.append(f"{current_file}: {line.strip()}")if current_section and is_priority_file:key_sections.extend(current_section[:50])key_diff = '\n'.join(key_sections)if len(key_diff) > MAX_DIFF_SIZE:return '\n'.join(key_sections[:100] + function_changes)return key_diffdef analyze_change_patterns(files_info, diff):"""分析變更模式,識別重構、功能添加、bug修復等"""patterns = {'is_refactoring': False,'is_feature': False,'is_bugfix': False,'is_docs': False,'is_config': False,'is_test': False,'main_language': None,'change_scope': 'multiple'}all_files = files_info['new_files'] + files_info['modified_files'] + files_info['deleted_files']# 分析文件類型分布file_types = defaultdict(int)for file in all_files:ext = os.path.splitext(file)[1].lower()file_types[ext] += 1# 確定主要編程語言if file_types:main_ext = max(file_types.items(), key=lambda x: x[1])[0]patterns['main_language'] = LANGUAGE_MAP.get(main_ext, main_ext)# 分析變更類型doc_extensions = ['.md', '.txt', '.rst']config_extensions = ['.json', '.yaml', '.yml', '.toml', '.ini', '.conf']doc_files = [f for f in all_files if any(f.lower().endswith(ext) for ext in doc_extensions) or 'readme' in f.lower()]test_files = [f for f in all_files if 'test' in f.lower() or f.endswith(('_test.py', '.test.js', '.spec.js'))]config_files = [f for f in all_files if any(f.endswith(ext) for ext in config_extensions)]total_files = len(all_files)if total_files > 0:if len(doc_files) / total_files > 0.5:patterns['is_docs'] = Trueif len(test_files) > 0:patterns['is_test'] = Trueif len(config_files) / total_files > 0.3:patterns['is_config'] = True# 通過diff內容分析變更類型if diff:diff_lower = diff.lower()refactor_keywords = ['rename', 'move', 'extract', 'refactor', 'reorganize']feature_keywords = ['add', 'new', 'implement', 'feature', 'support']bugfix_keywords = ['fix', 'bug', 'error', 'issue', 'problem', 'correct']if any(keyword in diff_lower for keyword in refactor_keywords):patterns['is_refactoring'] = Trueif any(keyword in diff_lower for keyword in feature_keywords) and files_info['new_files']:patterns['is_feature'] = Trueif any(keyword in diff_lower for keyword in bugfix_keywords):patterns['is_bugfix'] = True# 確定變更范圍if len(all_files) == 1:patterns['change_scope'] = 'single'elif len(set(os.path.dirname(f) for f in all_files)) == 1:patterns['change_scope'] = 'module'else:patterns['change_scope'] = 'multiple'return patterns# ==================== 項目檢測和摘要生成 ====================
def is_new_project_init(files_info):"""檢測是否為新項目的初始提交"""total_files = len(files_info['new_files'])if (total_files >= 5 and len(files_info['modified_files']) == 0 and len(files_info['deleted_files']) == 0):new_files_str = ' '.join(files_info['new_files']).lower()project_indicators = ['readme', 'package.json', 'requirements.txt', 'cargo.toml','pom.xml', 'build.gradle', '.gitignore', 'main.', 'index.']return any(indicator in new_files_str for indicator in project_indicators)return Falsedef create_diff_summary(files_info):"""為大型diff創建摘要"""summary_parts = []if files_info['new_files']:if len(files_info['new_files']) > 5:file_types = {}for file in files_info['new_files']:ext = os.path.splitext(file)[1] or 'no_ext'file_types[ext] = file_types.get(ext, 0) + 1type_summary = ', '.join([f"{count} {ext} files" for ext, count in file_types.items()])summary_parts.append(f"新增文件: {type_summary} (共{len(files_info['new_files'])}個文件)")else:summary_parts.append(f"新增文件: {', '.join(files_info['new_files'])}")if files_info['modified_files']:if len(files_info['modified_files']) > 5:summary_parts.append(f"修改文件: {len(files_info['modified_files'])}個文件")else:summary_parts.append(f"修改文件: {', '.join(files_info['modified_files'])}")if files_info['deleted_files']:summary_parts.append(f"刪除文件: {', '.join(files_info['deleted_files'])}")summary_parts.append(f"+{files_info['total_additions']} -{files_info['total_deletions']} 行")return '; '.join(summary_parts)def create_layered_summary(files_info, patterns):"""創建分層的變更摘要"""summary_parts = []# 第一層:變更類型change_types = []type_mapping = {'is_feature': "新功能",'is_bugfix': "錯誤修復",'is_refactoring': "代碼重構",'is_docs': "文檔更新",'is_config': "配置變更",'is_test': "測試相關"}for key, label in type_mapping.items():if patterns[key]:change_types.append(label)if change_types:summary_parts.append(f"變更類型: {', '.join(change_types)}")# 第二層:主要語言和范圍if patterns['main_language']:summary_parts.append(f"主要語言: {patterns['main_language']}")summary_parts.append(f"影響范圍: {patterns['change_scope']}")# 第三層:具體文件變更file_summary = create_diff_summary(files_info)summary_parts.append(file_summary)return '\n'.join(summary_parts)# ==================== 提示詞生成 ====================
def get_context_aware_prompt(patterns, files_info):"""根據變更模式生成上下文感知的提示詞"""base_prompt = "你是一個專業程序員。"prompt_mapping = {'is_docs': f"{base_prompt}這是文檔相關的變更,請生成符合 conventional commits 規范的提交信息,使用 'docs:' 前綴。僅返回一行,不要解釋。",'is_test': f"{base_prompt}這是測試相關的變更,請生成符合 conventional commits 規范的提交信息,使用 'test:' 前綴。僅返回一行,不要解釋。",'is_config': f"{base_prompt}這是配置文件相關的變更,請生成符合 conventional commits 規范的提交信息,使用 'chore:' 或 'config:' 前綴。僅返回一行,不要解釋。",'is_refactoring': f"{base_prompt}這是代碼重構相關的變更,請生成符合 conventional commits 規范的提交信息,使用 'refactor:' 前綴。僅返回一行,不要解釋。",'is_bugfix': f"{base_prompt}這是錯誤修復相關的變更,請生成符合 conventional commits 規范的提交信息,使用 'fix:' 前綴。僅返回一行,不要解釋。",}for pattern_type, prompt in prompt_mapping.items():if patterns[pattern_type]:return prompt# 特征檢測if patterns['is_feature'] or len(files_info['new_files']) > len(files_info['modified_files']):return f"{base_prompt}這是新功能相關的變更,請生成符合 conventional commits 規范的提交信息,使用 'feat:' 前綴。僅返回一行,不要解釋。"return f"{base_prompt}請為以下代碼變更生成一條簡潔、符合 conventional commits 規范的提交信息,僅返回一行,不要解釋。"# ==================== API 調用函數 ====================
def build_request_body(diff):"""構建API請求體"""files_info = analyze_diff(diff)total_files = len(files_info['new_files']) + len(files_info['modified_files']) + len(files_info['deleted_files'])patterns = analyze_change_patterns(files_info, diff)use_summary = len(diff) > MAX_DIFF_SIZE or total_files > MAX_FILES_FOR_DETAILif use_summary:print(f"[INFO] Diff過大({len(diff)}字符) 或文件過多({total_files}個),使用智能摘要模式")if is_new_project_init(files_info):content = f"新項目初始化提交,包含以下變更:\n{create_diff_summary(files_info)}"system_prompt = "你是一個專業程序員。這是一個新項目的初始提交,請生成一條符合 conventional commits 規范的提交信息,通常使用 'feat: ' 或 'init: ' 開頭。僅返回一行,不要解釋。"else:content = create_layered_summary(files_info, patterns)system_prompt = get_context_aware_prompt(patterns, files_info)else:if len(diff) > MAX_DIFF_SIZE // 2:print(f"[INFO] 使用智能diff提取,原始大小: {len(diff)}字符")content = extract_key_changes(diff)print(f"[INFO] 提取后大小: {len(content)}字符")else:content = diffsystem_prompt = get_context_aware_prompt(patterns, files_info)return {"model": MODEL_NAME,"temperature": 0.3,"messages": [{"role": "system", "content": system_prompt},{"role": "user", "content": content}]}def get_commit_message(request_body):"""調用 API 生成提交信息"""headers = {"Authorization": f"Bearer {API_KEY}","Content-Type": "application/json"}try:response = requests.post(API_URL, headers=headers, json=request_body, timeout=REQUEST_TIMEOUT)response.raise_for_status()return response.json()except requests.exceptions.Timeout:print(f"[ERROR] API 請求超時 ({REQUEST_TIMEOUT} 秒)。")return Noneexcept requests.exceptions.HTTPError as e:print(f"[ERROR] API 請求失敗,HTTP 狀態碼: {e.response.status_code}")try:print(f"[ERROR] API 響應內容: {e.response.text}")except Exception:passreturn Noneexcept requests.exceptions.RequestException as e:print(f"[ERROR] API 請求發生錯誤: {e}")return Noneexcept json.JSONDecodeError:print(f"[ERROR] 解碼 API 響應失敗。狀態碼: {response.status_code if 'response' in locals() else 'N/A'}")return Nonedef extract_commit_message(response_data):"""提取提交信息"""if not response_data:return Nonetry:return response_data['choices'][0]['message']['content']except (KeyError, IndexError, TypeError) as e:print(f"[ERROR] 無法提取提交信息。錯誤: {e}。響應內容:")print(json.dumps(response_data, indent=2, ensure_ascii=False))return None# ==================== 主程序 ====================
def main():"""主程序入口"""diff = get_git_diff()if not diff:if diff is not None:print("[INFO] 沒有暫存更改,請先運行 git add。")returnrequest_body = build_request_body(diff)print("[INFO] 請求體內容:")print(json.dumps(request_body, indent=2, ensure_ascii=False))api_response = get_commit_message(request_body)if not api_response:returnmessage = extract_commit_message(api_response)if not message:returnprint("\n[INFO] 生成的提交信息:")print(f"  {message}")git_commit(message)if __name__ == "__main__":main()

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/85572.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/85572.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/85572.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【三大前端語言之一】樣式:CSS詳解

【三大前端語言之一】樣式&#xff1a;CSS詳解 在了解完HTML的有關知識后&#xff0c;我們應該知道&#xff0c;一個網頁光有框架還不行&#xff0c;必須還得有裝飾它的樣式。就好比房子的結構搭好了&#xff0c;但如果沒有油漆、沒有窗簾、沒有家具&#xff0c;就無法真正展現…

Spring AI 聊天記憶功能實戰(一):從接口設計到生產實踐

Spring AI 聊天記憶功能實戰&#xff08;一&#xff09;&#xff1a;從接口設計到生產實踐 在構建AI對話應用時&#xff0c;聊天記憶管理及存儲是實現連貫上下文交互的關鍵組件。而大模型&#xff08;LLM&#xff09;本質上是無狀態的&#xff0c;這意味著它們不會保留歷史交互…

Element Plus 對話框 el-dialog 和 抽屜 el-drawer 的使用注意項(使用 div 包裹)

總結&#xff1a;使用 div 包裹&#xff01;&#xff01;&#xff01; 詳細說明&#xff1a; 對話框 el-dialog 或 抽屜 el-drawer 樣式的設置說明&#xff1a; 要想有效設置 el-dialog 或 el-drawer 的樣式&#xff0c;需確保 el-dialog 或 el-drawer 的上層不是template&am…

【python】簡單演示 gateway、service、client的工作原理

gateway 看起來主要是做協議轉換的A gateway is a network node that acts as an entrance and exit point, connecting two networks that use different protocols. It allows data to flow between these networks, essentially acting as a translator between different c…

數據倉庫面試題合集⑥

實時指標體系設計 + Flink 優化實戰:面試高頻問題 + 項目答題模板 面試中不僅會問“你做過實時處理嗎?”,更會追問:“實時指標體系是怎么搭建的?”、“你們的 Flink 穩定性怎么保證?” 本篇聚焦實時指標體系設計與 Flink 優化場景,幫你答出架構設計力,也答出調優實戰感…

Vue + AbortController 請求取消彈窗 hook 封裝

背景 實際業務開發場景中&#xff0c;往往存在有些大數據請求的需求&#xff0c;一旦請求發起加載遮罩后用戶就無法操作了&#xff0c;直接尬住&#xff0c;所以提供一個支持取消查詢的功能還是很有必要的&#xff0c;為了在全業務接口都能使用封裝一個hook。 ?為什么要用 A…

數據結構相關

1 問題 如何辨析數據對象和數據結構&#xff1f;如何設計多種儲存結構以及他們特性有什么&#xff1f;內存條和硬盤的區別&#xff1f; 2 方法 明晰倆者的定義數據對象是性質相同的有限個數據元素的集合&#xff0c;他是數據的一個子集。數據結構是指所涉及的數據元素的集合以及…

MacOS內存管理-刪除冗余系統數據System Data

文章目錄 一、問題復現二、解決思路三、解決流程四、附錄 一、問題復現 以題主的的 Mac 為例&#xff0c;我們可以看到System Data所占數據高達77.08GB&#xff0c;遠遠超出系統所占內存 二、解決思路 占據大量空間的是分散在系統中各個位置Cache數據&#xff1b; 其中容量最…

純視覺SOTA!華科小米推出ReCogDrive:結合VLM和強化學習的端到端自動駕駛框架

摘要 端到端自動駕駛的研究目前越來越火熱&#xff0c;現有方法通過視覺語言模型&#xff08;VLM&#xff09;來解決其在長尾場景中性能降低的問題&#xff0c;但是仍然存在一些局限性。本文提出了ReCogDrive&#xff0c;它將VLM與基于擴散的軌跡規劃器相結合&#xff0c;并且采…

MySQL慢SQL優化全攻略:從診斷到調優

目錄 慢SQL日志分析與診斷 開啟慢查詢日志 慢查詢日志分析工具 慢SQL優化策略 1. 避免SELECT * 查詢 2. 創建高效索引 索引選擇原則 索引使用注意事項 3. 使用EXPLAIN分析執行計劃 4. 優化排序操作 5. 解決深分頁問題 6. 避免全表掃描 7. 優化JOIN操作 8. 合理使用…

OPENPPP2 VMUX 技術探秘(高級指南)

&#x1f680; VMUX技術分析&#xff1a;OPENPPP2中的虛擬多路復用技術 &#x1f31f; 一、技術目標 &#x1f517; 連接多路復用 通過單個或多個物理鏈路&#xff0c;承載多個邏輯TCP連接。 &#x1f680; 高性能傳輸 支持數據包亂序重組實現動態流量控制&#xff08;擁塞檢測…

Linux系統時間不對導致mysql初始化失敗:Data Dictionary initialization failed.(數據字典版本驗證失敗)

文章目錄 問題描述分析**問題原因分析****解決方案****1. 修正系統時間****2. 檢查數據目錄完整性****3. 重新初始化數據目錄****4. 調整 MySQL 配置** **驗證與后續步驟****注意事項** 其他說明 問題描述 mysql數據初始化失敗&#xff0c;發現系統時間是1970年&#xff0c;我…

有趣的python程序Part1:如何根據記憶曲線使用python編寫一個單詞記憶默寫程序

目錄 前言 1. 數據管理模塊 2. 記憶算法實現 3. 持久化存儲 4. 用戶界面實現 5.整合與測試 前言 此篇文章為“有趣的python程序”專欄的第一篇文章&#xff0c;本專欄致力于分享一些有趣的編程作品&#xff0c;如果能夠使您產生興趣&#xff0c;不妨來動手改編使之成為更好…

【案例】性能優化在持續集成與持續交付中的應用

【案例】性能優化在持續集成與持續交付中的應用 為了更好地理解性能優化在CI/CD流程中的實際應用&#xff0c;本節將結合一個典型案例&#xff0c;從代碼提交到部署上線的完整流程中&#xff0c;講解如何嵌入性能檢測與自動化優化機制&#xff0c;并使用結構化流程圖直觀展示關…

P7 QT項目----會學天氣預報(完結)

7.8 QMap 在 Qt 中&#xff0c;如果你想要將 JSON 數據解析到一個 QMap 中&#xff0c;你可以遍歷 JSON 對象的所有鍵值對&#xff0c;并將它們添加到 QMap 里。這個方法特別適合于當你的 JSON 對象是一個簡單的鍵值對集合時。以下是一個如何實現這一點的示例。 示例&#…

操作系統筆記(關于進程引入和狀態的切換)

1.前言 今天下午結束了英語的四六級考試&#xff0c;終于是結束了&#xff0c;最近的這個考試太密集&#xff0c;周四的專業基礎課考試&#xff0c;周五的這個線性代數的考試和這個周六的英語四六級考試&#xff0c;吧我都要烤焦了&#xff0c;最近也是疲于應對這個考試&#…

M1芯片macOS安裝Xinference部署大模型

如果你看的是官方手冊&#xff1a;安裝 — Xinference 千萬不要直接運行&#xff1a; pip install "xinference[all]" 會遇到幾個問題&#xff1a; 1&#xff09;Python版本如果太新可能安裝失敗 2&#xff09;全量安裝會失敗 3&#xff09;未科學上網可能會time…

【ONNX量化實戰】使用ONNX Runtime進行靜態量化

目錄 什么是量化量化實現的原理實戰準備數據執行量化 驗證量化結語 什么是量化 量化是一種常見的深度學習技術&#xff0c;其目的在于將原始的深度神經網絡權重從高位原始位數被動態縮放至低位目標尾數。例如從FP32&#xff08;32位浮點&#xff09;量化值INT8&#xff08;8位…

【量子計算】格羅弗算法

文章目錄 &#x1f50d; 一、算法原理與工作機制? 二、性能優勢&#xff1a;二次加速的體現&#x1f310; 三、應用場景?? 四、局限性與挑戰&#x1f52e; 五、未來展望&#x1f48e; 總結 格羅弗算法&#xff08;Grover’s algorithm&#xff09;是量子計算領域的核心算法之…

C++ 互斥量

在 C 中&#xff0c;互斥量&#xff08;std::mutex&#xff09;是一種用于多線程編程中保護共享資源的機制&#xff0c;防止多個線程同時訪問某個資源&#xff0c;從而避免數據競爭&#xff08;data race&#xff09;和不一致的問題。 &#x1f512; 一、基礎用法&#xff1a;s…