原生js实现调用ollama api接口流式ai对话聊天效果代码
代码语言:html
所属分类:其他
代码描述:原生js实现调用ollama api接口流式ai对话聊天效果代码,流式打字输出,可中断输出。使用await fetch进行请求,模型可以在ollama中下载,这个代码提供了ui和交互效果。
代码标签: 原生 js 调用 ollama api 接口 流式 ai 对话 聊天
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" />
<style>
#historylist{
min-height:200px;
height: 400px;
background:white;
overflow-y: scroll; /* 允许垂直滚动 */
line-height: 20px;
}
.mesay{
background-color: aliceblue;
padding: 10px;
margin-top: 10px;
}
.aisay{
background-color:#d0e7ff;
padding: 10px;
}
/* 文本区域样式 */
#inputword {
width: 100%;
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
resize: none; /* 允许垂直调整大小 */
}
/* 按钮悬停效果 */
#inputword:focus {
border-color: #007bff; /* 设置为你想要的颜色,这里以Bootstrap的蓝色为例 */
outline: none; /* 可选:移除默认的轮廓线 */
box-shadow: 0 0 8px rgba(0, 123, 255, 0.2); /* 可选:添加阴影效果 */
}
/* 按钮样式 */
#myButton {
padding: 10px 20px;
border: none;
border-radius: 4px;
background-color: #007bff;
color: white;
fo.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0