Skip to content

Commit

Permalink
feat: #响应式 (Chanzhaoyu#22)
Browse files Browse the repository at this point in the history
* feat: #响应式

* fix: #兼容node 16

* feat: #接口代理

* fix: #延长超时时长到30秒

* fix: #for node 16

* fix: #node 16

* Update settings.json

* Update package.json

* Update index.vue

* Update Layout.vue

---------

Co-authored-by: Redon <[email protected]>
  • Loading branch information
YutHelloWorld and Chanzhaoyu committed Feb 15, 2023
1 parent 79eeb51 commit c617205
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Glob API URL
VITE_GLOB_API_URL='http:https://localhost:3002'
VITE_GLOB_API_URL=/api
VITE_APP_API_BASE_URL = http:https://localhost:3002/
5 changes: 3 additions & 2 deletions service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"express"
],
"engines": {
"node": ">=18.0.0"
"node": "^16 || ^18"
},
"scripts": {
"start": "esno ./src/index.ts",
Expand All @@ -23,7 +23,8 @@
},
"dependencies": {
"chatgpt": "^4.3.2",
"express": "^4.18.2"
"express": "^4.18.2",
"isomorphic-fetch": "^3.0.0"
},
"devDependencies": {
"@antfu/eslint-config": "^0.35.2",
Expand Down
42 changes: 42 additions & 0 deletions service/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions service/src/chatgpt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as dotenv from 'dotenv'
import type { SendMessageOptions } from 'chatgpt'
import { ChatGPTAPI } from 'chatgpt'
import 'isomorphic-fetch'
import type { ChatGPTAPI, SendMessageOptions } from 'chatgpt'
import { sendResponse } from './utils'

export interface ChatContext {
Expand All @@ -18,7 +18,14 @@ if (apiKey === undefined)
/**
* More Info: https://github.com/transitive-bullshit/chatgpt-api
*/
const api = new ChatGPTAPI({ apiKey, debug: false })
let api: ChatGPTAPI
// To use ESM in CommonJS, you can use a dynamic import
(async () => {
const { ChatGPTAPI } = await import('chatgpt')

api = new ChatGPTAPI(
{ apiKey: process.env.OPENAI_API_KEY })
})()

async function chatReply(
message: string,
Expand Down
6 changes: 1 addition & 5 deletions src/components/business/Chat/layout/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Sider from './sider/index.vue'
</script>

<template>
<div class="h-full overflow-hidden border rounded-md shadow-md min-w-[640px]">
<div class="h-full overflow-hidden border rounded-md shadow-md">
<NLayout class="h-full" has-sider>
<Sider />
<NLayoutContent class="h-full">
Expand All @@ -13,7 +13,3 @@ import Sider from './sider/index.vue'
</NLayout>
</div>
</template>

<style>
</style>
4 changes: 2 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { App } from 'vue'
import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'
import { createRouter, createWebHistory } from 'vue-router'

const routes: RouteRecordRaw[] = [
{
Expand All @@ -11,7 +11,7 @@ const routes: RouteRecordRaw[] = [
]

export const router = createRouter({
history: createWebHashHistory(),
history: createWebHistory(),
routes,
scrollBehavior: () => ({ left: 0, top: 0 }),
})
Expand Down
12 changes: 10 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import path from 'path'
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig(() => {
export default defineConfig((env) => {
const viteEnv = loadEnv(env.mode, process.cwd())
return {
resolve: {
alias: {
Expand All @@ -14,6 +15,13 @@ export default defineConfig(() => {
port: 1002,
host: '0.0.0.0',
open: false,
proxy: {
'/api': {
target: viteEnv.VITE_APP_API_BASE_URL,
changeOrigin: true, // 允许跨域
rewrite: path => path.replace('/api/', '/'),
},
},
},
build: {
reportCompressedSize: false,
Expand Down

0 comments on commit c617205

Please sign in to comment.