Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52bfd15ad8 | ||
|
|
e0920bee4b | ||
|
|
cb589e05e9 | ||
|
|
6aa2591d9c | ||
|
|
ad41dd21c6 | ||
|
|
35da3f1d1f | ||
|
|
31ea7c5529 | ||
|
|
cab7b0ec99 |
4
.npmrc
4
.npmrc
@@ -1,4 +0,0 @@
|
|||||||
registry=https://registry.npmmirror.com/
|
|
||||||
shamefully-hoist=true
|
|
||||||
strict-peer-dependencies=false
|
|
||||||
auto-install-peers=true
|
|
||||||
2
.vscode/extensions.json
vendored
2
.vscode/extensions.json
vendored
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
|
"recommendations": ["Vue.volar", "dbaeumer.vscode-eslint"]
|
||||||
}
|
}
|
||||||
|
|||||||
15
.vscode/settings.json
vendored
15
.vscode/settings.json
vendored
@@ -1,8 +1,21 @@
|
|||||||
{
|
{
|
||||||
"editor.formatOnSave": false,
|
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": true
|
||||||
},
|
},
|
||||||
|
"eslint.validate": [
|
||||||
|
"javascript",
|
||||||
|
"javascriptreact",
|
||||||
|
"typescript",
|
||||||
|
"typescriptreact",
|
||||||
|
"vue",
|
||||||
|
"html",
|
||||||
|
"json",
|
||||||
|
"jsonc",
|
||||||
|
"json5",
|
||||||
|
"yaml",
|
||||||
|
"yml",
|
||||||
|
"markdown"
|
||||||
|
],
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"antfu",
|
"antfu",
|
||||||
"axios",
|
"axios",
|
||||||
|
|||||||
18
CHANGELOG.md
18
CHANGELOG.md
@@ -0,0 +1,18 @@
|
|||||||
|
## v1.0.3
|
||||||
|
|
||||||
|
`2023-02-11`
|
||||||
|
|
||||||
|
### Enhancement
|
||||||
|
- 拆分 `service` 文件以便扩展
|
||||||
|
- 调整 `Eslint` 相关验证
|
||||||
|
|
||||||
|
### BugFix
|
||||||
|
- 修复部份控制台报错
|
||||||
|
|
||||||
|
## v1.0.2
|
||||||
|
|
||||||
|
`2023-02-10`
|
||||||
|
|
||||||
|
### BugFix
|
||||||
|
- 修复新增信息容器不会自动滚动到问题
|
||||||
|
- 修复文本过长不换行到问题 [#1](https://github.com/Chanzhaoyu/chatgpt-web/issues/1)
|
||||||
|
|||||||
95
package.json
95
package.json
@@ -1,50 +1,49 @@
|
|||||||
{
|
{
|
||||||
"name": "chatgpt-web",
|
"name": "chatgpt-web",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"description": "ChatGPT Web Bot",
|
"private": false,
|
||||||
"author": "ChenZhaoYu <chenzhaoyu1994@gami.com>",
|
"description": "ChatGPT Web Bot",
|
||||||
"private": false,
|
"author": "ChenZhaoYu <chenzhaoyu1994@gami.com>",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"chatgpt",
|
"chatgpt",
|
||||||
"chatbot",
|
"chatbot",
|
||||||
"web",
|
"web",
|
||||||
"vue"
|
"vue"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"service": "esno ./service/index.ts",
|
"service": "esno ./service/index.ts",
|
||||||
"build": "run-p type-check build-only",
|
"build": "run-p type-check build-only",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"build-only": "vite build",
|
"build-only": "vite build",
|
||||||
"type-check": "vue-tsc --noEmit",
|
"type-check": "vue-tsc --noEmit",
|
||||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
"lint": "eslint . --fix --ignore-path .gitignore",
|
||||||
"release": "bumpp package.json --commit --push --tag"
|
"release": "bumpp package.json --commit --push --tag"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"naive-ui": "^2.34.3",
|
"naive-ui": "^2.34.3",
|
||||||
"vue": "^3.2.45"
|
"vue": "^3.2.47"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "^0.35.2",
|
"@antfu/eslint-config": "^0.35.2",
|
||||||
"@iconify/vue": "^4.1.0",
|
"@iconify/vue": "^4.1.0",
|
||||||
"@types/babel__core": "^7.20.0",
|
"@types/express": "^4.17.17",
|
||||||
"@types/express": "^4.17.17",
|
"@types/node": "^18.13.0",
|
||||||
"@types/node": "^18.11.12",
|
"@vitejs/plugin-vue": "^4.0.0",
|
||||||
"@vitejs/plugin-vue": "^4.0.0",
|
"autoprefixer": "^10.4.13",
|
||||||
"autoprefixer": "^10.4.13",
|
"axios": "^1.3.2",
|
||||||
"axios": "^1.3.2",
|
"bumpp": "^8.2.1",
|
||||||
"bumpp": "^8.2.1",
|
"chatgpt": "^4.2.0",
|
||||||
"chatgpt": "^4.2.0",
|
"dotenv": "^16.0.3",
|
||||||
"dotenv": "^16.0.3",
|
"eslint": "^8.34.0",
|
||||||
"eslint": "^8.22.0",
|
"esno": "^0.16.3",
|
||||||
"esno": "^0.16.3",
|
"express": "^4.18.2",
|
||||||
"express": "^4.18.2",
|
"npm-run-all": "^4.1.5",
|
||||||
"npm-run-all": "^4.1.5",
|
"postcss": "^8.4.21",
|
||||||
"postcss": "^8.4.21",
|
"prettier": "^2.8.4",
|
||||||
"prettier": "^2.7.1",
|
"tailwindcss": "^3.2.6",
|
||||||
"tailwindcss": "^3.2.6",
|
"typescript": "~4.9.5",
|
||||||
"typescript": "~4.7.4",
|
"vite": "^4.1.1",
|
||||||
"vite": "^4.0.0",
|
"vue-tsc": "^1.0.24"
|
||||||
"vue-tsc": "^1.0.12"
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
479
pnpm-lock.yaml
generated
479
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
19
service/chatgpt.ts
Normal file
19
service/chatgpt.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import dotenv from 'dotenv'
|
||||||
|
import { ChatGPTAPI } from 'chatgpt'
|
||||||
|
|
||||||
|
dotenv.config()
|
||||||
|
|
||||||
|
const apiKey = ''
|
||||||
|
|
||||||
|
/**
|
||||||
|
* More Info: https://github.com/transitive-bullshit/chatgpt-api
|
||||||
|
*/
|
||||||
|
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY || apiKey })
|
||||||
|
|
||||||
|
async function chatReply(message: string) {
|
||||||
|
if (!message)
|
||||||
|
return
|
||||||
|
return await api.sendMessage(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { chatReply }
|
||||||
@@ -1,30 +1,10 @@
|
|||||||
import dotenv from 'dotenv'
|
|
||||||
import { ChatGPTAPI } from 'chatgpt'
|
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
|
import { chatReply } from './chatgpt'
|
||||||
dotenv.config()
|
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
|
|
||||||
async function chatAPI(message: string) {
|
|
||||||
if (!message)
|
|
||||||
throw new Error('Message is not defined')
|
|
||||||
|
|
||||||
if (!process.env.OPENAI_API_KEY)
|
|
||||||
throw new Error('OPENAI_API_KEY is not defined in .env file')
|
|
||||||
|
|
||||||
try {
|
|
||||||
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })
|
|
||||||
const res = await api.sendMessage(message)
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
return error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
app.all('*', (req, res, next) => {
|
app.all('*', (req, res, next) => {
|
||||||
res.header('Access-Control-Allow-Origin', '*')
|
res.header('Access-Control-Allow-Origin', '*')
|
||||||
res.header('Access-Control-Allow-Headers', 'Content-Type')
|
res.header('Access-Control-Allow-Headers', 'Content-Type')
|
||||||
@@ -36,6 +16,6 @@ app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))
|
|||||||
|
|
||||||
app.post('/chat', async (req, res) => {
|
app.post('/chat', async (req, res) => {
|
||||||
const { message } = req.body
|
const { message } = req.body
|
||||||
const response = await chatAPI(message)
|
const response = await chatReply(message)
|
||||||
res.send(response)
|
res.send(response)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
<script setup lang='ts'>
|
|
||||||
import { Icon } from '@/components'
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
user?: boolean
|
|
||||||
date?: string
|
|
||||||
message?: string
|
|
||||||
error?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
defineProps<Props>()
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="flex w-full mb-6" :class="[{ 'flex-row-reverse': user }]">
|
|
||||||
<div
|
|
||||||
class="flex items-center justify-center rounded-full overflow-hidden w-[32px] h-[32px]"
|
|
||||||
:class="[user ? 'ml-3' : 'mr-3']"
|
|
||||||
>
|
|
||||||
<img v-if="user" src="@/assets/avatar.jpg" class="object-cover w-full h-full " alt="avatar">
|
|
||||||
<Icon v-else local-icon="logo" class="text-[26px]" />
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col flex-1 text-sm" :class="[{ 'items-end': user }]">
|
|
||||||
<span class="text-xs text-[#b4bbc4]">
|
|
||||||
{{ date }}
|
|
||||||
</span>
|
|
||||||
<div class="p-2 mt-2 rounded-md" :class="[user ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]']">
|
|
||||||
<span class="leading-relaxed whitespace-pre" :class="[{ 'text-red-500': error }]">
|
|
||||||
{{ message }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
Reference in New Issue
Block a user