在騰訊云CodeBuddy上實現一個AI聊天助手

在騰訊云CodeBuddy上實現一個AI聊天助手項目

在當今數字化時代,AI聊天助手已經成為一種非常流行的應用,廣泛應用于客戶服務、智能助手等領域。今天,我們將通過騰訊云CodeBuddy平臺,實現一個基于Spring Boot和OpenAI API的AI聊天助手項目。這個項目將幫助你快速搭建一個功能強大的聊天助手,同時展示騰訊云CodeBuddy的強大開發能力。

項目背景

我們選擇的項目是 Spring AI 聊天助手,這是一個基于Spring Boot和OpenAI API的開源項目。它使用了DeepSeek-R1-Distill-Llama-8B模型,通過SiliconFlow API提供服務。這個項目具備以下功能特點:

  • 基于Spring AI框架實現的聊天功能
  • 使用OpenAI兼容的API接口
  • 響應式Web界面
  • 聊天歷史記錄管理
  • 支持代碼高亮顯示

環境準備

在開始之前,我們需要準備以下環境和工具:

  • 騰訊云CodeBuddy賬號:用于開發和部署項目。
  • JDK 17或更高版本:用于運行Spring Boot項目。
  • Maven 3.6或更高版本:用于項目構建。
  • OpenAI API密鑰或兼容的API密鑰:用于接入AI服務。

項目搭建

1. 安裝好CodeBuddy

首先,我們需要安裝好CodeBuddy,可以參考我上一篇博客,然后在項目里給出命令,讓AI創建代碼,要加上技術棧和版本,比如本博客使用的版本是1.0.0-M5

API交互截圖
這個過程比較長,需要一點引導AI創建修改代碼

2. 配置項目

在騰訊云CodeBuddy中,找到項目的 application.yml 文件,進行以下配置:

spring:ai:openai:api-key: your-api-key-herebase-url: https://api.siliconflow.cnchat:options:model: deepseek-ai/DeepSeek-R1-Distill-Llama-8B

你也可以通過環境變量設置API密鑰,例如:

export OPENAI_API_KEY=your-api-key-here

3. 構建和運行項目

在騰訊云CodeBuddy的終端中,運行以下命令構建項目:

mvn clean package

構建完成后,運行項目:

java -jar target/springboot-ai-chatbot-0.0.1-SNAPSHOT.jar

項目將在 http://localhost:8080 上運行。你可以通過瀏覽器訪問該地址,開始使用AI聊天助手。

4. 使用Web界面與AI交互

打開瀏覽器,訪問 http://localhost:8080。在輸入框中輸入你的問題,點擊“發送”按鈕或按Enter鍵,即可查看AI助手的回復。

5. 通過API與AI交互

你也可以通過API與AI進行交互。以下是幾個常用的API端點:

  • 發送聊天消息

    curl -X POST http://localhost:8080/api/chat \-H "Content-Type: application/json" \-d '{"message":"你好,請介紹一下自己"}'
    
  • 獲取聊天歷史

    curl -X GET http://localhost:8080/api/chat/history
    
  • 清除聊天歷史

    curl -X POST http://localhost:8080/api/chat/clear
    

代碼說明

1. ChatService.java

ChatService.java 是項目的核心服務類,它負責與OpenAI API進行交互,處理聊天邏輯。以下是代碼的關鍵部分:

