Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinDai committed Jun 10, 2023
1 parent 42c5ea2 commit e0f2095
Show file tree
Hide file tree
Showing 48 changed files with 36,096 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules/
miniprogram/miniprogram_npm
37 changes: 36 additions & 1 deletion README.md
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
13 changes: 13 additions & 0 deletions miniprogram/api/prompts.ts
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 }
19 changes: 19 additions & 0 deletions miniprogram/app.json
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"
]
}
2 changes: 2 additions & 0 deletions miniprogram/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/**app.scss**/
@import '/miniprogram/assets/styles/index.scss';
4 changes: 4 additions & 0 deletions miniprogram/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// app.ts

App({
});
Binary file added miniprogram/assets/images/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprogram/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions miniprogram/assets/images/prompt-default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions miniprogram/assets/images/prompt-translator.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions miniprogram/assets/styles/iconfont.scss
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';
}
38 changes: 38 additions & 0 deletions miniprogram/assets/styles/index.scss
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;
}
11 changes: 11 additions & 0 deletions miniprogram/assets/styles/tdesign-variables.scss
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;
}
4 changes: 4 additions & 0 deletions miniprogram/components/custom-loading/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
28 changes: 28 additions & 0 deletions miniprogram/components/custom-loading/index.scss
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;
}
}
}
38 changes: 38 additions & 0 deletions miniprogram/components/custom-loading/index.ts
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,
});
},
},
});
18 changes: 18 additions & 0 deletions miniprogram/components/custom-loading/index.wxml
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>
43 changes: 43 additions & 0 deletions miniprogram/components/custom-loading/loading.ts
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 };
7 changes: 7 additions & 0 deletions miniprogram/components/message-item/index.json
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"
}
}
32 changes: 32 additions & 0 deletions miniprogram/components/message-item/index.ts
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: {
}
})
9 changes: 9 additions & 0 deletions miniprogram/components/message-item/index.wxml
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>
Loading

0 comments on commit e0f2095

Please sign in to comment.