Merge remote-tracking branch 'origin/main'

This commit is contained in:
3 2025-06-03 12:44:56 +08:00
commit b93d9646ee
12 changed files with 102 additions and 33 deletions

View File

@ -1,10 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python facet">
<configuration sdkName="Python 3.12" />
</facet>
</component>
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" /> <excludeFolder url="file://$MODULE_DIR$/.venv" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Python 3.12 interpreter library" level="application" />
</component> </component>
</module> </module>

View File

@ -1,29 +1,41 @@
# 基于人工智能实现的交换机自动或半自动配置 # 基于人工智能实现的交换机自动或半自动配置
### 技术栈 ### 技术栈
- Python3 - **Python3**
- JavaScript - Flask
- React - FastAPI
- Flask-CORS
- **JavaScript**
- React
- JSX
- Framer-motion
- ~~chakra-ui~~
- shadcn-ui
- HTML5 - HTML5
### 项目分工 ### 项目分工
- **后端api人工智能算法** : `3`(主要) & `log_out` 使用python - **后端api人工智能算法** : `3`(主要) & `log_out` & `Jerry`(maybe) 使用python
- **前端管理后台设计**`Jerry`使用react - **前端管理后台设计**`Jerry`使用react
- **论文撰写**`log_out` - **论文撰写**`log_out`
### 各部分说明
[网页管理前端](https://github.com/Jerryplusy/AI-powered-switches/blob/main/src/frontend/README.md)
[逻辑处理后端](https://github.com/Jerryplusy/AI-powered-switches/blob/main/src/backend/README.md)
### 贡献流程 ### 贡献流程
- **后端api**: - **后端api**:
- 对于`3`:直接推送到`main`分支 - 对于`3`:直接推送到`main`分支
- 对于`Jerry`&`log_out`:**fork** 到自己仓库下提交推送到自己的仓库然后提交pullrequest并指定`3`审核 - 对于`Jerry`&`log_out`:新建额外的`feat``fix`分支,提交推送到自己的分支,然后提交`pullrequest``main`分支并指定`3`审核
- **前端管理后台**: - **前端管理后台**:
- 对于`Jerry`:直接推送更新到`main`分支 - 对于`Jerry`:直接推送更新到`main`分支
- 对于`3`&`log_out`:**fork** 到自己仓库下提交推送到自己的仓库然后提交pullrequest并指定`Jerry`审核 - 对于`3`&`log_out`:新建额外的`feat``fix`分支,提交推送到自己的分支,然后提交`pullrequest``main`分支并指定`Jerry`审核
- **论文(thesis)** - **论文(thesis)**
- **fork** 到自己仓库下提交推送到自己的仓库然后提交pullrequest并指定`log_out`审核 - 提交`pullrequest`并指定`log_out`审核
- **注意在推送前先更新项目**
### 项目活动时间 ### 项目活动时间
2025 6 - 8月 2025 6 - 8月

View File

@ -1,5 +1,5 @@
# 硅基流动API配置 # 硅基流动API配置
SILICONFLOW_API_KEY=sk-mhzuedasunrgdrxfkcxmxgaypgjnxgodvvmrzzdbqrwtkqej SILICONFLOW_API_KEY=sk-114514
SILICONFLOW_API_URL=https://api.siliconflow.ai/v1 SILICONFLOW_API_URL=https://api.siliconflow.ai/v1
# 交换机登录凭证 # 交换机登录凭证
@ -8,4 +8,4 @@ SWITCH_PASSWORD=your_switch_password
SWITCH_TIMEOUT=10 SWITCH_TIMEOUT=10
# 应用设置 # 应用设置
DEBUG=True DEBUG=True

48
src/backend/README.md Normal file
View File

@ -0,0 +1,48 @@
# AI-powered-switches Backend
这是 AI-powered-switches 的后端服务,基于 `Flask` 构建,提供 `REST API` 接口,用于解析自然语言生成网络交换机配置并下发到设备
### 项目结构
```bash
src/backend/
├── app/
│ ├── __init__.py # 创建 Flask 应用实例
│ ├── api/ # API 路由模块
│ │ ├── __init__.py # 注册 API 蓝图
│ │ ├── command_parser.py # /api/parse_command 接口
│ │ └── network_config.py # /api/apply_config 接口
│ └── services/ # 核心服务逻辑
│ └── ai_services.py # 调用外部 AI 服务生成配置
├── config.py # 配置加载与环境变量管理
├── exceptions.py # 自定义异常定义
├── run.py # 程序入口
├── requirements.txt # Python 依赖列表
└── Dockerfile/Dockerfile # 后端 Docker 镜像构建文件
```
### 本地运行
``` bash
pip install -r requirements.txt
```
创建`.env`并参照`.envExample`写入环境变量
```bash
python run.py
```
### Docker构建
```bash
docker build -t ai-switch-backend -f Dockerfile/Dockerfile .
```
```bash
docker run -p 5000:5000 \
-e AI_API_KEY=your_api_key \
-e SWITCH_USER=admin \
-e SWITCH_PASS=your_password \
ai-switch-backend
```

View File

@ -1,3 +1,6 @@
ignoredBuiltDependencies: ignoredBuiltDependencies:
- core-js - core-js
- core-js-pure - core-js-pure
packages:
- '.'

View File

@ -1,12 +1,14 @@
'use client' 'use client';
import { ChakraProvider } from '@chakra-ui/react';
import { ColorModeProvider } from './color-mode';
import createSystem from '@/theme';
import { ChakraProvider, defaultSystem } from '@chakra-ui/react' const system = createSystem;
import { ColorModeProvider } from './color-mode'
export function Provider(props) { export function Provider(props) {
return ( return (
<ChakraProvider value={defaultSystem}> <ChakraProvider value={system}>
<ColorModeProvider {...props} /> <ColorModeProvider {...props} />
</ChakraProvider> </ChakraProvider>
) );
} }

View File

View File

@ -3,7 +3,6 @@ import ReactDOM from 'react-dom/client';
import App from '@/App'; import App from '@/App';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
import { Provider } from '@/components/ui/provider'; import { Provider } from '@/components/ui/provider';
import system from '@/theme';
const root = ReactDOM.createRoot(document.getElementById('root')); const root = ReactDOM.createRoot(document.getElementById('root'));
root.render( root.render(

View File

View File

@ -1,7 +1,6 @@
import React from 'react'; import React from 'react';
import { Box, Button, Heading, VStack } from '@chakra-ui/react'; import { Box, Button, Heading, VStack } from '@chakra-ui/react';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import Card from '@/components/ui/Card';
const Welcome = () => { const Welcome = () => {
const navigate = useNavigate(); const navigate = useNavigate();

View File

View File

@ -3,25 +3,21 @@ import { defineConfig, createSystem, defaultConfig } from '@chakra-ui/react';
const config = defineConfig({ const config = defineConfig({
cssVarsRoot: ':where(:root, :host)', cssVarsRoot: ':where(:root, :host)',
cssVarsPrefix: 'ck', cssVarsPrefix: 'ck',
strictTokens: false, strictTokens: true,
globalCss: { globalCss: {}, //全局css
'html, body': {
margin: 0,
padding: 0,
fontFamily: "'Roboto', sans-serif",
backgroundColor: '{colors.bg}',
color: '{colors.text}',
},
},
conditions: { conditions: {
cqSm: '@container(min-width: 320px)', child: '& > *', //子元素选择
child: '& > *',
}, },
theme: { theme: {
//核心主题配置
components: {
//组件样式
},
breakpoints: { breakpoints: {
//响应式断点
sm: '320px', sm: '320px',
md: '768px', md: '768px',
lg: '960px', lg: '960px',
@ -29,6 +25,7 @@ const config = defineConfig({
}, },
tokens: { tokens: {
//基础主题
colors: { colors: {
bg: '#f9fafb', bg: '#f9fafb',
text: '#1a202c', text: '#1a202c',
@ -46,6 +43,7 @@ const config = defineConfig({
}, },
semanticTokens: { semanticTokens: {
//自定义标记
colors: { colors: {
danger: { value: '{colors.red}' }, danger: { value: '{colors.red}' },
primary: { value: '{colors.primary}' }, primary: { value: '{colors.primary}' },
@ -54,6 +52,7 @@ const config = defineConfig({
}, },
keyframes: { keyframes: {
//关键帧
fadeIn: { fadeIn: {
from: { opacity: 0 }, from: { opacity: 0 },
to: { opacity: 1 }, to: { opacity: 1 },
@ -65,6 +64,7 @@ const config = defineConfig({
}, },
animationStyles: { animationStyles: {
//预定义动画样式
fadeIn: { fadeIn: {
animation: 'fadeIn 0.3s ease-in', animation: 'fadeIn 0.3s ease-in',
}, },
@ -74,6 +74,7 @@ const config = defineConfig({
}, },
textStyles: { textStyles: {
//文字样式
heading: { heading: {
description: 'Page heading', description: 'Page heading',
value: { value: {
@ -90,6 +91,7 @@ const config = defineConfig({
}, },
layerStyles: { layerStyles: {
//层样式
card: { card: {
bg: 'white', bg: 'white',
boxShadow: 'soft', boxShadow: 'soft',
@ -100,6 +102,4 @@ const config = defineConfig({
}, },
}); });
const system = createSystem(defaultConfig, config); export default createSystem(defaultConfig, config);
export default system;