腾讯云AI代码助手编程挑战赛-算法小助手

作品简介
一个可以帮助学习计算机各种算法的AI小助手,提升工作效率。

技术架构

使用Html语言完成图形化页面的样式,使用JavaScript语言来操作对应的逻辑代码。

实现过程

1、创建一个界面

2、获取数据

3、添加按钮与功能

4、程序优化调试

开发环境、开发流程

系统环境:MacOs系统

开发工具:VSCode

开发插件:腾讯云AI代码助手

关键技术解析
1.绘制页面

2.获取数据

3.解析数据

4.渲染数据

腾讯云AI代码助手在上述过程中的助力
1.生成页面

2.获取数据

3.处理数据

4.事件绑定执行

使用说明
提问各种算法问题,点击按钮,界面算法内容。

项目源码

<template><div class="chat-container"><t-chatref="chatRef"layout="single"class="chat-window":clear-history="chatList.length > 0 && !isStreamLoad"@clear="clearConfirm"><template v-for="(item, index) in chatList" :key="index"><t-chat-item:avatar="item.avatar":name="item.name":role="item.role":datetime="item.datetime":text-loading="index === 0 && loading"><template #content><div:class="['chat-bubble', item.role === 'user' ? 'user-bubble' : 'assistant-bubble']"v-html="item.content"></div></template><template v-if="!isStreamLoad" #actions><t-chat-action:is-good="isGood[index]":is-bad="isBad[index]"@operation="(type, { e }) => handleOperation(type, { e, index })"class="feedback-action"/></template></t-chat-item></template><template #footer><div class="input-area"><t-chat-input:stop-disabled="isStreamLoad"@send="inputEnter"@stop="onStop"placeholder="请输入您的问题..."/><t-buttonv-if="isStreamLoad"@click="onStop"type="danger"icon="close"circleclass="stop-button"/></div></template></t-chat><!-- 反馈表单对话框 --><t-dialogv-model:visible="showFeedbackForm":mask-closable="false":show-close="false"width="450px"class="feedback-dialog"><div class="feedback-content"><t-textareav-model="feedbackContent"placeholder="您的宝贵建议对我们非常重要!您的反馈将帮助我们持续改进!":rows="4"class="feedback-textarea"/></div><template #footer><t-button type="primary" @click="submitFeedback">提交反馈</t-button></template></t-dialog><!-- 分享对话框 --><t-dialogv-model:visible="showShareDialog"title="分享对话":mask-closable="false":show-close="false"width="400px"class="share-dialog"><div class="share-options"><t-buttonvariant="outline"icon="wechat"@click="shareToWeChatFriends"class="share-button">微信好友</t-button><t-buttonvariant="outline"icon="wechat-moments"@click="shareToWeChatMoments"class="share-button">朋友圈</t-button><t-buttonvariant="outline"icon="weibo"@click="shareToWeibo"class="share-button">微博</t-button><t-buttonvariant="outline"icon="qq"@click="shareToQQZone"class="share-button">QQ空间</t-button></div></t-dialog></div>
</template><script setup>
import { ref } from 'vue';
import { MessagePlugin } from 'tdesign-vue-next';
import { saveAs } from 'file-saver';// 反馈表单相关的状态
const showFeedbackForm = ref(false);
const feedbackType = ref(null); // 'good' 或 'bad'
const currentFeedbackIndex = ref(null);
const feedbackContent = ref('');// 分享对话框相关的状态
const showShareDialog = ref(false);// 滚动到底部
const chatRef = ref(null);
const backBottom = () => {chatRef.value.scrollToBottom({behavior: 'smooth',});
};// 初始化聊天记录,仅保留初始机器人问候
const chatList = ref([{avatar: 'https://tdesign.gtimg.com/site/chat-avatar.png', // 小美的头像链接name: '客服小Ai',datetime: new Date().toLocaleString(),content: '早上好,我是你的鹅厂助理小Ai,我熟知计算机各种算法和数据结构,请问你有什么帮助?',role: 'assistant',},
]);// 初始化 isGood 和 isBad 数组
const isGood = ref([]);
const isBad = ref([]);const initializeFeedbackStates = () => {isGood.value = chatList.value.map(() => false);isBad.value = chatList.value.map(() => false);
};initializeFeedbackStates();const fetchCancel = ref(null);
const loading = ref(false);
const isStreamLoad = ref(false);/*** Clears the confirmation by resetting the chat list to an empty array.*/
const clearConfirm = function () {chatList.value = [];initializeFeedbackStates();
};/*** Handles the stop event for a fetch operation.*/
const onStop = function () {if (fetchCancel.value) {fetchCancel.value.abort();loading.value = false;isStreamLoad.value = false;}
};/*** Handles different types of operations based on the provided type and options.*/
const handleOperation = function (type, options) {const { index } = options;if (type === 'good') {isGood.value[index] = !isGood.value[index];if (isGood.value[index]) {isBad.value[index] = false;// 打开反馈表单feedbackType.value = 'good';currentFeedbackIndex.value = index;showFeedbackForm.value = true;}} else if (type === 'bad') {isBad.value[index] = !isBad.value[index];if (isBad.value[index]) {isGood.value[index] = false;// 打开反馈表单feedbackType.value = 'bad';currentFeedbackIndex.value = index;showFeedbackForm.value = true;}}
};/*** 提交反馈表单*/
const submitFeedback = () => {if (currentFeedbackIndex.value === null) {MessagePlugin.error('未找到对应的消息!');return;}// 显示固定成功消息MessagePlugin.success('感谢您的反馈,我们将持续改进!');// 关闭反馈表单showFeedbackForm.value = false;
};/*** Handles the asynchronous processing of user input data.*/
const handleData = async (inputValue) => {loading.value = true;isStreamLoad.value = true;const lastItem = chatList.value[0];const messages = [{role: 'user',content: inputValue,}];fetchSSE(messages, {success(result) {loading.value = false;const { data } = result;lastItem.content += data?.delta?.content;},complete(isOk, msg) {if (!isOk || !lastItem.content) {lastItem.role = 'error';lastItem.content = msg;}// 控制终止按钮isStreamLoad.value = false;loading.value = false;},cancel(cancel) {fetchCancel.value = cancel;},});
};/*** Handles the input when the enter key is pressed.*/
const inputEnter = function (inputValue) {if (isStreamLoad.value) {return;}if (!inputValue) return;const params = {avatar: 'https://tdesign.gtimg.com/site/chat-avatar.png', // 用户的头像链接name: '您',datetime: new Date().toLocaleString(),content: inputValue,role: 'user',};chatList.value.unshift(params);// 空消息占位const params2 = {avatar: 'https://tdesign.gtimg.com/site/chat-avatar.png', // 小美的头像链接name: '客服小Ai',datetime: new Date().toLocaleString(),content: '',role: 'assistant',};chatList.value.unshift(params2);isGood.value.unshift(false);isBad.value.unshift(false);handleData(inputValue);
};/*** 解析SSE数据*/
const fetchSSE = async (messages, options) => {const { success, fail, complete, cancel } = options;const controller = new AbortController();const { signal } = controller;cancel?.(controller);// your-api-keyconst apiKey = 'sk-6R0hq8U7v3bSbT1u41Lp6kPRwAgf9wnW73WgvSC7WUI73eRO';const responsePromise = fetch('/v1/chat/completions', {method: 'POST',headers: {'Content-Type': 'application/json',Authorization: `Bearer${apiKey ? ` ${apiKey}` : ''}`,},body: JSON.stringify({messages, // 消息列表model: 'hunyuan-pro', // 模型stream: true, // 流式}),signal,}).catch((e) => {const msg = e.toString() || '流式接口异常';complete?.(false, msg);return Promise.reject(e); // 确保错误能够被后续的.catch()捕获});responsePromise.then((response) => {if (!response?.ok) {complete?.(false, response.statusText);fail?.();throw new Error('Request failed'); // 抛出错误以便链式调用中的下一个.catch()处理}const reader = response.body.getReader();const decoder = new TextDecoder();if (!reader) throw new Error('No reader available');const bufferArr = [];let dataText = ''; // 记录数据const event = { type: null, data: null };async function processText({ done, value }) {if (done) {complete?.(true);return Promise.resolve();}const chunk = decoder.decode(value);const buffers = chunk.toString().split(/\r?\n/);bufferArr.push(...buffers);let i = 0;while (i < bufferArr.length) {const line = bufferArr[i];if (line) {dataText += line;const response = line.slice(6);if (response === '[DONE]') {event.type = 'finish';dataText = '';} else {try {const choices = JSON.parse(response.trim())?.choices?.[0];if (choices.finish_reason === 'stop') {event.type = 'finish';dataText = '';} else {event.type = 'delta';event.data = choices;}} catch (error) {console.error('解析错误:', error);}}}if (event.type && event.data) {const jsonData = { ...event };success(jsonData);event.type = null;event.data = null;}bufferArr.splice(i, 1);}return reader.read().then(processText);}return reader.read().then(processText);}).catch(() => {// 处理整个链式调用过程中发生的任何错误fail?.();});
};/*** 下载对话记录*/
const downloadConversation = () => {const conversation = chatList.value.map((msg) => {const time = new Date(msg.datetime).toLocaleString();// 去除HTML标签,确保文本格式清晰const content = msg.content.replace(/<[^>]+>/g, '');return `[${time}] ${msg.name} (${msg.role}): ${content}`;}).reverse() // 反转以按时间顺序排列.join('\n\n');const blob = new Blob([conversation], { type: 'text/plain;charset=utf-8' });saveAs(blob, 'conversation.txt');
};/*** 分享对话记录(打开分享对话框)*/
const shareConversation = async () => {openShareDialog();
};
</script><style lang="less" scoped>
/* 隐藏主题切换时的遮罩层 */
.t-dialog-mask, /* 可能的遮罩层类名 */
.theme-mask {display: none !important;
}/* 新的整体容器样式 */
.chat-container {display: flex;flex-direction: column;height: 100vh;padding: 30px;box-sizing: border-box;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}/* 工具栏样式更新,按钮统一样式和颜色 */
.toolbar {display: flex;justify-content: flex-end; /* 按钮靠右排列 */gap: 15px;margin-bottom: 25px;
}.toolbar-button {background-color: #bae7ff;font-size: 16px;padding: 8px 16px;display: flex;align-items: center;gap: 6px;
}/* 聊天窗口样式优化 */
.chat-window {flex: 1;border: none;border-radius: 16px;background-color: transparent;background-color: rgba(211, 211, 211, 0.5);  box-shadow: 0 8px 24px rgba(197, 235, 28, 0.1);overflow: hidden;
}/* 聊天气泡的通用样式 */
.chat-bubble {max-width: 65%;padding: 16px 22px;border-radius: 30px;margin-bottom: 18px;box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);word-break: break-word;font-size: 16px;line-height: 1.5;
}/* 用户消息气泡 */
.user-bubble {background-color: #bae7ff; /* 更清新的蓝色 */align-self: flex-end;border-top-right-radius: 0;
}/* 助手消息气泡 */
.assistant-bubble {background-color: #d9f7be; /* 柔和的绿色 */align-self: flex-start;border-top-left-radius: 0;
}/* 反馈按钮样式修改 */
.feedback-action {display: flex;gap: 10px;
}.feedback-action .t-button {background: none;border: none;cursor: pointer;font-size: 14px;padding: 4px 8px;border-radius: 4px;transition: background-color 0.3s, color 0.3s;
}.feedback-action .t-button:hover {background-color: rgba(24, 144, 255, 0.1);
}.active-good {color: #52c41a; /* 赞按钮选中时的绿色 */
}.active-bad {color: #ff4d4f; /* 踩按钮选中时的红色 */
}/* 调整聊天底部布局 */
.input-area {display: flex;align-items: center;gap: 15px;padding: 10px 0;border-top: 1px solid #f0f0f0;
}/* 停止按钮样式 */
.stop-button {background-color: #ff4d4f;border: none;width: 40px;height: 40px;
}/* 更新后的反馈表单对话框样式 */
.feedback-dialog {.t-dialog__header {background-color: #1890ff; /* 蓝色头部 */color: #ffffff;border-top-left-radius: 16px;border-top-right-radius: 16px;font-size: 18px;}.t-dialog__body {padding: 25px;background-color: #f0f5ff; /* 淡蓝色背景 */}.t-dialog__footer {background-color: #f0f5ff;border-bottom-left-radius: 16px;border-bottom-right-radius: 16px;}
}.feedback-content p {margin-bottom: 14px;font-size: 17px;
}.feedback-content strong {color: #60b1fd;
}.feedback-textarea {width: 100%;border: 1px solid #1890ff;border-radius: 8px;padding: 12px;resize: vertical;font-size: 16px;outline: none;transition: border-color 0.3s;
}.feedback-textarea:hover,
.feedback-textarea:focus {border-color: #40a9ff;
}/* 分享对话框样式 */
.share-dialog {.t-dialog__header {background-color: #40a9ff; /* 蓝色头部 */color: #ffffff;border-top-left-radius: 16px;border-top-right-radius: 16px;font-size: 18px;text-align: center;}.t-dialog__body {padding: 20px;background-color: #a8def7; /* 淡蓝色背景 */display: flex;flex-direction: column;align-items: center;}.share-dialog__footer {display: none; /* 移除对话框底部 */}
}.share-options {display: flex;flex-direction: column;gap: 12px;
}.share-button {width: 100%;display: flex;align-items: center;justify-content: center;gap: 8px;font-size: 16px;padding: 10px 0;border-radius: 8px;transition: background-color 0.3s, color 0.3s;
}.share-button:hover {background-color: rgba(24, 144, 255, 0.1);
}/* 响应式设计 */
@media (max-width: 768px) {.chat-container {padding: 20px;}.toolbar {flex-direction: column;align-items: stretch;gap: 12px;}.chat-bubble {max-width: 80%;}.feedback-dialog,.share-dialog {width: 90% !important;}.toolbar-button {font-size: 14px;padding: 6px 12px;}.chat-bubble {padding: 14px 18px;margin-bottom: 16px;font-size: 15px;}.feedback-content p {font-size: 16px;}.feedback-textarea {padding: 10px;font-size: 15px;}.share-button {font-size: 14px;padding: 8px 0;}
}
</style>

效果展示

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/66710.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用 IntelliJ IDEA 创建简单的 Java Web 项目

以下是使用 IntelliJ IDEA 创建几个简单的 Java Web 项目的步骤&#xff0c;每个项目实现基本的登录、注册和查看列表功能&#xff0c;依赖 Servlet/JSP 和基本的 Java Web 开发。 前置准备 确保安装了 IntelliJ IDEA Ultimate&#xff08;社区版不支持 Web 应用&#xff09;。…

抓包工具之mitmproxy

一、mitmproxy简介 mitmproxy介绍 mitmproxy又名中间人攻击代理&#xff0c;是一个抓包工具&#xff0c;类似于WireShark、Filddler&#xff0c;并且它支持抓取HTTP和HTTPS协议的数据包&#xff0c;只不过它是一个控制台的形式操作。另外&#xff0c;它还有两个非常有用的组件…

Flutter项目开发模版,开箱即用(Plus版本)

前言 当前案例 Flutter SDK版本&#xff1a;3.22.2 本文&#xff0c;是由这两篇文章 结合产出&#xff0c;所以非常建议大家&#xff0c;先看完这两篇&#xff1a; Flutter项目开发模版&#xff1a; 主要内容&#xff1a;MVVM设计模式及内存泄漏处理&#xff0c;涉及Model、…

rk3568 , buildroot , qt ,使用sqlite, 动态库, 静态库

问题说明&#xff1a; 客户反馈 &#xff0c;buildroot 系统 &#xff0c;使用qt 使用sqlite &#xff0c;有报错&#xff0c;无法使用sqlite. 测试情况说明&#xff1a; 我自己测试&#xff0c;发现&#xff0c; buildroot 自己默认就是 使能了 sqlite 的。 是否解决说明&…

嵌入式系统 tensorflow

&#x1f3ac; 秋野酱&#xff1a;《个人主页》 &#x1f525; 个人专栏:《Java专栏》《Python专栏》 ⛺️心若有所向往,何惧道阻且长 文章目录 探索嵌入式系统中的 TensorFlow&#xff1a;机遇与挑战一、TensorFlow 适配嵌入式的优势二、面临的硬件瓶颈三、软件优化策略四、实…

投机解码论文阅读:Falcon

题目&#xff1a;Falcon: Faster and Parallel Inference of Large Language Models through Enhanced Semi-Autoregressive Drafting and Custom-Designed Decoding Tree 地址&#xff1a;https://arxiv.org/pdf/2412.12639 一看它的架构图&#xff0c;可以发现它是基于EAGLE…

鸿蒙UI(ArkUI-方舟UI框架)

参考&#xff1a;https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/arkts-layout-development-overview-V13 ArkUI简介 ArkUI&#xff08;方舟UI框架&#xff09;为应用的UI开发提供了完整的基础设施&#xff0c;包括简洁的UI语法、丰富的UI功能&#xff…

《探索 PC 端的开源神经网络多模态模型宝藏》

《探索 PC 端的开源神经网络多模态模型宝藏》 一、多模态模型&#xff1a;开启智能交互新纪元二、主流 PC 端开源多模态模型大赏1. Obsidian&#xff1a;轻量级多模态先锋2. GLM-Edge 系列&#xff1a;移动端与 PC 端的全能选手3. Minicpm-llama3-v2.6&#xff1a;紧凑高效的多…

二次雷达的详细介绍及代码示例

一、二次雷达的工作原理 二次雷达&#xff0c;又称空管雷达信标系统&#xff08;Air Traffic Control Radar Beacon System&#xff0c;ATCRBS&#xff09;&#xff0c;是一种无线电电子测位和辨认系统。它由地面询问雷达和飞机上的应答雷达&#xff08;又称雷达信标&#xff0…

Clojure语言的多线程编程

Clojure语言的多线程编程 在现代软件开发中&#xff0c;多线程编程是一项重要的技能。它使程序能够在同一时间执行多个任务&#xff0c;充分利用多核处理器的性能。在众多编程语言中&#xff0c;Clojure作为一门函数式编程语言&#xff0c;提供了强大的并发支持。本文将深入探…

人工智能-数据分析及特征提取思路

1、概况 基于学生行为数据预测是否涉黄、涉黑等。 2.数据分析 数据分析的意义包括得到数据得直觉、发掘潜在的结构、提取重要的变量、删除异常值、检验潜在的假设和建立初步的模型。 2.1数据质量分析 2.1.1数据值分析 查看数据类型&#xff1a; 首先明确各字段的数据类型…

ChatGPT网络错误如何解决

在当今的信息化社会&#xff0c;网络技术已无处不在。无论是日常生活中的在线购物&#xff0c;还是工作中的远程会议&#xff0c;网络的稳定性和可靠性成为了我们无时无刻不在关注的重要问题。而在智能技术的快速发展中&#xff0c;像ChatGPT这样的人工智能模型&#xff0c;因其…

TensorFlow Quantum快速编程(基本篇)

一、TensorFlow Quantum 概述 1.1 简介 TensorFlow Quantum(TFQ)是由 Google 开发的一款具有开创性意义的开源库,它宛如一座桥梁,巧妙地将量子计算与 TensorFlow 强大的机器学习功能紧密融合。在当今科技飞速发展的时代,传统机器学习虽已取得诸多瞩目成就,然而面对日益…

Qt天气预报系统获取天气数据

Qt天气预报系统获取天气数据 1、获取天气数据1.1添加天气类头文件1.2定义今天和未来几天天气数据类1.3定义一个解析JSON数据的函数1.4在mainwindow中添加weatherData.h1.5创建今天天气数据和未来几天天气数据对象1.6添加parseJson定义1.7把解析JSON数据添加进去1.8添加错误1.9解…

[ASISCTF 2024 final]

过去有些日子的比赛的&#xff0c;国外很多比赛题目水平很高。没事的时候拿来作作。只是WP不全我不会的大多没有。 Crypto Lozib 这个题就挺有意思。由于远程都关了&#xff0c;只在本地把思路作了下。 #!/usr/bin/env python3import sys from Crypto.Util.number import *…

es 单个节点cpu过高

背景&#xff1a; es 单个节点cpu一直持续很高&#xff0c;其它节点cpu不高。 观察这个节点的jvm使用率比较高&#xff0c;怀疑是jvm内存没释放导致内存寻址效率低&#xff0c;引起cpu过高。 解决方法&#xff1a;手动执行fullgc&#xff0c; 在线执行对业务无影响。 jcmd pi…

国产编辑器EverEdit - 扩展脚本:关闭所有未修改文档

1 扩展脚本&#xff1a;关闭所有未修改文档 1.1 应用场景 当用户打开过多文档时&#xff0c;部分文档已经修改&#xff0c;而大部分没有修改&#xff0c;为了减少在众多已打开文档中来回跳转的不便&#xff0c;可以将没有修改的文档全部关闭&#xff0c;但目前提供的快速关闭窗…

高斯函数Gaussian绘制matlab

高斯 约翰卡尔弗里德里希高斯&#xff0c;&#xff08;德语&#xff1a;Johann Carl Friedrich Gau&#xff0c;英语&#xff1a;Gauss&#xff0c;拉丁语&#xff1a;Carolus Fridericus Gauss&#xff09;1777年4月30日–1855年2月23日&#xff0c;德国著名数学家、物理学家…

dolphinscheduler2.0.9升级3.1.9版本问题记录

相关版本说明 JDK&#xff1a;JDK (1.8&#xff09; DolphinScheduler &#xff1a;3.1.9 数据库&#xff1a;MySQL (8)&#xff0c;驱动&#xff1a;MySQL JDBC Driver 8.0.16 注册中心&#xff1a;ZooKeeper (3.8.4) 问题一&#xff1a;dolphinscheduler2.0.9对应zk版本使用…

Sqoop1.4.7安装

环境说明 准备三台服务器&#xff0c;分别为&#xff1a;bigdata141&#xff08;hadoop 主节点&#xff09;、bigdata142、bigdata143确保 hadoop 集群先启动好&#xff0c;hadoop 版本为 3.2.0如果只安装不使用的话&#xff0c;以上可以暂时不用管另准备一台服务器&#xff0…