test
This commit is contained in:
commit
cbfd2e97ef
68
.gitignore
vendored
Normal file
68
.gitignore
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
node_modules
|
||||
|
||||
# mac
|
||||
.DS_Store
|
||||
|
||||
.env*
|
||||
!.env*example
|
||||
|
||||
dist
|
||||
build
|
||||
logs
|
||||
|
||||
.turbo
|
||||
|
||||
pack-dist
|
||||
|
||||
# astro
|
||||
.astro
|
||||
|
||||
# next
|
||||
.next
|
||||
|
||||
# nuxt
|
||||
.nuxt
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# vuepress
|
||||
.vuepress/dist
|
||||
|
||||
# coverage
|
||||
coverage/
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
|
||||
# debug logs
|
||||
*.log
|
||||
*.tmp
|
||||
|
||||
# vscode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# idea
|
||||
.idea
|
||||
|
||||
# system
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
|
||||
# temp files
|
||||
*.tmp
|
||||
*.temp
|
||||
|
||||
# local development
|
||||
*.local
|
||||
|
||||
public/r
|
||||
|
||||
.pnpm-store
|
||||
|
||||
storage/
|
28
chat.js
Normal file
28
chat.js
Normal file
@ -0,0 +1,28 @@
|
||||
import Openai from 'openai';
|
||||
|
||||
console.log('Chat module loaded', process.env);
|
||||
|
||||
const openai = new Openai({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
baseURL: process.env.OPENAI_API_BASE_URL || 'https://api.openai.com/v1',
|
||||
timeout: 10000, // Set a timeout of 10 seconds
|
||||
dangerouslyAllowBrowser: true, // Allow browser usage
|
||||
});
|
||||
|
||||
export const chat = async (messages) => {
|
||||
try {
|
||||
const response = await openai.chat.completions.create({
|
||||
model: 'Qwen/Qwen2-7B-Instruct',
|
||||
messages: messages,
|
||||
max_tokens: 1000,
|
||||
temperature: 0.7,
|
||||
});
|
||||
return response.choices[0].message.content;
|
||||
} catch (error) {
|
||||
console.error('Error in chat completion:', error);
|
||||
throw error; // Re-throw the error for further handling
|
||||
}
|
||||
};
|
||||
|
||||
// const res = await chat([{ role: 'user', content: 'Hello, how are you?' }]);
|
||||
// console.log('Chat response:', res);
|
9
env.js
Normal file
9
env.js
Normal file
@ -0,0 +1,9 @@
|
||||
const OPENAI_API_KEY = localStorage.getItem('OPENAI_API_KEY') || 'sk-qbiigkzoaamuqxtwlgkugodncebkfbosemadfubjrseobpvx';
|
||||
export const process = {
|
||||
env: {
|
||||
OPENAI_API_KEY,
|
||||
OPENAI_API_BASE_URL: 'https://api.siliconflow.cn/v1',
|
||||
},
|
||||
};
|
||||
|
||||
window.process = process;
|
39
index.html
Normal file
39
index.html
Normal file
@ -0,0 +1,39 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Kevisual Template</title>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#root {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"openai": "https://esm.sh/openai"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root">123</div>
|
||||
<script type="module" src="./env.js"></script>
|
||||
<script type="module" src="./chat.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
26
kevisual.json
Normal file
26
kevisual.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"sync": {
|
||||
".gitignore": {
|
||||
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/gitignore/node.txt"
|
||||
},
|
||||
"tsconfig.json": {
|
||||
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/ts/front.json"
|
||||
},
|
||||
"vite.config.mjs": {
|
||||
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/vite/base.mjs"
|
||||
},
|
||||
"index.html": {
|
||||
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/vite/html/index.html"
|
||||
},
|
||||
"src/index.css": {
|
||||
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/vite/css/index.css"
|
||||
},
|
||||
"src/main.tsx": {
|
||||
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/vite/react/main.tsx"
|
||||
},
|
||||
"package.json": {
|
||||
"type": "download",
|
||||
"url": "https://kevisual.xiongxiao.me/root/ai/code/config/npm/frontend/npm-01.json"
|
||||
}
|
||||
}
|
||||
}
|
27
package.json
Normal file
27
package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "vite-react",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"basename": "/root/vite-react",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"pub": "envision deploy ./dist -k vite-react -v 0.0.1",
|
||||
"dev:web": "browser-sync start --server --files \"*.html, css/*.css, js/*.js\" --port 5173",
|
||||
"pub:web": "ev deploy ../* -k vite-react -v 1.0.1 -u"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"openai": "^5.1.1"
|
||||
},
|
||||
"packageManager": "pnpm@10.11.0"
|
||||
}
|
31
pnpm-lock.yaml
generated
Normal file
31
pnpm-lock.yaml
generated
Normal file
@ -0,0 +1,31 @@
|
||||
lockfileVersion: '9.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
devDependencies:
|
||||
openai:
|
||||
specifier: ^5.1.1
|
||||
version: 5.1.1
|
||||
|
||||
packages:
|
||||
|
||||
openai@5.1.1:
|
||||
resolution: {integrity: sha512-lgIdLqvpLpz8xPUKcEIV6ml+by74mbSBz8zv/AHHebtLn/WdpH4kdXT3/Q5uUKDHg3vHV/z9+G9wZINRX6rkDg==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
ws: ^8.18.0
|
||||
zod: ^3.23.8
|
||||
peerDependenciesMeta:
|
||||
ws:
|
||||
optional: true
|
||||
zod:
|
||||
optional: true
|
||||
|
||||
snapshots:
|
||||
|
||||
openai@5.1.1: {}
|
1
src/index.css
Normal file
1
src/index.css
Normal file
@ -0,0 +1 @@
|
||||
@import "tailwindcss";
|
4
src/main.tsx
Normal file
4
src/main.tsx
Normal file
@ -0,0 +1,4 @@
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { App } from './App.tsx';
|
||||
|
||||
createRoot(document.getElementById('root')!).render(<App />);
|
18
tsconfig.json
Normal file
18
tsconfig.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "@kevisual/types/json/frontend.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@kevisual"
|
||||
],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
],
|
||||
}
|
65
vite.config.mjs
Normal file
65
vite.config.mjs
Normal file
@ -0,0 +1,65 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import path from 'path';
|
||||
import pkgs from './package.json';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import basicSsl from '@vitejs/plugin-basic-ssl';
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config({ path: '.env.development' });
|
||||
const version = pkgs.version || '0.0.1';
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const basename = isDev ? '/' : pkgs?.basename || '/';
|
||||
const plugins = [react(), tailwindcss()];
|
||||
const isCNB = process.env.CNB === 'true';
|
||||
if (isDev && !isCNB) {
|
||||
// plugins.push(basicSsl());
|
||||
}
|
||||
let target = process.env.VITE_API_URL || 'http://localhost:51015';
|
||||
const apiProxy = { target: target, changeOrigin: true, ws: true, rewriteWsOrigin: true, secure: false, cookieDomainRewrite: 'localhost' };
|
||||
let proxy = {
|
||||
'/root/': {
|
||||
target: `${target}`,
|
||||
secure: false,
|
||||
},
|
||||
'/user/login/': {
|
||||
target: `${target}`,
|
||||
secure: false,
|
||||
},
|
||||
'/api': apiProxy,
|
||||
'/client': apiProxy,
|
||||
};
|
||||
/**
|
||||
* @see https://vitejs.dev/config/
|
||||
*/
|
||||
export default defineConfig(() => {
|
||||
return {
|
||||
plugins,
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
base: basename,
|
||||
envPrefix: 'KEVISUAL_',
|
||||
define: {
|
||||
DEV_SERVER: JSON.stringify(process.env.NODE_ENV === 'development'),
|
||||
APP_VERSION: JSON.stringify(version),
|
||||
BASE_NAME: JSON.stringify(basename),
|
||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
||||
},
|
||||
build: {
|
||||
target: 'modules',
|
||||
// lib: {
|
||||
// entry: './src/libs.ts',
|
||||
// formats: ['es'],
|
||||
// fileName: (format) => `render.js`,
|
||||
// },
|
||||
},
|
||||
server: {
|
||||
port: 7008,
|
||||
host: '0.0.0.0',
|
||||
allowedHosts: true,
|
||||
proxy,
|
||||
},
|
||||
};
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user