基于coze+微信小程序的ai對話

界面介紹:

代碼:(替換你的coze的配置)

<template><view class="container"><!-- 高斯模糊背景 --><view class="animated-bg"><view class="gradient-blob"></view><view class="gradient-blob two"></view><view class="gradient-blob three"></view><view class="gradient-blob four"></view><view class="overlay"></view></view><!-- 返回按鈕 --><view class="back-button" @tap="goBack"><text class="back-icon">←</text><text class="back-text">返回</text></view><!-- 頭部區域 --><view class="header"><text class="logo-text">AI Assistant</text><text class="subtitle">智能學習英語,探索無限可能</text></view><!-- 搜索區域 --><view class="search-section" :class="{ 'search-focused': isFocused }"><view class="search-box"><text class="search-icon">🔍</text><input class="search-input" type="text" v-model="searchQuery"placeholder="探索任何英語問題..."@focus="handleFocus"@blur="handleBlur"@confirm="handleSearch"/><view v-if="searchQuery" @tap="clearSearch" class="clear-btn"><text class="clear-icon">?</text></view></view></view><!-- 內容區域 --><scroll-view class="content-section" scroll-y :class="{ 'has-result': searchResult }"><!-- 默認狀態 --><view class="welcome-section" v-if="!searchResult && !loading"><view class="feature-cards"><view class="feature-card"><text class="card-icon">💡</text><text class="card-title">智能問答</text></view><view class="feature-card"><text class="card-icon">🎯</text><text class="card-title">精準解析</text></view><view class="feature-card"><text class="card-icon">🚀</text><text class="card-title">即時響應</text></view></view><view class="quick-starts"><text class="section-title">快速開始</text><view class="suggestion-chips"><text class="chip" @tap="useExample('講解英語的發展歷程')">英語簡史</text><text class="chip" @tap="useExample('如何有效的學習英語?')">英語學習方法</text><text class="chip" @tap="useExample('如何提高學習效率?')">提高英語學習效率</text></view></view></view><!-- 加載狀態 --><view class="loading-state" v-if="loading"><view class="pulse-loader"><view class="pulse"></view><view class="pulse"></view><view class="pulse"></view></view><text class="loading-text">AI 思考中...</text></view><!-- 結果展示 --><view class="result-wrapper" v-if="searchResult"><view class="result-card"><view class="result-header"><text class="ai-badge">AI</text><text class="timestamp">{{new Date().toLocaleTimeString()}}</text></view><text class="result-text">{{searchResult}}</text></view><!-- 跟進問題 --><view class="follow-up-section" v-if="followUpQuestions.length"><text class="section-title">延伸思考</text><view class="follow-up-list"><view class="follow-up-item" v-for="(question, index) in followUpQuestions" :key="index"@tap="useExample(question)"><text class="follow-up-icon">?</text><text class="follow-up-text">{{question}}</text></view></view></view></view></scroll-view></view>
</template><script>export default {data() {return {searchQuery: '',searchResult: '',followUpQuestions: [],loading: false,isFocused: false,// Coze API 配置cozeConfig: {apiUrl: 'https://api.coze.cn/open_api/v2/chat',token: '', // 替換為您的訪問令牌botId: '', // 替換為您的機器人IDuserId: '' // 用戶ID,可以根據需要修改}}},methods: {// 返回上一頁goBack() {uni.navigateBack({delta: 1 // 返回的頁面層數,1 表示返回上一頁});},handleFocus() {this.isFocused = true},handleBlur() {this.isFocused = false},clearSearch() {this.searchQuery = ''this.searchResult = ''},useExample(text) {this.searchQuery = textthis.handleSearch()},async handleSearch() {if (!this.searchQuery.trim()) {uni.showToast({title: '請輸入搜索內容',icon: 'none'});return;}this.loading = true;this.followUpQuestions = [];try {const response = await uni.request({url: this.cozeConfig.apiUrl,method: 'POST',header: {'Authorization': `Bearer ${this.cozeConfig.token}`,'Content-Type': 'application/json','Accept': '*/*','Host': 'api.coze.cn','Connection': 'keep-alive'},data: {conversation_id: Date.now().toString(),bot_id: this.cozeConfig.botId,user: this.cozeConfig.userId,query: this.searchQuery,stream: false}});// 解析響應const responseData = response[1].data; // 第二個元素才是實際數據if (responseData.code === 0) {const messages = responseData.messages || [];// 只獲取類型為 answer 的第一條消息作為核心回答const answer = messages.find(msg => msg.type === 'answer');if (answer) {// 移除可能的 verbose 信息和系統提示let cleanAnswer = answer.content.replace(/\{.*?\}/g, '') // 移除 JSON 格式的內容.replace(/\[.*?\]/g, '') // 移除方括號內的內容.trim();this.searchResult = cleanAnswer;}// 獲取跟進問題const followUps = messages.filter(msg => msg.type === 'follow_up');if (followUps.length > 0) {this.followUpQuestions = followUps.map(q => q.content);}} else {throw new Error('API 請求失敗');}} catch (error) {console.error('API Error:', error);uni.showToast({title: '搜索失敗,請重試',icon: 'none'});} finally {this.loading = false;}}}}
</script><style>.container {min-height: 100vh;position: relative;overflow: hidden;background: #f8f9fa;}.animated-bg {position: fixed;width: 100%;height: 100%;top: 0;left: 0;overflow: hidden;z-index: 0;background: linear-gradient(125deg, #00fff3, #ff00e6);animation: gradientBG 15s ease infinite;}.gradient-blob {position: absolute;width: 1000rpx;height: 1000rpx;background: linear-gradient(45deg,rgba(255, 49, 97, 0.5),rgba(255, 97, 162, 0.5));border-radius: 50%;filter: blur(80px);animation: blob-movement 20s infinite linear,color-shift 10s infinite alternate;opacity: 0.7;top: -300rpx;left: -300rpx;}.gradient-blob.two {background: linear-gradient(45deg,rgba(67, 206, 162, 0.5),rgba(24, 90, 157, 0.5));animation: blob-movement-2 25s infinite linear,color-shift-2 12s infinite alternate;animation-delay: -3s;top: 60%;left: 60%;}.gradient-blob.three {background: linear-gradient(45deg,rgba(255, 197, 84, 0.5),rgba(255, 159, 0, 0.5));animation: blob-movement-3 30s infinite linear,color-shift-3 8s infinite alternate;animation-delay: -5s;top: 40%;left: 30%;}.gradient-blob.four {background: linear-gradient(45deg,rgba(147, 88, 255, 0.5),rgba(19, 123, 255, 0.5));animation: blob-movement-4 28s infinite linear,color-shift-4 15s infinite alternate;animation-delay: -7s;top: 20%;left: 70%;}.overlay {position: absolute;top: 0;left: 0;right: 0;bottom: 0;background: rgba(255, 255, 255, 0.2);backdrop-filter: blur(20px);}@keyframes gradientBG {0% {background-position: 0% 50%;}50% {background-position: 100% 50%;}100% {background-position: 0% 50%;}}@keyframes blob-movement {0% {transform: translate(0, 0) scale(1) rotate(0deg);}33% {transform: translate(300rpx, 200rpx) scale(1.2) rotate(120deg);}66% {transform: translate(-200rpx, 400rpx) scale(0.8) rotate(240deg);}100% {transform: translate(0, 0) scale(1) rotate(360deg);}}@keyframes blob-movement-2 {0% {transform: translate(0, 0) scale(1.1) rotate(0deg);}33% {transform: translate(-250rpx, -300rpx) scale(0.9) rotate(120deg);}66% {transform: translate(300rpx, -200rpx) scale(1.2) rotate(240deg);}100% {transform: translate(0, 0) scale(1.1) rotate(360deg);}}@keyframes blob-movement-3 {0% {transform: translate(0, 0) scale(0.9) rotate(0deg);}33% {transform: translate(400rpx, -100rpx) scale(1.1) rotate(120deg);}66% {transform: translate(-300rpx, 200rpx) scale(0.8) rotate(240deg);}100% {transform: translate(0, 0) scale(0.9) rotate(360deg);}}@keyframes blob-movement-4 {0% {transform: translate(0, 0) scale(1) rotate(0deg);}33% {transform: translate(-200rpx, 300rpx) scale(1.1) rotate(120deg);}66% {transform: translate(250rpx, -250rpx) scale(0.9) rotate(240deg);}100% {transform: translate(0, 0) scale(1) rotate(360deg);}}@keyframes color-shift {0% {background: linear-gradient(45deg, rgba(255, 49, 97, 0.5), rgba(255, 97, 162, 0.5));}100% {background: linear-gradient(45deg, rgba(255, 182, 193, 0.5), rgba(255, 20, 147, 0.5));}}@keyframes color-shift-2 {0% {background: linear-gradient(45deg, rgba(67, 206, 162, 0.5), rgba(24, 90, 157, 0.5));}100% {background: linear-gradient(45deg, rgba(0, 255, 255, 0.5), rgba(0, 128, 128, 0.5));}}@keyframes color-shift-3 {0% {background: linear-gradient(45deg, rgba(255, 197, 84, 0.5), rgba(255, 159, 0, 0.5));}100% {background: linear-gradient(45deg, rgba(255, 215, 0, 0.5), rgba(255, 140, 0, 0.5));}}@keyframes color-shift-4 {0% {background: linear-gradient(45deg, rgba(147, 88, 255, 0.5), rgba(19, 123, 255, 0.5));}100% {background: linear-gradient(45deg, rgba(138, 43, 226, 0.5), rgba(65, 105, 225, 0.5));}}/* 頭部樣式 */.header {padding: 60rpx 40rpx;text-align: center;z-index: 1;position: relative;}.logo-text {font-size: 48rpx;color: #1a1a1a;font-weight: 600;letter-spacing: 2rpx;text-shadow: 0 2px 4px rgba(255, 255, 255, 0.2);}.subtitle {font-size: 28rpx;color: rgba(0, 0, 0, 0.7);margin-top: 16rpx;display: block;}/* 搜索框樣式 */.search-section {padding: 20rpx 40rpx;position: relative;z-index: 2;}.search-box {background: rgba(255, 255, 255, 0.2);backdrop-filter: blur(20px);border-radius: 20rpx;padding: 24rpx 32rpx;display: flex;align-items: center;border: 1px solid rgba(255, 255, 255, 0.3);transition: all 0.3s ease;}.search-box:hover {background: rgba(255,255,255,0.15);}.search-input {flex: 1;margin: 0 20rpx;font-size: 32rpx;color: #1a1a1a;height: 48rpx;line-height: 48rpx;}.search-icon, .clear-icon {font-size: 32rpx;color: rgba(255,255,255,0.6);}/* 功能卡片 */.feature-cards {display: flex;justify-content: space-around;padding: 40rpx;gap: 20rpx;}.feature-card {background: rgba(255, 255, 255, 0.2);backdrop-filter: blur(10px);border-radius: 16rpx;padding: 30rpx;text-align: center;flex: 1;border: 1px solid rgba(255, 255, 255, 0.3);transition: all 0.3s ease;}.feature-card:active {transform: scale(0.98);background: rgba(255,255,255,0.15);}.card-icon {font-size: 48rpx;margin-bottom: 16rpx;display: block;}.card-title {color: #fff;font-size: 28rpx;}/* 建議詞條 */.quick-starts {padding: 40rpx;}.section-title {color: rgba(0, 0, 0, 0.7);font-size: 28rpx;margin-bottom: 20rpx;display: block;}.suggestion-chips {display: flex;flex-wrap: wrap;gap: 16rpx;}.chip {background: rgba(255,255,255,0.1);padding: 16rpx 32rpx;border-radius: 100rpx;color: #fff;font-size: 28rpx;transition: all 0.3s ease;}.chip:active {background: rgba(255,255,255,0.2);transform: scale(0.98);}/* 加載動畫 */.loading-state {padding: 60rpx;text-align: center;}.pulse-loader {display: flex;justify-content: center;gap: 12rpx;}.pulse {width: 16rpx;height: 16rpx;background: #fff;border-radius: 50%;animation: pulse 1.5s infinite ease-in-out;}.pulse:nth-child(2) { animation-delay: 0.2s; }.pulse:nth-child(3) { animation-delay: 0.4s; }@keyframes pulse {0%, 100% { transform: scale(0.5); opacity: 0.2; }50% { transform: scale(1); opacity: 1; }}.loading-text {color: rgba(255,255,255,0.7);font-size: 28rpx;margin-top: 20rpx;display: block;}/* 結果卡片 */.result-wrapper {padding: 40rpx;}.result-card {background: rgba(255, 255, 255, 0.2);backdrop-filter: blur(15px);border-radius: 20rpx;padding: 30rpx;border: 1px solid rgba(255, 255, 255, 0.3);animation: slideUp 0.3s ease;}.result-header {display: flex;justify-content: space-between;align-items: center;margin-bottom: 20rpx;}.ai-badge {background: linear-gradient(135deg, #7C3AED, #3B82F6);color: #fff;padding: 6rpx 16rpx;border-radius: 8rpx;font-size: 24rpx;}.timestamp {color: rgba(255,255,255,0.5);font-size: 24rpx;}.result-text {color: #1a1a1a;font-size: 30rpx;line-height: 1.6;}/* 跟進問題 */.follow-up-section {margin-top: 40rpx;}.follow-up-list {display: flex;flex-direction: column;gap: 16rpx;}.follow-up-item {background: rgba(255, 255, 255, 0.15);padding: 24rpx;border-radius: 16rpx;display: flex;align-items: center;transition: all 0.3s ease;backdrop-filter: blur(10px);}.follow-up-item:active {background: rgba(255,255,255,0.15);transform: translateX(10rpx);}.follow-up-icon {color: rgba(255,255,255,0.5);margin-right: 16rpx;font-size: 24rpx;}.follow-up-text {color: #1a1a1a;font-size: 28rpx;}@keyframes slideUp {from { opacity: 0;transform: translateY(20rpx);}to {opacity: 1;transform: translateY(0);}}.search-input::placeholder {color: rgba(0, 0, 0, 0.4);}.back-button {position: fixed;top: 40rpx;left: 20rpx;display: flex;align-items: center;padding: 10rpx 20rpx;background: rgba(255, 255, 255, 0.8);border-radius: 50rpx;backdrop-filter: blur(10px);z-index: 999;box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);}.back-icon {font-size: 36rpx;margin-right: 10rpx;color: #333;}.back-text {font-size: 28rpx;color: #333;}
</style>

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

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

相關文章

Day11,Hot100(貪心算法)

貪心 &#xff08;1&#xff09;121. 買賣股票的最佳時機 第 i 天賣出的最大利潤&#xff0c;即在前面最低價的時候買入 class Solution:def maxProfit(self, prices: List[int]) -> int:min_price prices[0]ans 0for price in prices:ans max(ans, price - min_price…

Linux內核自定義協議族開發指南:理解net_device_ops、proto_ops與net_proto_family

在Linux內核中開發自定義協議族需要深入理解網絡協議棧的分層模型。net_device_ops、proto_ops和net_proto_family是三個關鍵結構體,分別作用于不同的層次。本文將詳細解析它們的作用、交互關系及實現方法,并提供一個完整的開發框架。 一、核心結構體的作用與層級關系 struct…

SpringBoot 中的 Redis 序列化

SpringBoot 中的 Redis 序列化 在 Spring Boot 中&#xff0c;Redis 的序列化是指將 Java 對象轉換為字節流&#xff08;序列化&#xff09;以便存儲到 Redis 中&#xff0c;以及從 Redis 中讀取字節流并將其轉換回 Java 對象&#xff08;反序列化&#xff09;。 這是因為在 R…

vLLM服務設置開機自啟動(Linux)

要在開機時進入指定的 conda 環境并啟動此 vllm 服務&#xff0c;您可以通過以下步驟設置一個 systemd 服務來自動執行腳本。 一、第一步&#xff1a;創建一個啟動腳本 1.打開終端并創建啟動腳本&#xff0c;例如 /home/username/start_vllm.sh&#xff08;請替換 username 為…

AI繪畫軟件Stable Diffusion詳解教程(3):Windows系統本地化部署操作方法(通用版)

上一篇教程介紹了如何在本地部署Stable Diffusion專業版&#xff0c;雖然便于技術人員研究&#xff0c;但是普通人使用起來不便捷&#xff0c;每次只能通過cmd窗口的指令形式或者python代碼方式來畫圖&#xff0c;要記很多的指令很繁瑣。 本篇教程教您搭建webui版的&#xff0…

大數據SQL調優專題——調優切入

引入 我們都知道大數據的SQL優化&#xff0c;并非一蹴而就的簡單任務&#xff0c;而是一個涉及多個環節的復雜過程。雖然我們的專欄名字叫大數據SQL調優&#xff0c;但是調優并不是簡單對SQL優化&#xff0c;而是一個涉及多個環節的復雜過程。實際上從需求接入到最終交付&…

貪心算法精品題

1.找錢問題 本題的貪心策略在于我們希望就可能的保留作用大的5元 class Solution { public:bool lemonadeChange(vector<int>& bills) {std::map<int ,int> _map;for(auto ch:bills){if(ch 5) _map[ch];else if(ch 10){if(_map[5] 0) return false;else{_m…

spring結合mybatis多租戶實現單庫分表

實現單庫分表 思路&#xff1a;student表數據量大&#xff0c;所以將其進行分表處理。一共有三個分表&#xff0c;分別是student0&#xff0c;student1&#xff0c;student2&#xff0c;在新增數據的時候&#xff0c;根據請求頭中的meta-tenant參數決定數據存在哪張表表。 數…

Ecode前后端傳值

說明 在泛微 E9 系統開發過程中&#xff0c;使用 Ecode 調用后端接口并進行傳值是極為常見且關鍵的操作。在上一篇文章中&#xff0c;我們探討了 Ecode 調用后端代碼的相關內容&#xff0c;本文將深入剖析在 Ecode 中如何向后端傳值&#xff0c;以及后端又該如何處理接收這些值…

黑馬Java面試教程_P5_微服務

系列博客目錄 文章目錄 系列博客目錄1.引言2.Spring Cloud2.1 Spring Cloud 5大組件有哪些?面試文稿 2.2 服務注冊和發現是什么意思?Spring Cloud 如何實現服務注冊發現?面試文稿 2.3 我看你之前也用過nacos、你能說下nacos與eureka的區別?面試文稿 2.4 你們項目負載均衡如…

【2025深度學習環境搭建-2】pytorch+Docker+VS Code+DevContainer搭建本地深度學習環境

上一篇文章&#xff1a;【2025深度學習環境搭建-1】在Win11上用WSL2和Docker解鎖GPU加速 先啟動Docker&#xff01;對文件內容有疑問&#xff0c;就去問AI 一、用Docker拉取pytorch鏡像&#xff0c;啟動容器&#xff0c;測試GPU docker pull pytorch/pytorch:2.5.0-cuda12.4…

Linux驅動開發實戰(一):LED控制驅動詳解

Linux驅動開發野火實戰&#xff08;一&#xff09;&#xff1a;LED控制驅動詳解 文章目錄 Linux驅動開發野火實戰&#xff08;一&#xff09;&#xff1a;LED控制驅動詳解引言一、基礎知識1.1 什么是字符設備驅動1.2 重要的數據結構read 函數write 函數open 函數release 函數 二…

Linux上用C++和GCC開發程序實現不同MySQL實例下單個Schema之間的穩定高效的數據遷移

設計一個在Linux上運行的GCC C程序&#xff0c;同時連接兩個不同的MySQL實例&#xff0c;兩個實例中分別有兩個Schema的表結構完全相同&#xff0c;復制一個實例中一個Schema里的所有表的數據到另一個實例中一個Schema里&#xff0c;使用以下快速高效的方法&#xff0c;加入異常…

Redis除了做緩存還能做什么?

Redis 除了作為高性能緩存外&#xff0c;還因其豐富的數據結構和功能&#xff0c;廣泛應用于多種場景。以下是 Redis 的十大核心用途及具體示例&#xff1a; 1. 分布式會話存儲 用途&#xff1a;存儲用戶會話信息&#xff08;如登錄狀態&#xff09;&#xff0c;實現多服務間共…

JBoltAI_SpringBoot如何區分DeepSeek R1深度思考和具體回答的內容(基于Ollama)?

當我們用Ollama運行DeepSeek R1模型&#xff0c;向它提問時&#xff0c;會發現它的回答里是有think標簽的 如果我們直接將Ollama的回復用于生產環境&#xff0c;肯定是不行的&#xff0c;對于不同的場景&#xff0c;前面輸出的一堆內容&#xff0c;可能并不需要在客戶端展示&a…

MySQL 使用 `WHERE` 子句時 `COUNT(*)`、`COUNT(1)` 和 `COUNT(column)` 的區別解析

文章目錄 1. COUNT() 函數的基本作用2. COUNT(*)、COUNT(1) 和 COUNT(column) 的詳細對比2.1 COUNT(*) —— 統計所有符合條件的行2.2 COUNT(1) —— 統計所有符合條件的行2.3 COUNT(column) —— 統計某一列非 NULL 的記錄數 3. 性能對比3.1 EXPLAIN 分析 4. 哪種方式更好&…

將DeepSeek接入vscode的N種方法

接入deepseek方法一:cline 步驟1:安裝 Visual Studio Code 后,左側導航欄上點擊擴展。 步驟2:搜索 cline,找到插件后點擊安裝。 步驟3:在大模型下拉菜單中找到deep seek,然后下面的輸入框輸入你在deepseek申請的api key,就可以用了 讓deepseek給我寫了一首關于天氣的…

AndroidManifest.xml文件的作用

AndroidManifest.xml文件在Android應用程序中扮演著至關重要的角色。它是應用程序的全局配置文件&#xff0c;提供了關于應用程序的所有必要信息&#xff0c;這些信息對于Android系統來說是至關重要的&#xff0c;因為它決定了應用程序的運行方式和權限要求&#xff0c;確保了應…

Mac本地部署Deep Seek R1

Mac本地部署Deep Seek R1 1.安裝本地部署大型語言模型的工具 ollama 官網&#xff1a;https://ollama.com/ 2.下載Deepseek R1模型 網址&#xff1a;https://ollama.com/library/deepseek-r1 根據電腦配置&#xff0c;選擇模型。 我的電腦&#xff1a;Mac M3 24G內存。 這…

React進階之前端業務Hooks庫(五)

前端業務Hooks庫 Hooks原理useStateuseEffect上述問題useState,useEffect 復用的能力練習:怎樣實現一套React過程中的hooks狀態 & 副作用Hooks原理 不能在循環中、條件判斷、子函數中調用,只能在函數最外層去調用useEffect 中,deps 為空,執行一次useState 使用: imp…