Skip to content

Commit 9e653d9

Browse files
committed
2.24.1
1 parent c60d02b commit 9e653d9

File tree

8 files changed

+158
-9
lines changed

8 files changed

+158
-9
lines changed

changlog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# 功能升级日志
22

33
# 计划
4+
# 2.24.1
5+
- 😄 新增:gpt-image-1 dall.e-2 支持 v1/image/edit 支持多图
6+
- 🐞 改进:默认上传改为5M
7+
48
# 2.23.10
59

610
- 😄 新增:gpt-image-1 这个是dall-e格式

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chatgpt-web-midjourney-proxy",
3-
"version": "2.23.10",
3+
"version": "2.24.1",
44
"private": false,
55
"description": "ChatGPT Web Midjourney Proxy",
66
"author": "Dooy <ydlhero@gmail.com>",

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"package": {
1010
"productName": "ChatGPT-MJ",
11-
"version": "2.23.10"
11+
"version": "2.24.1"
1212
},
1313
"tauri": {
1414
"allowlist": {

src/api/mjapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface gptsType{
1818
//const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
1919
export function upImg(file:any ):Promise<any>
2020
{
21-
const maxSize= homeStore.myData.session.uploadImgSize? (+homeStore.myData.session.uploadImgSize):1
21+
const maxSize= homeStore.myData.session.uploadImgSize? (+homeStore.myData.session.uploadImgSize):5
2222
return new Promise((h,r)=>{
2323
const filename = file.name;
2424
if(file.size>(1024*1024 * maxSize)){

src/api/openapi.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,20 @@ export const whisperUpload = ( FormData:FormData )=>{
225225
})
226226
}
227227

228+
//gpt 文件上传 /v1/image/edits
229+
export const gptUploadFile= (url :string, FormData:FormData)=>{
230+
url= gptGetUrl( url);
231+
let headers= {'Content-Type': 'multipart/form-data' }
232+
headers={...headers,...getHeaderAuthorization()}
233+
234+
return axios.post( url , FormData, { headers })
235+
236+
}
237+
228238
export const subGPT= async (data:any, chat:Chat.Chat )=>{
229239
let d:any;
230240
let action= data.action;
241+
// mlog("gp-image-1 base64Array ", data.base64Array )
231242
//chat.myid= `${Date.now()}`;
232243
if( action=='gpt.dall-e-3' && data.data && data.data.model && data.data.model.indexOf('ideogram')>-1 ){ //ideogram
233244
mlog("ddlog 数据 ", data.data )
@@ -246,6 +257,50 @@ export const subGPT= async (data:any, chat:Chat.Chat )=>{
246257
chat.loading=false;
247258
homeStore.setMyData({act:'updateChat', actData:chat });
248259
}
260+
}else if( action=='gpt.dall-e-3' && data.data.base64Array!=undefined ){ //执行变化
261+
mlog("gp-image-1 base64Array ",data.data , data.data.base64Array )
262+
//let d= await gptFetch('/v1/images/edits', data.data);
263+
const formData = new FormData( );
264+
for(let o in data.data ){
265+
if(o=='base64Array'){
266+
for(let f of data.data.base64Array){
267+
formData.append('image[]', f.file )
268+
}
269+
}else{
270+
formData.append(o, data.data[o])
271+
}
272+
273+
274+
}
275+
mlog("formData ", formData )
276+
277+
//const jda= upd.data
278+
try {
279+
const ds = await gptUploadFile('/v1/images/edits', formData)
280+
const d=ds.data;
281+
if(ds.status!=200) throw "Fail with status:"+ ds.status
282+
//const d= jda;
283+
//mlog("gp-image-1 结果 ", d )
284+
285+
286+
let key= 'dall:'+chat.myid;
287+
const rz : any= d.data[0];
288+
if(rz.b64_json){
289+
const base64='data:image/png;base64,'+rz.b64_json;
290+
await localSaveAny(base64,key)
291+
}
292+
293+
chat.text= rz.revised_prompt??`图片已完成`;
294+
chat.opt={imageUrl:rz.url?rz.url: 'https://www.openai-hk.com/res/img/open.png' } ;
295+
chat.loading = false;
296+
homeStore.setMyData({act:'updateChat', actData:chat });
297+
} catch (e) {
298+
chat.text='失败!'+"\n```json\n"+ (d?JSON.stringify(d, null, 2):e) +"\n```\n";
299+
chat.loading=false;
300+
homeStore.setMyData({act:'updateChat', actData:chat });
301+
}
302+
303+
249304
}else if( action=='gpt.dall-e-3' ){ //执行变化
250305
// chat.model= 'dall-e-3';
251306

src/locales/zh-CN.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default {
175175
,tQuality:'画质'
176176
,tStyles:'艺术程度'
177177
,tVersion:'模型版本'
178-
,dalleInfo:' 说明: <li>1 dall-e 是openAi提供的画图模型</li> <li>2 openAi的图片有时效性,请做好备份</li> <li>3 注意:1790px的图片价格是双倍</li> '
178+
,dalleInfo:' 说明: <li>1 dall-e 是openAi提供的画图模型</li> <li>2 openAi的图片有时效性,请做好备份</li> <li>3 注意:1790px的图片价格是双倍</li> <li>4 注意:dall-e-2、gpt-image-1 支持多图参考</li> '
179179
,version:'版本'
180180
,size:'尺寸'
181181
,blendInfo:'说明: <li>1 合成至少2张图片</li> <li>2 最多可传6张图</li> '

src/views/mj/aiDall.vue

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script setup lang="ts">
22
import { ref ,computed,watch} from 'vue';
3-
import {useMessage, NButton,NSelect,NInput} from 'naive-ui';
3+
import {useMessage, NButton,NSelect,NInput, NImage} from 'naive-ui';
44
import {gptFetch, mlog, upImg} from '@/api'
55
import { homeStore } from '@/store';
66
import { SvgIcon } from '@/components/common';
7+
import { t } from '@/locales';
78
89
const ms = useMessage();
910
const config = ref( {
@@ -17,7 +18,13 @@ model:[
1718
,{ "label": "Flux.1.1-Pro", "value": "flux.1.1-pro" }
1819
]
1920
});
20-
const st =ref({isGo:false });
21+
interface myFile{
22+
file:any
23+
base64:string
24+
}
25+
const st =ref({isGo:false,quality:'medium' });
26+
const fsRef= ref() ;
27+
const base64Array= ref<myFile[]>([]);
2128
const f = ref({size:'1024x1024', prompt:'',"model": "dall-e-3","n": 1});
2229
const isDisabled= computed(()=>{
2330
if(st.value.isGo) return true;
@@ -33,7 +40,16 @@ const create= async ()=>{
3340
//return ;
3441
let obj= {
3542
action:'gpt.dall-e-3',
36-
data:f.value
43+
data:{} //f.value
44+
}
45+
obj.data= { ...f.value}
46+
if(isCanImageEdit.value){
47+
obj.data= {...obj.data ,quality:st.value.quality};
48+
}
49+
if (isCanImageEdit.value && base64Array.value.length>0){
50+
51+
obj.data= {...obj.data, 'base64Array':base64Array.value,quality:st.value.quality};
52+
mlog("data", '我加东西了:', base64Array.value )
3753
}
3854
homeStore.setMyData({act:'draw', actData:obj});
3955
st.value.isGo=true;
@@ -46,6 +62,15 @@ watch(()=>homeStore.myData.act,(n)=>{
4662
if(n=='updateChat') st.value.isGo=false;
4763
})
4864
65+
66+
const qualityOption= computed(()=>{
67+
return [
68+
{label:'High',value: 'high'}
69+
,{label:'Medium',value: 'medium'}
70+
,{label:'Low',value: 'low'}
71+
72+
]
73+
});
4974
const dimensionsList= computed(()=>{
5075
if(f.value.model=='dall-e-2'){
5176
return [{
@@ -60,6 +85,19 @@ const dimensionsList= computed(()=>{
6085
}
6186
];
6287
}
88+
if(f.value.model=='gpt-image-1'){
89+
return [{
90+
"label": "1024px*1024px",
91+
"value": "1024x1024"
92+
}, {
93+
"label": "1536px*1024px",
94+
"value": "1536x1024"
95+
}, {
96+
"label": "1024px*1536px",
97+
"value": "1024x1536"
98+
}
99+
];
100+
}
63101
return [{
64102
"label": "1024px*1024px",
65103
"value": "1024x1024"
@@ -76,6 +114,27 @@ const dimensionsList= computed(()=>{
76114
watch(()=>f.value.model,(n)=>{
77115
f.value.size='1024x1024';
78116
})
117+
const isCanImageEdit= computed(()=>{
118+
if(f.value.model=='dall-e-2') return true;
119+
if(f.value.model=='gpt-image-1') return true;
120+
return false;
121+
})
122+
123+
const selectFile=(input:any)=>{
124+
const ff=input.target.files[0];
125+
upImg(input.target.files[0]).then(d=>{
126+
fsRef.value.value='';
127+
const index = base64Array.value.findIndex(item => item.base64 == d);
128+
if(index>-1){
129+
ms.error(t('mjchat.no2add') )
130+
return ;
131+
}
132+
base64Array.value.push({file: ff ,base64:d});
133+
if(base64Array.value.length>1) st.value.isGo=true;
134+
//if(st)
135+
}).catch(e=>ms.error(e));
136+
}
137+
79138
</script>
80139
<template>
81140
<section class="mb-4 flex justify-between items-center" >
@@ -86,10 +145,32 @@ watch(()=>f.value.model,(n)=>{
86145
<div>{{ $t('mjchat.size') }}</div>
87146
<n-select v-model:value="f.size" :options="dimensionsList" filterable tag size="small" class="!w-[70%]" :clearable="false" />
88147
</section>
148+
<section class="mb-4 flex justify-between items-center" v-if="isCanImageEdit" >
149+
<div>Quality</div>
150+
<n-select v-model:value="st.quality" :options="qualityOption" filterable tag size="small" class="!w-[70%]" :clearable="false" />
151+
</section>
152+
89153
<div class="mb-1">
90154
<n-input type="textarea" v-model:value="f.prompt" :placeholder="$t('mjchat.prompt')" round clearable maxlength="500" show-count
91155
:autosize="{ minRows:3, maxRows:10 }" />
92156
</div>
157+
<div class="mb-1" v-if="isCanImageEdit">
158+
<div class="flex justify-start items-center flex-wrap myblend">
159+
160+
<div class="w-[var(--my-blend-img-size)] h-[var(--my-blend-img-size)] mr-2 mt-2 bg-[#ddd] overflow-hidden rounded-sm relative group " v-for="item in base64Array">
161+
<NImage :src="item.base64" object-fit="cover"></NImage>
162+
<SvgIcon icon="fluent:delete-12-filled"
163+
class="absolute top-0 right-0 text-red-600 text-[20px] cursor-pointer hidden group-hover:block "
164+
@click="base64Array.splice(base64Array.indexOf(item),1)"></SvgIcon>
165+
</div>
166+
167+
<div @click="fsRef.click()" v-if="base64Array.length<3"
168+
class="w-[var(--my-blend-img-size)] h-[var(--my-blend-img-size)] mt-2 bg-[#999] overflow-hidden rounded-sm flex justify-center items-center cursor-pointer">
169+
<SvgIcon icon="mdi:add-bold" class="text-[40px] text-[#fff]"></SvgIcon>
170+
</div>
171+
172+
</div>
173+
</div>
93174

94175
<div class="mb-4 flex justify-end items-center">
95176
<div class="flex ">
@@ -103,4 +184,13 @@ watch(()=>f.value.model,(n)=>{
103184
<ul class="pt-4" v-html="$t('mjchat.dalleInfo')">
104185

105186
</ul>
106-
</template>
187+
188+
<input type="file" @change="selectFile" ref="fsRef" style="display: none" accept="image/jpeg, image/jpg, image/png, image/gif"/>
189+
190+
</template>
191+
192+
<style scoped>
193+
.myblend{
194+
--my-blend-img-size:75px
195+
}
196+
</style>

src/views/mj/aiDrawInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ initLoad();
7979

8080
<n-tab-pane name="ideogram" tab="IdeoGram">
8181
<div class="p-2"> <aiIdeoInput/> </div>
82-
</n-tab-pane>
82+
</n-tab-pane>
8383

8484

8585

0 commit comments

Comments
 (0)