Skip to content

Commit

Permalink
Merge pull request #18 from lingmengcan/dev
Browse files Browse the repository at this point in the history
new db sql
  • Loading branch information
lingmengcan authored Sep 24, 2024
2 parents f6c07f7 + 04c0ce9 commit 15d6fda
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 66 deletions.
118 changes: 107 additions & 11 deletions doc/lingmengcan-ai.sql → doc/lingmengcan-ai-202409241125.sql

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,32 @@
"genorm": "rm -rf entities-template & npx typeorm-model-generator -h localhost -d lingmengcan -p 3306 -u root -x 123456 -e mysql -o entities-template --noConfig true --ce pascal --cp camel"
},
"dependencies": {
"@langchain/community": "^0.2.31",
"@langchain/core": "^0.2.28",
"@langchain/openai": "^0.2.7",
"@nestjs/common": "^10.4.1",
"@langchain/community": "^0.3.2",
"@langchain/core": "^0.3.3",
"@langchain/ollama": "^0.1.0",
"@langchain/openai": "^0.3.0",
"@nestjs/common": "^10.4.4",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.4.1",
"@nestjs/core": "^10.4.4",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.4.1",
"@nestjs/platform-express": "^10.4.4",
"@nestjs/serve-static": "^4.0.2",
"@nestjs/swagger": "^7.4.0",
"@nestjs/swagger": "^7.4.2",
"@nestjs/typeorm": "^10.0.2",
"@types/node-fetch": "^2.6.11",
"axios": "^1.7.5",
"axios": "^1.7.7",
"bcrypt": "^5.1.1",
"chromadb": "^1.8.1",
"chromadb": "^1.9.2",
"class-validator": "^0.14.1",
"dayjs": "^1.11.13",
"express-session": "^1.18.0",
"https-proxy-agent": "^7.0.5",
"js-yaml": "^4.1.0",
"langchain": "^0.2.17",
"langchain": "^0.3.2",
"mammoth": "^1.8.0",
"multer": "1.4.5-lts.1",
"mysql2": "^3.11.0",
"mysql2": "^3.11.3",
"node-fetch": "^3.3.2",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
Expand All @@ -58,22 +59,22 @@
"uuid": "^10.0.0"
},
"devDependencies": {
"@nestjs/cli": "^10.4.4",
"@nestjs/cli": "^10.4.5",
"@nestjs/schematics": "^10.1.4",
"@nestjs/testing": "^10.4.1",
"@nestjs/testing": "^10.4.4",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.21",
"@types/express-session": "^1.18.0",
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.13",
"@types/multer": "^1.4.12",
"@types/node": "^20.16.1",
"@types/node": "^20.16.6",
"@types/passport-jwt": "^4.0.1",
"@types/qs": "^6.9.15",
"@types/qs": "^6.9.16",
"@types/supertest": "^6.0.2",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
Expand All @@ -84,7 +85,7 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.5.4"
"typescript": "^5.6.2"
},
"jest": {
"moduleFileExtensions": [
Expand Down
19 changes: 7 additions & 12 deletions service/src/services/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { v4 as uuidv4 } from 'uuid';
import { File } from '@/entities/file.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { DataSource, Repository } from 'typeorm';
import { DocumentLoader } from 'langchain/dist/document_loaders/base';
import { ConfigService } from '@nestjs/config';
import { MessageService } from './message.service';
import { extname } from 'path';
import { ChatService } from './chat.service';
import { FileDto } from '@/dtos/file.dto';
import { LlmService } from './llm.service';
import { DocumentLoader } from '@langchain/core/document_loaders/base';

export class FileService {
constructor(
Expand Down Expand Up @@ -65,21 +65,23 @@ export class FileService {
}

// 文本切割,将文档拆分为块,这里要优化,不能只用中文符号切割
const textsplitter = new RecursiveCharacterTextSplitter({
const textSplitter = new RecursiveCharacterTextSplitter({
separators: ['\n\n', '\n', '。', '!', '?'],
chunkSize: 400,
chunkOverlap: 100,
});

// 加载文档并拆分
const docs = await loader.loadAndSplit(textsplitter);
const docs = await loader.load();

const splitDocs = await textSplitter.splitDocuments(docs);

const embeddings = modelName
? new OpenAIEmbeddings({ openAIApiKey, modelName }, { basePath })
: new OpenAIEmbeddings({ openAIApiKey }, { basePath });

// 加载向量存储库
await Chroma.fromDocuments(docs, embeddings, {
await Chroma.fromDocuments(splitDocs, embeddings, {
collectionName: fileId,
url: this.configService.get<string>('chromadb.db'),
});
Expand All @@ -93,14 +95,7 @@ export class FileService {
const fileType = extname(file.filename);

// 上传文件
const fileId = await this.addFile(
dto.conversationId,
file.originalname,
file.size,
fileType,
file.path,
userName,
);
const fileId = await this.addFile(dto.conversationId, file.originalname, file.size, fileType, file.path, userName);

await this.refactorVectorStore(
fileId,
Expand Down
4 changes: 4 additions & 0 deletions web/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ declare global {
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
const onUnmounted: typeof import('vue')['onUnmounted']
const onUpdated: typeof import('vue')['onUpdated']
const onWatcherCleanup: typeof import('vue')['onWatcherCleanup']
const provide: typeof import('vue')['provide']
const reactive: typeof import('vue')['reactive']
const readonly: typeof import('vue')['readonly']
Expand All @@ -53,10 +54,13 @@ declare global {
const useCssModule: typeof import('vue')['useCssModule']
const useCssVars: typeof import('vue')['useCssVars']
const useDialog: typeof import('naive-ui')['useDialog']
const useId: typeof import('vue')['useId']
const useLoadingBar: typeof import('naive-ui')['useLoadingBar']
const useMessage: typeof import('naive-ui')['useMessage']
const useModel: typeof import('vue')['useModel']
const useNotification: typeof import('naive-ui')['useNotification']
const useSlots: typeof import('vue')['useSlots']
const useTemplateRef: typeof import('vue')['useTemplateRef']
const watch: typeof import('vue')['watch']
const watchEffect: typeof import('vue')['watchEffect']
const watchPostEffect: typeof import('vue')['watchPostEffect']
Expand Down
30 changes: 15 additions & 15 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@vicons/antd": "^0.12.0",
"@vicons/ionicons5": "^0.12.0",
"@vueuse/core": "^10.11.1",
"axios": "^1.7.5",
"axios": "^1.7.7",
"dayjs": "^1.11.13",
"highlight.js": "^11.10.0",
"js-cookie": "^3.0.5",
Expand All @@ -26,41 +26,41 @@
"naive-ui": "^2.39.0",
"pinia": "^2.2.2",
"qs": "^6.13.0",
"vue": "^3.4.38",
"vue": "^3.5.8",
"vue-i18n": "^9.14.0",
"vue-masonry": "^0.16.0",
"vue-router": "^4.4.3"
"vue-router": "^4.4.5"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.14",
"@tailwindcss/typography": "^0.5.15",
"@tsconfig/node18": "^18.2.4",
"@types/markdown-it": "^14.1.2",
"@types/markdown-it-link-attributes": "^3.0.5",
"@types/node": "^20.16.1",
"@types/qs": "^6.9.15",
"@vitejs/plugin-vue": "^5.1.2",
"@types/node": "^20.16.6",
"@types/qs": "^6.9.16",
"@vitejs/plugin-vue": "^5.1.4",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/tsconfig": "^0.5.1",
"autoprefixer": "^10.4.20",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"eslint-define-config": "^2.1.0",
"eslint-plugin-vue": "^9.27.0",
"eslint-plugin-vue": "^9.28.0",
"less": "^4.2.0",
"less-loader": "^12.2.0",
"markdown-it-link-attributes": "^4.0.1",
"npm-run-all2": "^6.2.2",
"postcss": "^8.4.41",
"npm-run-all2": "^6.2.3",
"postcss": "^8.4.47",
"prettier": "^3.3.3",
"stylelint": "^16.8.2",
"stylelint": "^16.9.0",
"stylelint-config-recommended": "^14.0.1",
"stylelint-config-recommended-less": "^3.0.1",
"tailwindcss": "^3.4.10",
"tailwindcss": "^3.4.13",
"typescript": "~5.5.4",
"unplugin-auto-import": "^0.17.8",
"unplugin-vue-components": "^0.27.4",
"vite": "^5.4.2",
"vue-tsc": "^2.0.29"
"vite": "^5.4.7",
"vue-tsc": "^2.1.6"
}
}
16 changes: 8 additions & 8 deletions web/src/models/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ export interface ControlNetParams {

// 图生图请求参数,省性能,不做转换,命名改为下划线分割
export interface Img2ImgParams extends Txt2ImgParams {
init_images: string[]; // 初始化图像的数组
init_images: string[]; // 初始图像(要求使用base64列表)
resize_mode: number; // 调整大小的模式
image_cfg_scale: number; // 图像配置的缩放比例
mask: string; // 掩码
mask_blur_x: number; // 掩码在 x 方向的模糊程度
mask_blur_y: number; // 掩码在 y 方向的模糊程度
mask_blur: number; // 掩码的整体模糊程度
mask_round: boolean; // 掩码是否为圆形
mask: string; // 蒙版base64
mask_blur_x: number; // 蒙版边缘在 x 方向的模糊程度
mask_blur_y: number; // 蒙版边缘在 y 方向的模糊程度
mask_blur: number; // 蒙版边缘模糊
mask_round: boolean; // 蒙版是否为圆形
inpainting_fill: number; // 修复绘画的填充方式
inpaint_full_res: boolean; // 是否为全分辨率的修复绘画
inpaint_full_res_padding: number; // 全分辨率修复绘画的填充值
inpainting_mask_invert: number; // 修复绘画掩码的反转
inpainting_mask_invert: number; // 0 正常,1 则反转蒙版
initial_noise_multiplier: number; // 初始噪声的乘数
latent_mask: string; // 潜在的掩码
latent_mask: string; // 潜在的蒙版
include_init_images: boolean; // 是否包含初始化图像
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/router/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function createRouterGuards(router: Router) {
});

router.afterEach((to, _, failure) => {
document.title = to?.meta?.title ? `${document.title}-${to.meta.title}` : document.title;
document.title = to?.meta?.title ? `${import.meta.env.VITE_APP_TITLE}-${to.meta.title}` : document.title;

if (isNavigationFailure(failure)) {
}
Expand Down
4 changes: 3 additions & 1 deletion web/src/views/draw/generate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<n-tab-pane name="txt2img" :tab="$t('views.draw.stableDiffusion.txt2img')" class="flex flex-col h-full">
<stableDiffusion v-model:txt2imgParams="txt2imgParams" v-model:loraList="loraList" />
</n-tab-pane>
<n-tab-pane name="img2img" :tab="$t('views.draw.stableDiffusion.img2img')"></n-tab-pane>
<n-tab-pane name="img2img" :tab="$t('views.draw.stableDiffusion.img2img')" class="flex flex-col h-full">
<stableDiffusion v-model:txt2imgParams="txt2imgParams" v-model:loraList="loraList" />
</n-tab-pane>
<n-tab-pane name="2video" :tab="$t('views.draw.stableDiffusion.genVideo')" disabled></n-tab-pane>
</n-tabs>
<div class="flex justify-center pt-3 border-t">
Expand Down

0 comments on commit 15d6fda

Please sign in to comment.