commit cbfd2e97ef6ad257b5d05f49b43e3cbae08562ea Author: abearxiong Date: Mon Jun 9 16:19:09 2025 +0800 test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec6578a --- /dev/null +++ b/.gitignore @@ -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/ \ No newline at end of file diff --git a/chat.js b/chat.js new file mode 100644 index 0000000..48652ca --- /dev/null +++ b/chat.js @@ -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); diff --git a/env.js b/env.js new file mode 100644 index 0000000..9d7a7db --- /dev/null +++ b/env.js @@ -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; diff --git a/index.html b/index.html new file mode 100644 index 0000000..9d94fee --- /dev/null +++ b/index.html @@ -0,0 +1,39 @@ + + + + + + + Kevisual Template + + + + + +
123
+ + + + + \ No newline at end of file diff --git a/kevisual.json b/kevisual.json new file mode 100644 index 0000000..3626fa3 --- /dev/null +++ b/kevisual.json @@ -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" + } + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..9371ce9 --- /dev/null +++ b/package.json @@ -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 ", + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "openai": "^5.1.1" + }, + "packageManager": "pnpm@10.11.0" +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..a0a1f28 --- /dev/null +++ b/pnpm-lock.yaml @@ -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: {} diff --git a/src/index.css b/src/index.css new file mode 100644 index 0000000..a461c50 --- /dev/null +++ b/src/index.css @@ -0,0 +1 @@ +@import "tailwindcss"; \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx new file mode 100644 index 0000000..7e1ba3d --- /dev/null +++ b/src/main.tsx @@ -0,0 +1,4 @@ +import { createRoot } from 'react-dom/client'; +import { App } from './App.tsx'; + +createRoot(document.getElementById('root')!).render(); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8f93311 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "@kevisual/types/json/frontend.json", + "compilerOptions": { + "baseUrl": ".", + "typeRoots": [ + "./node_modules/@types", + "./node_modules/@kevisual" + ], + "paths": { + "@/*": [ + "src/*" + ] + }, + }, + "include": [ + "src/**/*", + ], +} \ No newline at end of file diff --git a/vite.config.mjs b/vite.config.mjs new file mode 100644 index 0000000..b650eec --- /dev/null +++ b/vite.config.mjs @@ -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, + }, + }; +});