Merge branch 'main' of github.com:ZhiShuYun/AIFrontend

This commit is contained in:
AceDataCloud committed 2023-10-17 22:22:57 +08:00
commit ab3016534f
23 files changed
+805 -143

No files matched your search

+2
View File
@@ -30,5 +30,7 @@ export default defineComponent({
.info {
font-size: 14px;
color: var(--el-text-color-regular);
display: block;
text-align: center;
}
</style>
@@ -0,0 +1,65 @@
<template>
<div class="field">
<h2 class="title">高级模式</h2>
<el-switch v-model="value" class="ml-2" />
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSwitch } from 'element-plus';
const DEFAULT_ADVANCED = false;
export default defineComponent({
name: 'AdvancedSelector',
components: {
ElSwitch
},
props: {
modelValue: {
type: Boolean,
default: false
}
},
emits: ['update:modelValue'],
data() {
return {
value: this.modelValue
};
},
watch: {
modelValue(val) {
if (val !== this.value) {
this.value = val;
}
},
value(val) {
this.$emit('update:modelValue', val);
}
},
mounted() {
if (this.value === undefined) {
this.value = DEFAULT_ADVANCED;
}
this.$emit('update:modelValue', this.value);
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
.title {
font-size: 14px;
margin-bottom: 0;
width: 30%;
}
.value {
flex: 1;
}
}
</style>
+31 -33
View File
@@ -1,27 +1,16 @@
<template>
<div class="model-selector">
<el-dropdown trigger="click" @command="onCommandChange">
<el-button>
<font-awesome-icon class="icon" icon="fa-regular fa-" />
<span>
{{ value.displayName }}
</span>
<font-awesome-icon icon="fa-solid fa-chevron-down" />
</el-button>
<template #dropdown>
<el-dropdown-menu class="menu">
<el-dropdown-item
v-for="(channel, channelIndex) in options"
:key="channelIndex"
:command="channel"
class="option"
>
<font-awesome-icon :icon="channel.icon" />
{{ channel.displayName }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<div class="channel-selector">
<el-button
v-for="(option, optionKey) in options"
:key="optionKey"
:class="{ button: true, active: option.name === value.name }"
@click="onSelect(option)"
>
<font-awesome-icon :class="{ icon: true, [option.name]: true }" :icon="option.icon" />
<span>
{{ option.displayName }}
</span>
</el-button>
</div>
</template>
@@ -39,9 +28,7 @@ import {
export default defineComponent({
name: 'ModelSelector',
components: {
ElDropdown,
ElButton,
ElDropdownItem,
FontAwesomeIcon
},
props: {
@@ -50,7 +37,7 @@ export default defineComponent({
required: true
}
},
emits: ['update:modelValue'],
emits: ['update:modelValue', 'select'],
data() {
return {
value: this.modelValue,
@@ -64,22 +51,30 @@ export default defineComponent({
}
}
},
mounted() {
this.$emit('update:modelValue', this.value);
this.$emit('select', this.value);
},
methods: {
onCommandChange(command: IMidjourneyChannel) {
this.value = command;
this.$emit('update:modelValue', command);
onSelect(option: IMidjourneyChannel) {
this.value = option;
this.$emit('update:modelValue', option);
this.$emit('select', option);
}
}
});
</script>
<style lang="scss" scoped>
.model-selector {
.channel-selector {
background-color: #ececf1;
padding: 7px 6px;
border-radius: 15px;
margin-bottom: 5px;
.group {
width: 372px;
margin-left: auto;
margin-right: auto;
.button {
padding: 20px 30px;
color: black;
border: none;
@@ -96,10 +91,13 @@ export default defineComponent({
.icon {
display: inline-block;
margin-right: 5px;
&.base {
&.turbo {
color: #ff9900;
}
&.plus {
&.fast {
color: #2dc49c;
}
&.relax {
color: #ce65e6;
}
}
+10 -4
View File
@@ -16,7 +16,7 @@
item: true,
active: value.includes(item.value)
}"
@click="onChoose(item.value)"
@click="onToggle(item.value)"
>
<el-image :src="item.image" fit="fill" class="preview" />
<span class="name">{{ item.label }}</span>
@@ -125,9 +125,15 @@ export default defineComponent({
this.$emit('update:modelValue', this.value);
},
methods: {
onChoose(value: string) {
this.value.push(value);
this.$emit('update:modelValue', this.value);
onToggle(value: string) {
if (this.value.includes(value)) {
this.value.splice(this.value.indexOf(value), 1);
this.$emit('update:modelValue', this.value);
return;
} else {
this.value.push(value);
this.$emit('update:modelValue', this.value);
}
}
}
});
@@ -1,50 +0,0 @@
<template>
<div class="preview">
<el-image
v-if="modelValue?.image_url"
v-loading="state === midjourneyImagineState.PENDING"
:src="modelValue?.image_url"
fit="fill"
class="image"
/>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElImage } from 'element-plus';
import { IMidjourneyImagineResponse, MidjourneyImagineState } from '@/operators';
export default defineComponent({
name: 'ImaginePreview',
components: {
ElImage
},
props: {
modelValue: {
type: Object as () => IMidjourneyImagineResponse,
default: undefined
},
state: {
type: Object as () => MidjourneyImagineState,
default: undefined
}
},
data() {
return {
midjourneyImagineState: MidjourneyImagineState
};
}
});
</script>
<style lang="scss" scoped>
.preview {
width: 100%;
text-align: center;
.image {
width: 200px;
height: 200px;
}
}
</style>
+19 -6
View File
@@ -1,10 +1,14 @@
<template>
<div class="panel">
<model-selector v-model="preset.model" class="block" />
<ratio-selector v-model="preset.ratio" class="block" />
<version-selector v-model="preset.version" class="block" />
<stylize-selector v-model="preset.stylize" class="block" />
<chaos-selector v-model="preset.chaos" class="block" />
<model-selector v-if="false" v-model="preset.model" class="mb-4" />
<ratio-selector v-model="preset.ratio" class="mb-4" />
<quality-selector v-model="preset.quality" class="mb-4" />
<version-selector v-model="preset.version" class="mb-4" />
<advanced-selector v-model="preset.advanced" class="mb-4" />
<stylize-selector v-if="preset.advanced" v-model="preset.stylize" class="mb-4" />
<wired-selector v-if="preset.advanced" v-model="preset.wired" class="mb-4" />
<chaos-selector v-if="preset.advanced" v-model="preset.chaos" class="mb-4" />
<raw-selector v-if="preset.advanced" v-model="preset.raw" class="mb-4" />
</div>
</template>
@@ -15,14 +19,23 @@ import VersionSelector from './VersionSelector.vue';
import StylizeSelector from './StylizeSelector.vue';
import ChaosSelector from './ChaosSelector.vue';
import ModelSelector from './ModelSelector.vue';
import QualitySelector from './QualitySelector.vue';
import WiredSelector from './WiredSelector.vue';
import RawSelector from './RawSelector.vue';
import AdvancedSelector from './AdvancedSelector.vue';
export default defineComponent({
name: 'PresetPanel',
components: {
ModelSelector,
QualitySelector,
RatioSelector,
VersionSelector,
StylizeSelector,
ChaosSelector
ChaosSelector,
WiredSelector,
RawSelector,
AdvancedSelector
},
props: {
modelValue: {
@@ -0,0 +1,85 @@
<template>
<div class="field">
<h2 class="title">画质</h2>
<el-radio-group v-model="value">
<el-radio-button v-for="item in options" :key="item.value" :label="item.value">
{{ item.label }}
</el-radio-button>
</el-radio-group>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElRadioButton, ElRadioGroup } from 'element-plus';
export const DEFAULT_QUALITY = '.5';
export default defineComponent({
name: 'QualitySelector',
components: {
ElRadioButton,
ElRadioGroup
},
props: {
modelValue: {
type: String,
default: undefined
}
},
emits: ['update:modelValue'],
data() {
return {
value: this.modelValue,
active: 0,
options: [
{
label: '低',
value: '.25'
},
{
label: '中',
value: '.5'
},
{
label: '高',
value: '1'
}
]
};
},
watch: {
modelValue(val) {
if (val !== this.value) {
this.value = val;
}
},
value(val) {
this.$emit('update:modelValue', val);
}
},
mounted() {
if (!this.value) {
this.value = DEFAULT_QUALITY;
}
this.$emit('update:modelValue', this.value);
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
.title {
font-size: 14px;
margin-bottom: 0;
width: 30%;
}
.value {
flex: 1;
}
}
</style>
+65
View File
@@ -0,0 +1,65 @@
<template>
<div class="field">
<h2 class="title">原生</h2>
<el-switch v-model="value" class="ml-2" />
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSwitch } from 'element-plus';
const DEFAULT_RAW = false;
export default defineComponent({
name: 'RawSelector',
components: {
ElSwitch
},
props: {
modelValue: {
type: Boolean,
default: false
}
},
emits: ['update:modelValue'],
data() {
return {
value: this.modelValue
};
},
watch: {
modelValue(val) {
if (val !== this.value) {
this.value = val;
}
},
value(val) {
this.$emit('update:modelValue', val);
}
},
mounted() {
if (this.value === undefined) {
this.value = DEFAULT_RAW;
}
this.$emit('update:modelValue', this.value);
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
.title {
font-size: 14px;
margin-bottom: 0;
width: 30%;
}
.value {
flex: 1;
}
}
</style>
+104
View File
@@ -0,0 +1,104 @@
<template>
<div class="tasks">
<div v-for="(task, taskKey) in tasks" :key="taskKey" class="task">
<task-preview :model-value="task" @custom="$emit('custom', $event)" />
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import TaskPreview from './TaskPreview.vue';
import {
IApplication,
IMidjourneyImagineTask,
MidjourneyImagineState,
apiUsageOperator,
midjourneyOperator
} from '@/operators';
interface IData {
historyTasks: IMidjourneyImagineTask[];
}
export default defineComponent({
name: 'TaskBriefList',
components: {
TaskPreview
},
props: {
activeTask: {
type: Object as () => IMidjourneyImagineTask | undefined,
required: true
},
application: {
type: Object as () => IApplication | undefined,
required: true
}
},
emits: ['update:modelValue', 'custom', 'update:activeTask'],
data(): IData {
return {
historyTasks: []
};
},
computed: {
tasks() {
return [...(this.activeTask ? [this.activeTask] : []), ...this.historyTasks];
}
},
watch: {
application(val) {
if (val) {
this.getHistoryTasks();
}
},
activeTask(val: IMidjourneyImagineTask | undefined, oldVal: IMidjourneyImagineTask | undefined) {
if (
(val?.state === MidjourneyImagineState.FINISHED && oldVal?.state !== MidjourneyImagineState.FINISHED) ||
(val?.state === MidjourneyImagineState.FAILED && oldVal?.state !== MidjourneyImagineState.FAILED)
) {
console.log('need to refresh history tasks');
this.getHistoryTasks();
this.$emit('update:activeTask', undefined);
}
}
},
methods: {
async getHistoryTasks() {
const {
data: { items: apiUsages }
} = await apiUsageOperator.getAll({
user_id: this.$store.state.user.id,
application_id: this.application?.id,
offset: 0,
limit: 5,
ordering: '-created_at'
});
const tasks = await Promise.all(
apiUsages.map(async (apiUsage) => {
const taskId = apiUsage.metadata?.task_id;
const { data: task } = await midjourneyOperator.task(taskId);
if (task.response?.success === false) {
task.state = MidjourneyImagineState.FAILED;
}
return task;
})
);
this.historyTasks = tasks.filter((task) => task && task?.response);
}
}
});
</script>
<style lang="scss" scoped>
.tasks {
padding-top: 20px;
height: 100%;
overflow-y: scroll;
border-left: 1px solid var(--el-border-color);
display: flex;
flex-direction: column;
align-items: center;
}
</style>
+172
View File
@@ -0,0 +1,172 @@
<template>
<div class="preview">
<div class="info mb-4">
<div class="left">
<el-tag v-if="modelValue?.response?.success === true" type="success">成功</el-tag>
<el-tag v-if="modelValue?.response?.success === false" type="danger">失败</el-tag>
</div>
<div class="right"></div>
</div>
<div v-if="modelValue?.state === midjourneyImagineState.PENDING" class="content">
<el-image class="image">
<template #error>
<div class="image-slot">Loading...</div>
</template>
</el-image>
</div>
<div v-else-if="modelValue?.state === midjourneyImagineState.FAILED" class="content">
<el-image class="image">
<template #error>
<div class="image-slot">{{ modelValue?.response?.detail }}</div>
</template>
</el-image>
</div>
<div v-else class="content">
<el-image
v-if="modelValue?.response?.image_url"
:src="modelValue?.response?.image_url"
:preview-src-list="[modelValue?.response?.image_url as string]"
fit="fill"
class="image"
/>
<p v-if="modelValue?.response?.progress !== undefined && modelValue?.response?.progress !== 100" class="progress">
{{ modelValue?.response?.progress }}%
</p>
</div>
<div class="operations">
<el-button
v-for="(action, actionKey) in modelValue?.response?.actions"
:key="actionKey"
type="info"
size="small"
class="btn-action"
@click="onCustom(action)"
>
{{ actionMapping[action] }}
</el-button>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElImage, ElTag, ElButton } from 'element-plus';
import { IMidjourneyImagineTask, MidjourneyImagineAction, MidjourneyImagineState } from '@/operators';
interface IData {
midjourneyImagineState: typeof MidjourneyImagineState;
actionMapping: Record<MidjourneyImagineAction, string>;
}
export default defineComponent({
name: 'TaskPreview',
components: {
ElImage,
ElTag,
ElButton
},
props: {
modelValue: {
type: Object as () => IMidjourneyImagineTask | undefined,
required: true
}
},
emits: ['custom'],
data(): IData {
return {
midjourneyImagineState: MidjourneyImagineState,
actionMapping: {
[MidjourneyImagineAction.GENERATE]: 'Generate',
[MidjourneyImagineAction.UPSAMPLE1]: 'U1',
[MidjourneyImagineAction.UPSAMPLE2]: 'U2',
[MidjourneyImagineAction.UPSAMPLE3]: 'U3',
[MidjourneyImagineAction.UPSAMPLE4]: 'U4',
[MidjourneyImagineAction.VARIATION1]: 'V1',
[MidjourneyImagineAction.VARIATION2]: 'V2',
[MidjourneyImagineAction.VARIATION3]: 'V3',
[MidjourneyImagineAction.VARIATION4]: 'V4',
[MidjourneyImagineAction.HIGH_VARIATION]: 'Vary (Strong)',
[MidjourneyImagineAction.LOW_VARIATION]: 'Vary (Subtle)',
[MidjourneyImagineAction.ZOOM_OUT_2X]: 'Zoom Out 2x',
[MidjourneyImagineAction.ZOOM_OUT_1_5X]: 'Zoom Out 1.5x',
[MidjourneyImagineAction.SQUARE]: 'Make Square',
[MidjourneyImagineAction.PAN_LEFT]: '⬅️',
[MidjourneyImagineAction.PAN_UP]: '⬆️',
[MidjourneyImagineAction.PAN_DOWN]: '⬇️',
[MidjourneyImagineAction.PAN_RIGHT]: '➡️',
[MidjourneyImagineAction.REROLL]: '🔄'
}
};
},
methods: {
onCustom(action: string) {
this.$emit('custom', {
action,
image_id: this.modelValue?.response?.image_id
});
}
}
});
</script>
<style lang="scss" scoped>
.preview {
width: 350px;
padding: 15px;
display: flex;
flex-direction: column;
align-items: center;
border-radius: 20px;
margin-bottom: 20px;
border: 1px solid var(--el-border-color);
.info {
display: flex;
flex-direction: row;
justify-content: stretch;
width: 100%;
}
.content {
width: 100%;
position: relative;
margin-bottom: 10px;
.image {
width: 100%;
min-height: 200px;
.image-slot {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
background: var(--el-fill-color-light);
color: var(--el-text-color-secondary);
// font-size: 30px;
}
}
.progress {
position: absolute;
top: 49%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 20px;
font-weight: bold;
color: white;
text-shadow: 0 0 5px black;
}
}
.operations {
display: flex;
justify-content: center;
flex-direction: row;
width: 100%;
align-items: baseline;
flex-wrap: wrap;
.btn-action {
margin-bottom: 10px;
}
}
}
</style>
@@ -1,7 +1,7 @@
<template>
<div class="field">
<h2 class="title">版本</h2>
<el-select v-model="value" class="value" placeholder="Select" size="small">
<el-select v-model="value" class="value" placeholder="Select">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>
@@ -0,0 +1,64 @@
<template>
<div class="field">
<h2 class="title">怪异度</h2>
<el-slider v-model="value" :min="0" :max="1000" :step="1" class="value" />
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSlider } from 'element-plus';
const DEFAULT_WIRED = 0;
export default defineComponent({
name: 'WiredSelector',
components: {
ElSlider
},
props: {
modelValue: {
type: String,
default: undefined
}
},
emits: ['update:modelValue'],
data() {
return {
value: this.modelValue
};
},
watch: {
modelValue(val) {
if (val !== this.value) {
this.value = val;
}
},
value(val) {
this.$emit('update:modelValue', val);
}
},
mounted() {
if (!this.value) {
this.value = DEFAULT_WIRED;
}
this.$emit('update:modelValue', this.value);
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
.title {
font-size: 14px;
margin-bottom: 0;
width: 30%;
}
.value {
flex: 1;
}
}
</style>
+2
View File
@@ -0,0 +1,2 @@
export const ENDPOINT_API = 'https://api.zhishuyun.com';
export const ENDPOINT_DATA = 'https://data.zhishuyun.com';
+1
View File
@@ -4,3 +4,4 @@ export * from './user';
export * from './api';
export * from './chat';
export * from './midjourney';
export * from './usage';
+6 -6
View File
@@ -1,29 +1,29 @@
import { IMidjourneyChannel } from './models';
export const MIDJOURNEY_CHANNEL_NAME_FAST = 'Fast';
export const MIDJOURNEY_CHANNEL_NAME_RELAX = 'Relax';
export const MIDJOURNEY_CHANNEL_NAME_TURBO = 'Turbo';
export const MIDJOURNEY_CHANNEL_NAME_FAST = 'fast';
export const MIDJOURNEY_CHANNEL_NAME_RELAX = 'relax';
export const MIDJOURNEY_CHANNEL_NAME_TURBO = 'turbo';
export const API_ID_MIDJOURNEY_FAST = '9a628863-8879-462b-bbee-5dc46505b733';
export const API_ID_MIDJOURNEY_RELAX = 'c58713f3-fef7-4c18-824c-9f76b5a07a7f';
export const API_ID_MIDJOURNEY_TURBO = '62ec82bd-7de3-427f-b71a-ab3551ac7677';
export const MIDJOURNEY_CHANNEL_FAST: IMidjourneyChannel = {
icon: 'fa-bolt fa-regular',
icon: 'fa-solid fa-wind',
apiId: API_ID_MIDJOURNEY_FAST,
name: MIDJOURNEY_CHANNEL_NAME_FAST,
displayName: 'Fast'
};
export const MIDJOURNEY_CHANNEL_RELAX: IMidjourneyChannel = {
icon: 'fa-bolt fa-regular',
icon: 'fa-solid fa-mug-saucer',
apiId: API_ID_MIDJOURNEY_RELAX,
name: MIDJOURNEY_CHANNEL_NAME_RELAX,
displayName: 'Relax'
};
export const MIDJOURNEY_CHANNEL_TURBO: IMidjourneyChannel = {
icon: 'fa-bolt fa-regular',
icon: 'fa-solid fa-bolt',
apiId: API_ID_MIDJOURNEY_TURBO,
name: MIDJOURNEY_CHANNEL_NAME_TURBO,
displayName: 'Turbo'
+32 -6
View File
@@ -15,7 +15,24 @@ export interface IMidjourneyPreset {
export enum MidjourneyImagineAction {
GENERATE = 'generate',
UPSAMPLE1 = 'upsample1'
UPSAMPLE1 = 'upsample1',
UPSAMPLE2 = 'upsample2',
UPSAMPLE3 = 'upsample3',
UPSAMPLE4 = 'upsample4',
VARIATION1 = 'variation1',
VARIATION2 = 'variation2',
VARIATION3 = 'variation3',
VARIATION4 = 'variation4',
HIGH_VARIATION = 'high_variation',
LOW_VARIATION = 'low_variation',
ZOOM_OUT_2X = 'zoom_out_2x',
ZOOM_OUT_1_5X = 'zoom_out_1_5x',
SQUARE = 'square',
PAN_LEFT = 'pan_left',
PAN_UP = 'pan_up',
PAN_DOWN = 'pan_down',
PAN_RIGHT = 'pan_right',
REROLL = 'reroll'
}
export enum MidjourneyImagineState {
@@ -26,8 +43,8 @@ export enum MidjourneyImagineState {
}
export interface IMidjourneyImagineRequest {
action: MidjourneyImagineAction;
prompt: string;
action?: MidjourneyImagineAction;
prompt?: string;
image_id?: string;
}
@@ -37,11 +54,20 @@ export interface IMidjourneyImagineResponse {
image_id: string;
image_url: string;
actions: MidjourneyImagineAction[];
code?: string;
detail?: string;
success?: boolean;
}
export interface IMidjourneyImagineTask {
request?: IMidjourneyImagineRequest;
response?: IMidjourneyImagineResponse;
state?: MidjourneyImagineState;
}
export interface IMidjourneyImagineOptions {
stream?: (response: IMidjourneyImagineResponse) => void;
token: string;
endpoint: string;
path: string;
token?: string;
endpoint?: string;
path?: string;
}
+25 -2
View File
@@ -1,10 +1,33 @@
import axios, { AxiosResponse } from 'axios';
import { IMidjourneyImagineOptions, IMidjourneyImagineRequest, IMidjourneyImagineResponse } from './models';
import { IMidjourneyImagineRequest, IMidjourneyImagineResponse, IMidjourneyImagineTask } from './models';
import { ENDPOINT_API } from '../common/contants';
class MidjourneyOperator {
async task(id: string): Promise<AxiosResponse<IMidjourneyImagineTask>> {
return await axios.post(
`/midjourney/tasks`,
{
action: 'retrieve',
id: id
},
{
headers: {
accept: 'application/json',
'content-type': 'application/json'
},
baseURL: ENDPOINT_API
}
);
}
async imagine(
data: IMidjourneyImagineRequest,
options: IMidjourneyImagineOptions
options: {
stream: (response: IMidjourneyImagineResponse) => void;
token: string;
endpoint: string;
path: string;
}
): Promise<AxiosResponse<IMidjourneyImagineResponse>> {
return await axios.post(options.path, data, {
headers: {
View File
Whitespace-only changes.
+2
View File
@@ -0,0 +1,2 @@
export * from './operator';
export * from './models';
+19
View File
@@ -0,0 +1,19 @@
import { IApi } from '../api';
export interface IApiUsage {
id?: string;
api?: IApi;
api_id?: string;
application_id?: string;
trace_id?: string;
metadata?: any;
created_at?: string;
updated_at?: string;
}
export interface IApiUsageListResponse {
count: number;
items: IApiUsage[];
}
export type IApiUsageDetailResponse = IApiUsage;
+27
View File
@@ -0,0 +1,27 @@
import { AxiosResponse } from 'axios';
import { httpClient } from '../instance';
import { IApiUsageDetailResponse, IApiUsageListResponse } from './models';
export interface IApiUsageQuery {
user_id?: string;
offset?: number;
limit?: number;
application_id?: string;
ordering?: string;
}
class ApiUsageOperator {
key = 'usage/apis';
async getAll(query: IApiUsageQuery): Promise<AxiosResponse<IApiUsageListResponse>> {
return await httpClient.get(`/${this.key}/`, {
params: query
});
}
async get(id: string): Promise<AxiosResponse<IApiUsageDetailResponse>> {
return await httpClient.get(`/${this.key}/${id}`);
}
}
export const apiUsageOperator = new ApiUsageOperator();
+69 -35
View File
@@ -1,15 +1,18 @@
<template>
<div class="page">
<div class="presets">
<channel-selector v-model="channel" />
<preset-panel v-model="preset" />
</div>
<div class="main">
<channel-selector v-model="channel" class="mb-4" @select="onSelectChannel" />
<api-status :application="application" class="mb-4" />
<prompt-input v-model="prompt" class="mb-4" />
<elements-selector v-model="elements" class="mb-4" />
<ignore-selector v-model="ignore" class="mb-4" />
<el-button type="primary" @click="onGenerate"> 生成 </el-button>
<imagine-preview v-model="response" :state="state" />
</div>
<div class="tasks">
<task-brief-list v-model:active-task="task" :application="application" @custom="onCustom" />
</div>
</div>
</template>
@@ -22,7 +25,6 @@ import ElementsSelector from '@/components/midjourney/ElementsSelector.vue';
import IgnoreSelector from '@/components/midjourney/IgnoreSelector.vue';
import { ElButton, ElImage } from 'element-plus';
import ChannelSelector from '@/components/midjourney/ChannelSelector.vue';
import ImaginePreview from '@/components/midjourney/ImaginePreview.vue';
import {
IApplication,
IMidjourneyChannel,
@@ -32,8 +34,12 @@ import {
MIDJOURNEY_CHANNEL_FAST,
applicationOperator,
midjourneyOperator,
MidjourneyImagineState
MidjourneyImagineState,
IMidjourneyImagineTask,
IMidjourneyImagineRequest
} from '@/operators';
import ApiStatus from '@/components/common/ApiStatus.vue';
import TaskBriefList from '@/components/midjourney/TaskBriefList.vue';
interface IData {
channel: IMidjourneyChannel;
@@ -44,8 +50,7 @@ interface IData {
initializing: boolean;
applied: boolean | undefined;
application: IApplication | undefined;
response: IMidjourneyImagineResponse | undefined;
state: MidjourneyImagineState | undefined;
task: IMidjourneyImagineTask | undefined;
}
export default defineComponent({
@@ -57,7 +62,8 @@ export default defineComponent({
ElementsSelector,
IgnoreSelector,
ElButton,
ImaginePreview
ApiStatus,
TaskBriefList
},
data(): IData {
return {
@@ -69,15 +75,17 @@ export default defineComponent({
ignore: '',
initializing: false,
applied: undefined,
response: undefined,
state: undefined
task: undefined
};
},
mounted() {
this.onFetchChannel();
this.onFetchApplication();
},
methods: {
async onFetchChannel() {
async onSelectChannel() {
await this.onFetchApplication();
},
async onFetchApplication() {
this.initializing = true;
const { data: applications } = await applicationOperator.getAll({
user_id: this.$store.state.user.id,
@@ -90,39 +98,60 @@ export default defineComponent({
}
this.application = applications.items[0];
},
async onGenerate() {
this.state = MidjourneyImagineState.PENDING;
async onStartTask(request: IMidjourneyImagineRequest) {
const token = this.application?.credential?.token;
const endpoint = this.application?.api?.endpoint;
const path = this.application?.api?.path;
if (!token || !endpoint || !this.prompt || !path) {
if (!token || !endpoint || !path) {
console.error('no token or endpoint or question');
return;
}
this.task = {
...this.task,
request,
state: MidjourneyImagineState.PENDING
};
midjourneyOperator
.imagine(
{
prompt: this.prompt,
action: MidjourneyImagineAction.GENERATE
},
{
token,
endpoint,
path,
stream: (response: IMidjourneyImagineResponse) => {
console.log(response);
this.state = MidjourneyImagineState.GENERATING;
this.response = response;
}
.imagine(request, {
token,
endpoint,
path,
stream: (response: IMidjourneyImagineResponse) => {
console.log(response);
this.task = {
...this.task,
state: MidjourneyImagineState.GENERATING,
response
};
}
)
.then((res) => {
this.state = MidjourneyImagineState.FINISHED;
console.log(res);
})
.catch(() => {
this.state = MidjourneyImagineState.FAILED;
.then(() => {
this.task = {
...this.task,
state: MidjourneyImagineState.FINISHED
};
})
.catch((error) => {
this.task = {
...this.task,
state: MidjourneyImagineState.FAILED,
response: error?.response as IMidjourneyImagineResponse
};
});
},
async onCustom(payload: { image_id: string; action: MidjourneyImagineAction }) {
const request = {
image_id: payload.image_id,
action: payload.action
};
this.onStartTask(request);
},
async onGenerate() {
const request = {
prompt: this.prompt,
action: MidjourneyImagineAction.GENERATE
};
this.onStartTask(request);
}
}
});
@@ -137,7 +166,7 @@ export default defineComponent({
.presets {
width: 260px;
height: 100%;
background-color: var(--el-bg-color-page);
// background-color: var(--el-bg-color-page);
}
.main {
flex: 1;
@@ -147,5 +176,10 @@ export default defineComponent({
margin-bottom: 10px;
}
}
.tasks {
width: 400px;
height: 100%;
// background-color: var(--el-bg-color-page);
}
}
</style>
+4
View File
@@ -13,11 +13,13 @@ import {
faPalette as faSolidPalette,
faBars as faSolidBars,
faGear as faSolidGear,
faMugSaucer as faSolidMugSaucer,
faRotateRight as faSolidRotateRight,
faCheck as faSolidCheck,
faPlus as faSolidPlus,
faBolt as faSolidBolt,
faQuestion as faSolidQuestion,
faWind as faSolidWind,
faTrash as faSolidTrash,
faChevronDown as faSolidChevronDown,
faArrowsRotate as faSolidArrowsRotate,
@@ -45,9 +47,11 @@ library.add(faSolidTriangleExclamation);
library.add(faSolidUpRightFromSquare);
library.add(faSolidArrowsRotate);
library.add(faRegularPaperPlane);
library.add(faSolidWind);
library.add(faRegularComment);
library.add(faSolidArrowRightFromBracket);
library.add(faSolidTrash);
library.add(faSolidChevronDown);
library.add(faSolidPalette);
library.add(faSolidWandMagicSparkles);
library.add(faSolidMugSaucer);