package com.example.chatbot.service;import com.example.chatbot.exception.ChatException;
import com.example.chatbot.model.ChatMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;@Service
public class ChatService {private static final Logger log = LoggerFactory.getLogger(ChatService.class);private final ChatClient chatClient;private final String systemPrompt;private final int maxHistorySize;private final List<Message> chatHistory = new ArrayList<>();private final ReentrantLock historyLock = new ReentrantLock();public ChatService(ChatClient.Builder builder,@Value("${spring.ai.openai.system-prompt:你是一個友好、樂于助人的AI助手。請提供簡潔、準確的回答。}") String systemPrompt,@Value("${spring.ai.chat.history.max-size:50}") int maxHistorySize) {this.chatClient = builder.defaultSystem(systemPrompt).build();this.systemPrompt = systemPrompt;this.maxHistorySize = maxHistorySize;initializeChatHistory();}/*** 初始化聊天歷史,添加系統消息*/private void initializeChatHistory() {historyLock.lock();try {chatHistory.clear();chatHistory.add(new SystemMessage(systemPrompt));log.info("聊天歷史已初始化,系統提示: {}", systemPrompt);} finally {historyLock.unlock();}}/*** 處理聊天請求* @param userInput 用戶輸入內容* @return AI響應內容*/public String chat(String userInput) {if (userInput == null || userInput.trim().isEmpty()) {throw new ChatException("輸入內容不能為空");}try {String processedInput = userInput.trim();log.info("收到用戶輸入: {}", processedInput);// 添加用戶消息到歷史記錄UserMessage userMessage = new UserMessage(processedInput);addToHistory(userMessage);// 檢查歷史記錄大小,超過限制則清理trimHistoryIfNeeded();// 創建提示并獲取響應(直接使用框架Message列表)Prompt prompt = new Prompt(new ArrayList<>(getFrameworkChatHistory()));log.info("發送請求到AI模型,歷史消息數量: {}", prompt.getInstructions().size());String responseContent = chatClient.prompt(prompt).call().chatResponse().getResult().getOutput().getContent();// 處理空響應if (responseContent == null || responseContent.trim().isEmpty()) {responseContent = "抱歉,未能生成有效響應,請嘗試重新提問。";log.warn("AI返回空響應,使用默認回復");}// 添加助手響應到歷史記錄addToHistory(new AssistantMessage(responseContent));log.info("AI響應處理完成,響應長度: {}", responseContent.length());return responseContent;} catch (Exception e) {log.error("處理聊天請求失敗", e);throw new ChatException("處理聊天請求失敗: " + e.getMessage(), e);}}/*** 獲取前端需要的聊天歷史(不含系統消息)* @return 聊天歷史列表*/public List<ChatMessage> getChatHistory() {historyLock.lock();try {return chatHistory.stream().skip(1) // 跳過系統消息.map(message -> {String role = message instanceof UserMessage ? "user" : "assistant";return new ChatMessage(role, message.getContent());}).collect(Collectors.toList());} finally {historyLock.unlock();}}/*** 獲取框架需要的完整聊天歷史(包含系統消息)* @return 框架消息列表*/private List<Message> getFrameworkChatHistory() {historyLock.lock();try {return new ArrayList<>(chatHistory);} finally {historyLock.unlock();}}/*** 清除聊天歷史*/public void clearHistory() {initializeChatHistory();log.info("聊天歷史已清除");}/*** 添加消息到歷史記錄*/private void addToHistory(Message message) {historyLock.lock();try {chatHistory.add(message);log.debug("添加消息到歷史,角色: {}, 內容長度: {}",message.getClass().getSimpleName(),message.getContent().length());} finally {historyLock.unlock();}}/*** 如果歷史記錄超過最大限制,清理部分歷史*/private void trimHistoryIfNeeded() {historyLock.lock();try {// 保留系統消息,只清理用戶和助手的消息if (chatHistory.size() > maxHistorySize) {int messagesToRemove = chatHistory.size() - maxHistorySize;for (int i = 0; i < messagesToRemove; i++) {chatHistory.remove(1); // 從索引1開始刪除(保留系統消息)}log.info("聊天歷史已修剪,移除了 {} 條消息,當前大小: {}",messagesToRemove, chatHistory.size());}} finally {historyLock.unlock();}}
}
  • OpenAIClient:這是Spring AI提供的客戶端,用于與OpenAI API進行交互。
  • ChatRequest:這是發送給AI的請求對象,包含用戶的消息。
  • ChatResponse:這是從AI返回的響應對象,包含AI的回復。

2. ChatController.java

ChatController.java 是項目的控制器類,負責處理HTTP請求和響應。以下是代碼的關鍵部分:

package com.example.chatbot.controller;import com.example.chatbot.model.ChatMessage;
import com.example.chatbot.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;import java.util.List;
import java.util.Map;@RestController
@RequestMapping("/api/chat")
public class ChatController {private final ChatService chatService;@Autowiredpublic ChatController(ChatService chatService) {this.chatService = chatService;}@PostMappingpublic ResponseEntity<ChatMessage> chat(@RequestBody Map<String, String> request) {String userMessage = request.get("message");String response = chatService.chat(userMessage);return ResponseEntity.ok(new ChatMessage("assistant", response));}@GetMapping("/history")public ResponseEntity<List<ChatMessage>> getChatHistory() {return ResponseEntity.ok(chatService.getChatHistory());}@PostMapping("/clear")public ResponseEntity<Void> clearHistory() {chatService.clearHistory();return ResponseEntity.ok().build();}
}
  • @PostMapping:處理發送聊天消息的POST請求。
  • @GetMapping("/history"):處理獲取聊天歷史的GET請求。
  • @PostMapping("/clear"):處理清除聊天歷史的POST請求。

3. index.html

index.html 是項目的前端頁面,提供了一個響應式的Web界面,用戶可以通過這個界面與AI進行交互。以下是代碼的關鍵部分:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI 聊天助手</title><!-- 引入Tailwind CSS --><script src="https://cdn.tailwindcss.com"></script><!-- 引入Font Awesome --><link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet"><!-- 配置Tailwind自定義顏色和字體 --><script>tailwind.config = {theme: {extend: {colors: {primary: '#3B82F6',secondary: '#10B981',neutral: '#F3F4F6',dark: '#1F2937',light: '#F9FAFB'},fontFamily: {inter: ['Inter', 'system-ui', 'sans-serif'],},}}}</script><style type="text/tailwindcss">@layer utilities {.content-auto {content-visibility: auto;}.message-appear {animation: fadeIn 0.3s ease-out forwards;}.typing-pulse span {animation: pulse 1.4s infinite ease-in-out both;}.typing-pulse span:nth-child(1) { animation-delay: -0.32s; }.typing-pulse span:nth-child(2) { animation-delay: -0.16s; }}@keyframes fadeIn {from { opacity: 0; transform: translateY(10px); }to { opacity: 1; transform: translateY(0); }}@keyframes pulse {0%, 80%, 100% { transform: scale(0); }40% { transform: scale(1); }}</style>
</head>
<body class="font-inter bg-gradient-to-br from-light to-neutral min-h-screen flex flex-col">
<!-- 頂部導航欄 -->
<header class="bg-white shadow-md py-4 px-6 sticky top-0 z-10"><div class="max-w-4xl mx-auto flex items-center justify-between"><div class="flex items-center gap-2"><i class="fa fa-comments text-primary text-2xl"></i><h1 class="text-[clamp(1.25rem,3vw,1.75rem)] font-bold text-dark">AI 聊天助手</h1></div><div class="text-sm text-gray-500"><span class="flex items-center gap-1"><span class="h-2 w-2 bg-green-500 rounded-full animate-pulse"></span>在線</span></div></div>
</header><!-- 主內容區 -->
<main class="flex-grow flex flex-col max-w-4xl w-full mx-auto w-full px-4 py-6 md:py-8"><!-- 聊天容器 --><div class="chat-container bg-white rounded-2xl shadow-lg p-4 md:p-6 h-[70vh] overflow-y-auto mb-6"><div th:each="message : ${chatHistory}"><div th:class="${message.role == 'user' ? 'message user-message' : 'message assistant-message'}"th:utext="${#strings.replace(#strings.escapeXml(message.content), '&#10;', '<br/>')}"></div></div><!-- 輸入指示器 --><div class="message assistant-message typing opacity-0" id="typing-indicator"><div class="flex items-center gap-2"><div class="w-2 h-2 bg-gray-400 rounded-full typing-pulse"><span class="absolute w-2 h-2 bg-gray-400 rounded-full"></span><span class="absolute w-2 h-2 bg-gray-400 rounded-full ml-3"></span><span class="absolute w-2 h-2 bg-gray-400 rounded-full ml-6"></span></div><span>正在思考...</span></div></div></div><!-- 輸入區域 --><div class="input-container bg-white rounded-2xl shadow-md p-3 flex gap-3"><inputtype="text"id="user-input"placeholder="輸入你的問題..."autocomplete="off"class="flex-grow px-4 py-3 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 outline-none transition-all"><button id="send-btn" class="bg-primary hover:bg-primary/90 text-white p-3 rounded-xl transition-all shadow-md hover:shadow-lg flex items-center justify-center"><i class="fa fa-paper-plane"></i></button><button id="clear-btn" class="bg-gray-200 hover:bg-gray-300 text-gray-700 p-3 rounded-xl transition-all shadow-sm hover:shadow"><i class="fa fa-trash"></i></button></div>
</main><!-- 頁腳 -->
<footer class="py-4 px-6 text-center text-gray-500 text-sm"><p>? 2025 AI 聊天助手 | 提供智能對話服務</p>
</footer><script>document.addEventListener('DOMContentLoaded', function() {const chatContainer = document.querySelector('.chat-container');const userInput = document.getElementById('user-input');const sendBtn = document.getElementById('send-btn');const clearBtn = document.getElementById('clear-btn');const typingIndicator = document.getElementById('typing-indicator');// 滾動到底部function scrollToBottom() {chatContainer.scrollTop = chatContainer.scrollHeight;}// 初始滾動到底部scrollToBottom();// 添加消息到聊天界面function addMessage(content, isUser) {const messageDiv = document.createElement('div');messageDiv.className = `message message-appear ${isUser ? 'user-message' : 'assistant-message'} mb-4 opacity-0`;// 處理代碼塊格式if (content.includes('```')) {content = content.replace(/```([\s\S]*?)```/g,'<pre class="bg-gray-100 p-3 rounded-lg my-2 overflow-x-auto"><code>$1</code></pre>');}messageDiv.innerHTML = content.replace(/\n/g, '<br/>');chatContainer.appendChild(messageDiv);// 觸發動畫setTimeout(() => {messageDiv.classList.remove('opacity-0');}, 10);scrollToBottom();}// 發送消息function sendMessage() {const message = userInput.value.trim();if (message === '') return;// 添加用戶消息addMessage(message, true);userInput.value = '';// 顯示正在輸入指示器typingIndicator.style.display = 'block';setTimeout(() => {typingIndicator.classList.remove('opacity-0');}, 10);scrollToBottom();// 發送請求到服務器fetch('/api/chat', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify({ message: message })}).then(response => response.json()).then(data => {// 隱藏正在輸入指示器typingIndicator.classList.add('opacity-0');setTimeout(() => {typingIndicator.style.display = 'none';}, 300);// 添加AI響應addMessage(data.content, false);}).catch(error => {console.error('Error:', error);typingIndicator.classList.add('opacity-0');setTimeout(() => {typingIndicator.style.display = 'none';}, 300);addMessage('發生錯誤,請重試。', false);});}// 清除聊天歷史function clearChat() {fetch('/api/chat/clear', {method: 'POST'}).then(() => {// 清除聊天界面const messages = chatContainer.querySelectorAll('.message:not(.typing)');messages.forEach(msg => {msg.classList.add('opacity-0');setTimeout(() => msg.remove(), 300);});}).catch(error => {console.error('Error:', error);});}// 事件監聽器sendBtn.addEventListener('click', sendMessage);clearBtn.addEventListener('click', clearChat);userInput.addEventListener('keypress', function(e) {if (e.key === 'Enter') {sendMessage();}});// 樣式定義const style = document.createElement('style');style.textContent = `.user-message {background-color: #3B82F6;color: white;margin-left: auto;border-radius: 18px 18px 4px 18px;padding: 12px 18px;max-width: 75%;word-wrap: break-word;box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);}.assistant-message {background-color: #F3F4F6;color: #1F2937;margin-right: auto;border-radius: 18px 18px 18px 4px;padding: 12px 18px;max-width: 75%;word-wrap: break-word;box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);}pre {font-family: 'Consolas', 'Monaco', monospace;}.chat-container::-webkit-scrollbar {width: 6px;}.chat-container::-webkit-scrollbar-track {background: #f1f1f1;border-radius: 10px;}.chat-container::-webkit-scrollbar-thumb {background: #c1c1c1;border-radius: 10px;}.chat-container::-webkit-scrollbar-thumb:hover {background: #a8a8a8;}`;document.head.appendChild(style);});</script>
</body>
</html>
  • chat-container:聊天界面的容器。
  • chat-history:顯示聊天歷史的區域。
  • chat-input:用戶輸入消息的輸入框。
  • send-button:發送消息的按鈕。

4. scripts.js

scripts.js 是前端的JavaScript腳本,負責處理用戶輸入和與后端API的交互。以下是代碼的關鍵部分:

document.getElementById('send-button').addEventListener('click', function() {const message = document.getElementById('chat-input').value;if (message) {fetch('/api/chat', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify({ message: message })}).then(response => response.json()).then(data => {const chatHistory = document.getElementById('chat-history');chatHistory.innerHTML += `<p><strong>User:</strong> ${message}</p>`;chatHistory.innerHTML += `<p><strong>AI:</strong> ${data.choices[0].message.content}</p>`;document.getElementById('chat-input').value = '';});}
});
  • fetch:發送POST請求到后端API。
  • response.json():解析返回的JSON數據。
  • innerHTML:將聊天內容動態顯示到頁面上。

自定義項目

你可以通過修改以下文件來自定義聊天助手的行為:

  • ChatService.java:修改系統提示信息和聊天邏輯。
  • index.html:自定義Web界面。
  • application.yml:調整模型參數和API設置。

項目截圖

以下是項目運行的截圖:

項目運行截圖

總結

通過騰訊云CodeBuddy,我們快速搭建了一個基于Spring Boot和OpenAI API的AI聊天助手項目。這個項目不僅具備強大的功能,還提供了靈活的自定義選項。希望這篇文章能幫助你更好地理解和使用騰訊云CodeBuddy進行項目開發。

如果你有任何問題或建議,歡迎在評論區留言。讓我們一起探索更多有趣的技術項目!

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

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

相關文章

JavaScript Array.prototype.flatMap ():數組 “扁平化 + 映射” 的高效組合拳

在 JavaScript 數組處理中&#xff0c;我們經常需要先對每個元素進行轉換&#xff08;映射&#xff09;&#xff0c;再將結果 “鋪平”&#xff08;扁平化&#xff09;。比如將數組中的每個字符串按空格拆分&#xff0c;然后合并成一個新數組。傳統做法是先用map()轉換&#xf…

區塊鏈與元宇宙:數字資產的守護者

1 區塊鏈支撐元宇宙數字資產的底層邏輯1.1 不可篡改性構建信任基石區塊鏈的不可篡改性為元宇宙數字資產提供了堅實的信任基礎。其核心在于分布式賬本技術&#xff0c;當一筆數字資產交易發生時&#xff0c;會被打包成區塊并廣播至網絡中的所有節點。每個節點都會對這筆交易進行…

Linux軟件編程:進程和線程(進程)

進程一、基本概念進程&#xff1a;是程序動態執行過程&#xff0c;包括創建、調度、消亡程序&#xff1a;存放在外存的一段數據的集合二、進程創建&#xff08;一&#xff09;進程空間分布每個進程運行起來后&#xff0c;操作系統開辟0-4G的虛擬空間進程空間&#xff1a;用戶空…

Mybatis學習筆記(五)

分頁插件與性能優化 分頁插件配置 簡要描述&#xff1a;MybatisPlus分頁插件是基于物理分頁實現的高性能分頁解決方案&#xff0c;支持多種數據庫的分頁語法&#xff0c;能夠自動識別數據庫類型并生成對應的分頁SQL。 核心概念&#xff1a; 物理分頁&#xff1a;直接在SQL層面進…

企業可商用的conda:「Miniforge」+「conda-forge」

文章目錄一、徹底卸載現有 Anaconda/Miniconda二、安裝 Miniforge&#xff08;推薦&#xff09;macOS/Linux檢查Windows檢查三、將通道固定為 conda-forge&#xff08;嚴格優先&#xff09;四、驗證是否仍引用 Anaconda 源五、常見問題&#xff08;FAQ&#xff09;六、參考命令…

Flutter ExpansionPanel組件(可收縮的列表)

可以展開或者收縮的面板組件&#xff0c;收縮面板組件效果由ExpansionPanelList組件和ExpansionPanel組件共同完成。 ExpansionPanelList屬性說明屬性說明children子元素expansionCallback設置回調事件ExpansionPanel屬性說明headerBuilder收縮的標題body內容isExpanded設置內容…

C/C++ 進階:深入解析 GCC:從源碼到可執行程序的魔法四步曲

引言距離上一篇博客更新已經過去了大概一兩周的時間&#xff0c;而對于 Linux 系統的基本指令以及 Shell 編程的學習其實基本講解完畢&#xff0c;Linux基礎一塊的知識就將告一段落了&#xff0c;如果有細節性的知識&#xff0c;我也會及時分享給各位&#xff0c;作為一名正在攀…

云服務器運行持續強化學習COOM框架的問題

1 環境要求 下載地址&#xff1a;https://github.com/TTomilin/COOM tensorflow 2.11以上 python 3.9以上 tensorflow2.12.0&#xff0c;需要安裝tensorflow-probability0.19 2 修改代碼 COOM/wrappers/reward.py 將 from gym import RewardWrapper修改為 from gymnasium impor…

MyBatis Interceptor 深度解析與應用實踐

MyBatis Interceptor 深度解析與應用實踐 一、MyBatis Interceptor概述 1.1 什么是MyBatis Interceptor MyBatis Interceptor&#xff0c;也稱為MyBatis 插件&#xff0c;是 MyBatis 提供的一種擴展機制&#xff0c;用于在 MyBatis 執行 SQL 的過程中插入自定義邏輯。它類似…

【自動化測試】Web自動化測試 Selenium

&#x1f525;個人主頁&#xff1a; 中草藥 &#x1f525;專欄&#xff1a;【Java】登神長階 史詩般的Java成神之路 測試分類 了解各種各樣的測試方法分類&#xff0c;不是為了墨守成規按照既定方法區測試&#xff0c;而是已了解思維為核心&#xff0c;并了解一些專業名詞 根…

2025 電賽 C 題完整通關攻略:從單目標定到 2 cm 測距精度的全流程實戰

摘要 2025 年全國大學生電子設計競賽 C 題要求“僅用一顆固定攝像頭”在 5 s 內完成 100 cm~200 cm 距離、誤差 ≤2 cm 的單目測距&#xff0c;并實時顯示功耗。本文整合國一選手方案、CSDN 高分博文、B 站實測視頻及官方說明&#xff0c;給出從硬件選型→離線標定→在線算法→…

Day 10: Mini-GPT完整手寫實戰 - 從組件組裝到文本生成的端到端實現

Day 10-2: Mini-GPT完整手寫實戰 - 從組件組裝到文本生成的端到端實現 ?? 今日學習目標 掌握GPT架構組裝:將Transformer組件組裝成完整的生成模型 理解生成式預訓練:掌握自回歸語言建模的核心機制 端到端代碼實現:從數據預處理到模型訓練的完整流程 文本生成實戰:訓練Mi…

深入解析Prompt緩存機制:原理、優化與實踐經驗

深入解析Prompt緩存機制&#xff1a;原理、優化與實踐經驗 概述 在大型語言模型應用中&#xff0c;API請求的延遲和成本始終是開發者關注的核心問題。Prompt緩存&#xff08;Prompt Caching&#xff09;技術通過智能地復用重復內容&#xff0c;有效減少了API響應時間和運行成本…

CV 醫學影像分類、分割、目標檢測,之【3D肝臟分割】項目拆解

CV 醫學影像分類、分割、目標檢測&#xff0c;之【3D肝臟分割】項目拆解第1行&#xff1a;from posixpath import join第2行&#xff1a;from torch.utils.data import DataLoader第3行&#xff1a;import os第4行&#xff1a;import sys第5行&#xff1a;import random第6行&a…

Mybatis學習筆記(七)

Spring Boot集成 簡要描述&#xff1a;MyBatis-Plus與Spring Boot的深度集成&#xff0c;提供了自動配置、啟動器等特性&#xff0c;大大簡化了配置和使用。 核心概念&#xff1a; 自動配置&#xff1a;基于條件的自動配置機制啟動器&#xff1a;簡化依賴管理的starter配置屬性…

機器人伴侶的智能升級:Deepoc具身智能模型如何重塑成人伴侶體驗

引言&#xff1a;機器人伴侶市場的技術變革需求隨著人工智能技術的飛速發展和人們情感需求的多元化&#xff0c;機器人成人伴侶市場正在經歷前所未有的增長。傳統機器人伴侶已經能夠滿足基礎的交互需求&#xff0c;但在智能化、情感化和個性化方面仍存在明顯不足。這正是深算紀…

metabase基礎使用技巧 (dashboard, filter)

這是metabase系列分享文章的第2部分。本文將介紹metabase的基礎概念和使用介紹 question question是metabase中提供的通過UI化操作就能實現簡單的 快捷 直接的BI查詢。 點擊右側的New -> Question即可創建Question&#xff0c;可以理解為一個格式化的查詢&#xff1a; 這里…

機器人成人伴侶的智能化升級:Deepoc具身模型賦能沉浸式體驗

引言&#xff1a;成人機器人市場的技術革新需求隨著人工智能和機器人技術的快速發展&#xff0c;成人陪伴機器人行業正經歷從簡單機械運動到智能化交互的轉型。據市場研究數據顯示&#xff0c;全球成人機器人市場規模預計將在2026年突破100億美元&#xff0c;年復合增長率保持在…

Go語言企業級權限管理系統設計與實現

最近跟著學長再寫河南師范大學附屬中學圖書館的項目&#xff0c;學長交給了我一個任務&#xff0c;把本項目的權限管理給吃透&#xff0c;然后應用到下一個項目上。 我當然是偷著樂吶&#xff0c;因為讀代碼的時候&#xff0c;總是莫名給我一種公費旅游的感覺。 本來就想去了解…

Java應用快速部署Tomcat指南

將Java應用部署到Apache Tomcat服務器是開發Web應用過程中常見的任務。Tomcat是一個免費且開源的Servlet容器,它為Java應用提供了運行環境。本文將介紹如何準備你的Java應用,并將其部署到Tomcat服務器上。 Java 應用部署 tomcat 的根目錄結構 Tomcat中默認網站根目錄是$CAT…