Skip to content

Commit

Permalink
修复对话复制Bug;后端图片Size参数判断
Browse files Browse the repository at this point in the history
  • Loading branch information
NingNing0111 committed Apr 9, 2024
1 parent 7fc3fd5 commit ff0b93c
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 50 deletions.
36 changes: 18 additions & 18 deletions docker-compose-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ services:
networks:
- know-hub-network

minio:
image: minio/minio:latest
restart: always
container_name: minio
privileged: true
command: server --address ":9000" --console-address ":9001" /data
ports:
- "9000:9000"
- "9001:9001"
networks:
- know-hub-network
volumes:
- "./config:/root/.minio"
- "./data:/data"
environment:
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin
- MINIO_DEFAULT_BUCKETS=know-hub
# minio:
# image: minio/minio:latest
# restart: always
# container_name: minio
# privileged: true
# command: server --address ":9000" --console-address ":9001" /data
# ports:
# - "9000:9000"
# - "9001:9001"
# networks:
# - know-hub-network
# volumes:
# - "./config:/root/.minio"
# - "./data:/data"
# environment:
# - MINIO_ROOT_USER=minioadmin
# - MINIO_ROOT_PASSWORD=minioadmin
# - MINIO_DEFAULT_BUCKETS=know-hub

networks:
know-hub-network:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified know-hub-ai-backend/data/.minio.sys/buckets/.usage.json/xl.meta
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -53,12 +54,15 @@ public BaseResponse drawImage(@RequestBody DrawImageDTO drawImageDTO){
Integer height = options.height();
Integer width = options.width();
if(StrUtil.equals(options.model(),OpenAiImageApi.ImageModel.DALL_E_2.getValue())){
if(!dall2Size.contains(height) || !dall2Size.contains(width)){

// height 或 width不在指定范围内 或者 高 或 宽在指定范围内 但不相等 则不支持
if(dall2Size.contains(height) && !Objects.equals(height, width) || !dall2Size.contains(height) || !dall2Size.contains(width)){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"图片尺寸不支持");
}
}
if(StrUtil.equals(options.model(),OpenAiImageApi.ImageModel.DALL_E_3.getValue())){
if(!dall3Size.contains(height) || !dall3Size.contains(width)){
// height 或 width 不在指定范围内 或者 高宽相等并且等于1792 则大小不支持
if(!dall3Size.contains(height) || !dall3Size.contains(width) || height == 1792 && height.equals(width)){
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"图片尺寸不支持");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public record DrawOptions(String model,Integer width, Integer height,String form
* @param model AI绘图模型 dall-e-3或dall-e-2(默认)
* @param width 图片宽度 dall-e-2(256、512或1024)、dall-e-3(1024, 1792)
* @param height 图片高度 dall-e-2(256、512或1024)、dall-e-3(1024、1792)
* dall-e-2支持width * height,且width==height 的大小
* dall-e-3支持width * height,且width=1792 & width != height 的大小
* @param format 响应的格式 url或b64_json
*
*/
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.ningning0111.utils;

import cn.hutool.core.date.DateUtil;
import com.ningning0111.config.KnowHubAIConfig;
import io.minio.*;
import io.minio.http.Method;
import io.minio.messages.Bucket;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -30,13 +32,15 @@
@Slf4j
@Component
@Lazy // 懒加载 需要用到时 才注入
@RequiredArgsConstructor
public class MinioUtil {
@Value("${minio.endpoint}")
private String ENDPOINT;
@Value("${minio.access-key}")
private String ACCESS_KEY;
@Value("${minio.secret-key}")
private String SECRET_KEY ;
private final KnowHubAIConfig knowHubAIConfig;
public static String BUCKET_NAME ;
public static MinioClient minioClient;
@Value("${minio.bucket-name}")
Expand All @@ -49,14 +53,17 @@ public void setBucketName(String bucketName) {
*/
@PostConstruct
public void init() {
try {
log.info("Minio Initialize........................");
minioClient = MinioClient.builder().endpoint(ENDPOINT).credentials(ACCESS_KEY, SECRET_KEY).build();
createBucket(BUCKET_NAME);
log.info("Minio Initialize........................successful");
} catch (Exception e) {
e.printStackTrace();
log.error("初始化minio配置异常: 【{}】", e.fillInStackTrace());
// 如果开启了minio,则初始化minio客户端
if(knowHubAIConfig.isMinioEnabled()){
try {
log.info("Minio Initialize........................");
minioClient = MinioClient.builder().endpoint(ENDPOINT).credentials(ACCESS_KEY, SECRET_KEY).build();
createBucket(BUCKET_NAME);
log.info("Minio Initialize........................successful");
} catch (Exception e) {
e.printStackTrace();
log.error("初始化minio配置异常: 【{}】", e.fillInStackTrace());
}
}
}
/**
Expand Down
42 changes: 22 additions & 20 deletions know-hub-ai-backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@ spring:
username: ${PGVECTOR_USERNAME:postgres}
password: ${PGVECTOR_PASSWORD:postgres}
url: jdbc:postgresql://${PGVECTOR_HOST:localhost}/${PGVECTOR_DATABASE:know-hub}
# 8h待机自动断开数据库连接解决方案
tomcat:
max-active: 100
min-idle: 10
min-evictable-idle-time-millis: 1800000
test-on-borrow: true
test-on-return: true
test-while-idle: true
validation-query: select 1
type: com.zaxxer.hikari.HikariDataSource
# hikari连接池配置
hikari:
#连接池名
pool-name: HikariCP
#最小空闲连接数
minimum-idle: 5
# 空闲连接存活最大时间,默认10分钟
idle-timeout: 600000
# 连接池最大连接数,默认是10
maximum-pool-size: 10
# 此属性控制从池返回的连接的默认自动提交行为,默认值:true
auto-commit: true
# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认30分钟
max-lifetime: 1800000
# 数据库连接超时时间,默认30秒
connection-timeout: 30000
# 连接测试query
connection-test-query: SELECT 1

servlet:
multipart:
max-file-size: 20MB
Expand All @@ -23,16 +34,13 @@ spring:
hibernate:
ddl-auto: create


show-sql: true
open-in-view: true
# api和key分享自:https://pgthinker.me/2023/10/03/196/
ai:
openai:
base-url: https://api.mnzdna.xyz
api-key: sk-W0KF2fh5BTX3fEUvBf1262B948354c03B079C94956CfD4B5
# base-url: ${DEFAULT_BASE_URL}
# api-key: ${DEFAULT_API_KEY}
base-url: ${DEFAULT_BASE_URL}
api-key: ${DEFAULT_API_KEY}

# MinIO
minio:
Expand All @@ -41,15 +49,9 @@ minio:
secret-key: ${MINIO_SECRET_KEY:minioadmin}
bucket-name: ${BUCKET_NAME:know-hub}


server:
port: 8329

# know-hub-ai的配置
know-hub-ai:
minio-enabled: ${MINIO_DISABLED:false}





11 changes: 9 additions & 2 deletions know-hub-ai-frontend/src/view/chat/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@
<div class="card-header" v-if="item.role === 'user'">
<el-image :src="User" style="width: 50px; margin-right: 20px" />
<div>
<el-button type="primary" size="small">复制</el-button>
<el-button type="warning" size="small">删除</el-button>
<el-button
type="primary"
size="small"
@click="toCopy(item.content)"
>复制</el-button
>
<el-button type="warning" size="small" @click="toDelete(index)"
>删除</el-button
>
</div>
</div>
</template>
Expand Down
12 changes: 12 additions & 0 deletions know-hub-ai-frontend/src/view/draw/Draw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
/>
</el-select>
</el-form-item>
<el-form-item>
<el-text
>dall-e-2模型支持:<i>256 x 256、512 x 512、1024 x 1024</i></el-text
>
</el-form-item>
<el-form-item>
<el-text
>dall-e-3模型支持:<i
>1024 x 1024、1024 x 1792、1792 x 1024</i
></el-text
>
</el-form-item>
<el-form-item label="图片宽度:">
<el-radio-group v-model="drawDto.options.width" class="ml-4">
<template v-if="drawDto.options.model === 'dall-e-2'">
Expand Down

0 comments on commit ff0b93c

Please sign in to comment.