-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
36,096 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
node_modules/ | ||
miniprogram/miniprogram_npm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
# chat-bot | ||
# chat-bot | ||
|
||
_本项目基础源自https://github.com/leon-fong/ChatGPT-miniprogram,对该项目做了功能上的裁剪,只保留了最简单的调用ChatGPT聊天功能并且改为使用typescript_ | ||
|
||
## 安装 | ||
|
||
1. 克隆项目 | ||
```bash | ||
git clone https://github.com/MartinDai/chat-bot.git | ||
``` | ||
|
||
2. 进入项目目录 | ||
```bash | ||
cd chat-bot | ||
``` | ||
|
||
3. 安装依赖 | ||
```bash | ||
npm install | ||
``` | ||
|
||
4. 打开微信开发者工具 - 工具 - 构建npm | ||
|
||
## 配置 | ||
|
||
1. 设置根域名 `BaseUrl` 和 `APPID` | ||
|
||
路径: | ||
- miniprogram/config/development.ts [开发环境] | ||
- miniprogram/config/production.ts [生产环境] | ||
|
||
> ⚠️ `BaseUrl` 可以设置反向代理的地址,具体教程参考:[使用 Cloudflare Workers 解决 OpenAI 和 ChatGPT 的 API 无法访问的问题](https://github.com/noobnooc/noobnooc/discussions/9) | ||
2. 设置 `OPEN_API_KEY` | ||
|
||
路径:miniprogram/config/index.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Prompt } from "~/models/model" | ||
|
||
const ChatGptPrompt: Prompt = { | ||
title: 'default', | ||
name: 'ChatGPT', | ||
content: '', | ||
description: '一个 AI 语言模型,可以回答问题的人工智能程序。', | ||
checked: true | ||
} | ||
|
||
const defaultPrompt: Prompt = ChatGptPrompt | ||
|
||
export { defaultPrompt } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"window": { | ||
"backgroundTextStyle": "light", | ||
"navigationBarBackgroundColor": "#f4f5f5", | ||
"navigationBarTitleText": "ChatBot", | ||
"navigationBarTextStyle": "black" | ||
}, | ||
"lazyCodeLoading": "requiredComponents", | ||
"resolveAlias": { | ||
"~/*": "/*" | ||
}, | ||
"usingComponents": { | ||
"custom-loading": "/components/custom-loading/index" | ||
}, | ||
"sitemapLocation": "sitemap.json", | ||
"pages": [ | ||
"pages/home/index" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/**app.scss**/ | ||
@import '/miniprogram/assets/styles/index.scss'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// app.ts | ||
|
||
App({ | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@font-face { | ||
font-family: 'iconfont'; /* Project id 3718153 */ | ||
src: url('//at.alicdn.com/t/c/font_3718153_0vtxp0q7aezj.woff2?t=1667092254173') format('woff2'), | ||
url('//at.alicdn.com/t/c/font_3718153_0vtxp0q7aezj.woff?t=1667092254173') format('woff'), | ||
url('//at.alicdn.com/t/c/font_3718153_0vtxp0q7aezj.ttf?t=1667092254173') format('truetype'); | ||
} | ||
|
||
.iconfont { | ||
font-family: 'iconfont' !important; | ||
font-size: 16px; | ||
font-style: normal; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
.icon-xiaochengxu:before { | ||
content: '\e646'; | ||
} | ||
|
||
.icon-pullright:before { | ||
content: '\e720'; | ||
} | ||
|
||
.icon-close:before { | ||
content: '\e747'; | ||
} | ||
|
||
.icon-leftarrow:before { | ||
content: '\e755'; | ||
} | ||
|
||
.icon-home:before { | ||
content: '\e7a7'; | ||
} | ||
|
||
.icon-search:before { | ||
content: '\e7b4'; | ||
} | ||
|
||
.icon-leftalignment:before { | ||
content: '\e7cf'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@import '/assets/styles/tdesign-variables.wxss'; | ||
|
||
page { | ||
font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Segoe UI, Arial, Roboto, 'PingFang SC', | ||
'miui', 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; | ||
font-size: 28rpx; | ||
font-weight: 300; | ||
color: #031c24; | ||
background-color: #f4f5f5; | ||
} | ||
|
||
/* scroll-view滚动条样式 */ | ||
::-webkit-scrollbar { | ||
display: none; | ||
} | ||
|
||
.safeAreaInsetBottom { | ||
padding-bottom: calc(env(safe-area-inset-bottom)); | ||
} | ||
|
||
.btn-clear { | ||
background-color: transparent; | ||
border: none; | ||
outline: none; | ||
cursor: pointer; | ||
font-size: inherit; | ||
font-weight: inherit; | ||
color: inherit; | ||
text-align: inherit; | ||
text-decoration: inherit; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.btn-clear::after, | ||
.btn-clear::before { | ||
border: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
page { | ||
--primary-color:#ffd001; | ||
--primary-lite-color:#ffeb67; | ||
--td-button-primary-bg-color: var(--primary-color); | ||
--td-button-primary-border-color: var(--primary-color); | ||
--td-button-primary-active-bg-color: #ffeb67; | ||
--td-button-primary-active-border-color: #ffeb67; | ||
--td-cell-left-icon-color: #333; | ||
--td-button-primary-disabled-bg: #ffeb67; | ||
--td-button-primary-disabled-border-color: #ffeb67; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"component": true, | ||
"usingComponents": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* components/custom-loading/index.scss */ | ||
.loading-wrapper { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
position: fixed; | ||
left: 0; | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
|
||
.mask-wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-around; | ||
align-items: center; | ||
width: 240rpx; | ||
height: 240rpx; | ||
padding: 32rpx; | ||
box-sizing: border-box; | ||
background-color: rgba(3, 28, 36, 1); | ||
border-radius: 16rpx; | ||
|
||
.loading-text { | ||
color: #ffffff; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// components/custom-loading/index.ts | ||
const { systemInfo } = getApp(); | ||
|
||
Component({ | ||
/** | ||
* 组件的属性列表 | ||
*/ | ||
properties: { | ||
loading: { | ||
// loading状态 | ||
type: Boolean, | ||
value: false, | ||
}, | ||
zIndex: { | ||
type: Number, | ||
value: 1000, | ||
}, | ||
}, | ||
|
||
/** | ||
* 组件的初始数据 | ||
*/ | ||
data: { | ||
systemInfo, // 设备信息 | ||
}, | ||
|
||
/** | ||
* 组件的方法列表 | ||
*/ | ||
methods: {}, | ||
pageLifetimes: { | ||
hide() { | ||
this.setData({ | ||
loading: false, | ||
}); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!--components/custom-loading/index.wxml--> | ||
<view | ||
wx:if="{{loading}}" | ||
catchtouchmove="noop" | ||
style="width: {{systemInfo.screenWidth}}px; height: {{systemInfo.screenHeight}}px; z-index: {{zIndex}};" | ||
class="loading-wrapper" | ||
> | ||
<view class="mask-wrapper"> | ||
<custom-image | ||
src="/assets/images/loading.gif" | ||
width="100rpx" | ||
height="100rpx" | ||
showLoading="{{false}}" | ||
class="image" | ||
/> | ||
<text class="loading-text">加载中...</text> | ||
</view> | ||
</view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const defaultOptions = { | ||
selector: '#custom-loading', | ||
}; | ||
|
||
function getContext() { | ||
const pages = getCurrentPages(); | ||
return pages[pages.length - 1]; | ||
} | ||
|
||
const Loading = (options = {}) => { | ||
options = Object.assign({ ...defaultOptions }, options); | ||
|
||
return new Promise<void>(() => { | ||
const content = getContext(); | ||
if (content) { | ||
// @ts-ignore | ||
const loading = content.selectComponent(options.selector || ""); | ||
// @ts-ignore | ||
delete options.selector; | ||
if (loading) { | ||
loading.setData(options); | ||
} else { | ||
console.warn('未找到 custom-loading 节点,请确认 selector 及 context 是否正确'); | ||
} | ||
} else { | ||
console.warn('未找到 custom-loading 节点所在的页面栈信息'); | ||
} | ||
}); | ||
}; | ||
|
||
Loading.show = function () { | ||
return Loading({ | ||
loading: true, | ||
}); | ||
}; | ||
|
||
Loading.clear = function () { | ||
return Loading({ | ||
loading: false, | ||
}); | ||
}; | ||
|
||
export { Loading }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"component": true, | ||
"usingComponents": { | ||
"t-avatar": "tdesign-miniprogram/avatar/avatar", | ||
"t-icon": "tdesign-miniprogram/icon/icon" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// components/message-item/index.ts | ||
Component({ | ||
options:{ | ||
virtualHost:true | ||
}, | ||
/** | ||
* 组件的属性列表 | ||
*/ | ||
properties: { | ||
role: { | ||
type: String, | ||
default: 'assistant', | ||
}, | ||
content: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
|
||
/** | ||
* 组件的初始数据 | ||
*/ | ||
data: { | ||
|
||
}, | ||
|
||
/** | ||
* 组件的方法列表 | ||
*/ | ||
methods: { | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<view class="message"> | ||
<view class="message__wrap {{role === 'user' && 'message__layout--reverse'}} animate__animated animate__fadeInUp"> | ||
<view class="message__box message__box--{{role}}"> | ||
<text class="message__box--text" user-select wx:if="{{content}}">{{content}}</text> | ||
<slot wx:else></slot> | ||
</view> | ||
<view class="message__avatar "></view> | ||
</view> | ||
</view> |
Oops, something went wrong.