马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
一、引入
起首可以先看下作者的文章
- FastApi相关文章:创建最简朴FastApi的项目
- Vue相关文章:最简朴的aixos二次封装
- Langchain相关文章:怎样利用LangSmith跟踪deepseek模型
二、后端搭建
1 项目文件结构
- routers:存放api接口
- service:存放实际操作函数
- init.py: 挂载接口
- main:运行步伐
2 创建聊天接口
3 创建chatService
一定要配置代理和模型密钥
4 挂载接口
5 运行主函数
三、前端搭建
1 创建axios实例
2 创建哀求
3 发送哀求
4 界面布局
界面布局的源代码
- <template>
- <div class="chat-container">
- <div class="timeline-container">
- <el-timeline>
- <el-timeline-item
- v-for="(activity, index) in activities"
- :key="index"
- :icon="activity.icon"
- :type="activity.type"
- :color="activity.color"
- :size="activity.size"
- :hollow="activity.hollow"
- :timestamp="activity.timestamp"
- >
- {
-
- { activity.content }}
- </el-timeline-item>
- </el-timeline>
- </div>
- <div id="container" class="input-container">
- <div id="chat" class="chat-input">
- <el-input
- v-model="msg"
- input-style="width: calc(100% - 80px); height: 60px; border-radius: 8px;"
- :rows="2"
- type="text"
- placeholder="请输入消息"
- @keydown.enter="sendMsg();"
- />
- <el-button @click="sendMsg()" class="send-button">发送</el-button>
- </div>
- </div>
- </div>
- </template>
- <script setup>
- import { MoreFilled } from '@element-plus/icons-vue'
- import {ref, onMounted} from "vue";
- import {getChat} from '@/api/chat'
- const activities = ref([
- {
- content: '请问有什么可以帮您的?',
- timestamp: new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString(),
- color: '#0bbd87',
- },
- ]);
- const msg = ref('');
- const sendMsg = () => {
- activities.value.push(
- {
- content: `你:${msg.value}`,
- timestamp: new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString(),
- size: 'large',
- type: 'primary',
- icon: MoreFilled,
- },
- );
- activities.value.push(
- {
- content: 'waiting...',
- timestamp: new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString(),
- color: '#0bbd87',
- },
- );
- getChat(msg.value).then(res => {
- activities.value.pop();
- activities.value.push(
- {
- content: res.data,
- timestamp: new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString(),
- color: '#0bbd87',
- },
- );
- });
- msg.value = '';
- };
- </script>
- <style scoped>
- .chat-container {
- background-color: #A8C9D4;
- padding: 10px;
- border-radius: 8px;
- width: 600px;
- height: 500px;
- display: flex;
- flex-direction: column;
- }
- .timeline-container {
- height: 600px;
- width: 100%;
- overflow-y: auto;
- border: 1px solid #1e7ba2;
- border-radius: 8px;
- padding: 10px;
- }
- .input-container {
- margin-top: 10px;
- }
- .chat-input {
- display: flex;
- align-items: center;
- }
- .send-button {
- margin-left: 10px;
- height: 60px;
- border-radius: 8px;
- }
- </style>
复制代码 5 配置代理
四、展示结果
五、源代码
源代码地点:天才奇男子/学习条记
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |