feat: improve media playground inputs and outputs
This commit is contained in:
1 parent
88c55cc6a9
commit
9a946b29e6
7 files changed
+225
-39
No files matched your search
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { Box, Download, ExternalLink } from 'lucide-vue-next'
|
||||
import { safeMediaUrl, type MediaResult } from '../services/media'
|
||||
const props = defineProps<{ media: MediaResult; pending?: boolean }>()
|
||||
const image = computed(() => safeMediaUrl(props.media.imageUrl) || safeMediaUrl(props.media.previewUrl))
|
||||
const video = computed(() => safeMediaUrl(props.media.videoUrl))
|
||||
const audio = computed(() => safeMediaUrl(props.media.audioUrl))
|
||||
const model = computed(() => safeMediaUrl(props.media.modelUrl))
|
||||
const result = computed(() => safeMediaUrl(props.media.resultUrl))
|
||||
const hasResult = computed(() => image.value || video.value || audio.value || model.value || result.value)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="media-result">
|
||||
<div v-if="video || image || model || pending" class="media-preview">
|
||||
<video v-if="video" :src="video" :poster="image" controls preload="metadata">浏览器不支持视频播放,请打开结果文件。</video>
|
||||
<img v-else-if="image" :src="image" alt="模型生成结果预览" loading="lazy" />
|
||||
<div v-else class="media-placeholder"><Box :size="34" /><span>{{ pending ? '结果生成后将在这里展示' : '3D 模型文件已生成' }}</span></div>
|
||||
</div>
|
||||
<audio v-if="audio" :src="audio" controls preload="metadata">浏览器不支持音频播放,请打开结果文件。</audio>
|
||||
<div v-if="hasResult" class="media-actions">
|
||||
<a v-if="model" :href="model" target="_blank" rel="noopener noreferrer"><Download :size="15" />下载 {{ media.resultFormat?.toUpperCase() || '3D' }} 模型</a>
|
||||
<a v-if="image" :href="image" target="_blank" rel="noopener noreferrer"><ExternalLink :size="15" />查看图片</a>
|
||||
<a v-if="video" :href="video" target="_blank" rel="noopener noreferrer"><Download :size="15" />打开视频文件</a>
|
||||
<a v-if="audio" :href="audio" target="_blank" rel="noopener noreferrer"><Download :size="15" />打开音频文件</a>
|
||||
<a v-if="result && !model && !video && !audio && result !== image" :href="result" target="_blank" rel="noopener noreferrer"><Download :size="15" />打开结果文件</a>
|
||||
</div>
|
||||
<p v-if="model" class="media-hint">3D 文件可在兼容软件中旋转查看和编辑;上方展示上游返回的预览图。</p>
|
||||
<p v-if="hasResult" class="media-hint">结果链接可能有有效期,请及时保存。</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.media-result{display:grid;gap:12px;width:100%;min-width:0}.media-preview{display:grid;place-items:center;min-height:180px;overflow:hidden;border:1px solid var(--border);border-radius:10px;background:var(--soft)}.media-preview img,.media-preview video{display:block;width:100%;max-height:420px;object-fit:contain}.media-placeholder{display:grid;justify-items:center;gap:12px;padding:28px;color:var(--muted);font-size:12px}.media-result audio{width:100%;max-width:100%}.media-actions{display:flex;flex-wrap:wrap;gap:10px}.media-actions a{display:inline-flex;align-items:center;gap:6px;padding:9px 12px;border:1px solid var(--border);border-radius:8px;font-size:12px;color:var(--primary);text-decoration:none;background:#fff}.media-actions a:hover{background:var(--primary-soft)}.media-hint{margin:0;color:var(--muted);font-size:11px;line-height:1.6}
|
||||
</style>
|
||||
@@ -1,5 +1,6 @@
|
||||
export type CatalogModelType = 'text' | 'code' | 'multimodal' | 'image' | 'audio' | 'video' | 'embedding' | '3d'
|
||||
export type CatalogCallMode = 'sync' | 'stream' | 'async'
|
||||
export type AsyncMediaType = '3d' | 'video' | 'image' | 'audio'
|
||||
|
||||
export interface CatalogProvider {
|
||||
id: string
|
||||
@@ -230,12 +231,21 @@ export interface AsyncTaskResult {
|
||||
updated_at?: string
|
||||
createdAt?: string
|
||||
completedAt?: string
|
||||
result?: { format?: string; url?: string; modelUrl?: string; previewUrl?: string; videoUrl?: string; creditsConsumed?: number; [key: string]: unknown }
|
||||
output?: { modelUrl?: string; previewUrl?: string; videoUrl?: string }
|
||||
result?: { format?: string; url?: string; modelUrl?: string; previewUrl?: string; videoUrl?: string; imageUrl?: string; audioUrl?: string; mimeType?: string; creditsConsumed?: number; [key: string]: unknown }
|
||||
output?: { modelUrl?: string; previewUrl?: string; videoUrl?: string; imageUrl?: string; audioUrl?: string; url?: string; format?: string; mimeType?: string }
|
||||
creditsConsumed?: number
|
||||
error?: { code?: number; message?: string }
|
||||
}
|
||||
|
||||
/** OpenAI-compatible multimodal content. Keep text-only calls byte-for-byte compatible. */
|
||||
function userMessage(prompt: string, mediaUrl?: string): string | Array<Record<string, unknown>> {
|
||||
if (!mediaUrl) return prompt
|
||||
return [
|
||||
{ type: 'text', text: prompt },
|
||||
{ type: 'image_url', image_url: { url: mediaUrl } },
|
||||
]
|
||||
}
|
||||
|
||||
export class CatalogApiError extends Error {
|
||||
constructor(readonly status: number, message: string, readonly code?: string) {
|
||||
super(message)
|
||||
@@ -327,27 +337,27 @@ class HttpCatalogClient {
|
||||
return response.blob()
|
||||
}
|
||||
|
||||
async chatCompletion(apiKey: string, input: { model: string; prompt: string; maxTokens?: number }) {
|
||||
async chatCompletion(apiKey: string, input: { model: string; prompt: string; maxTokens?: number; mediaUrl?: string }) {
|
||||
return this.request<ChatCompletionResult>('/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${apiKey}`, 'X-Moyi-Source': 'playground', 'Idempotency-Key': crypto.randomUUID() },
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }], max_tokens: input.maxTokens || 4096 }),
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: userMessage(input.prompt, input.mediaUrl) }], max_tokens: input.maxTokens || 4096 }),
|
||||
})
|
||||
}
|
||||
|
||||
async playgroundChatCompletion(keyId: string, input: { model: string; prompt: string; maxTokens?: number }) {
|
||||
async playgroundChatCompletion(keyId: string, input: { model: string; prompt: string; maxTokens?: number; mediaUrl?: string }) {
|
||||
return this.request<ChatCompletionResult>(`/api/playground/keys/${encodeURIComponent(keyId)}/chat/completions`, {
|
||||
method: 'POST',
|
||||
headers: { 'X-Moyi-Source': 'playground', 'Idempotency-Key': crypto.randomUUID() },
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }], max_tokens: input.maxTokens || 4096 }),
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: userMessage(input.prompt, input.mediaUrl) }], max_tokens: input.maxTokens || 4096 }),
|
||||
})
|
||||
}
|
||||
|
||||
async streamChat(apiKey: string, input: { model: string; prompt: string; maxTokens: number }, onDelta: (content: string, reasoning: string) => void, signal: AbortSignal) {
|
||||
async streamChat(apiKey: string, input: { model: string; prompt: string; maxTokens: number; mediaUrl?: string }, onDelta: (content: string, reasoning: string) => void, signal: AbortSignal) {
|
||||
const response = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
||||
method: 'POST', credentials: 'include', signal,
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}`, 'X-Moyi-Source': 'playground', 'Idempotency-Key': crypto.randomUUID() },
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }], stream: true, max_tokens: input.maxTokens }),
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: userMessage(input.prompt, input.mediaUrl) }], stream: true, max_tokens: input.maxTokens }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({}))
|
||||
@@ -358,11 +368,11 @@ class HttpCatalogClient {
|
||||
await readChatStream(response.body, onDelta)
|
||||
}
|
||||
|
||||
async playgroundStreamChat(keyId: string, input: { model: string; prompt: string; maxTokens: number }, onDelta: (content: string, reasoning: string) => void, signal: AbortSignal) {
|
||||
async playgroundStreamChat(keyId: string, input: { model: string; prompt: string; maxTokens: number; mediaUrl?: string }, onDelta: (content: string, reasoning: string) => void, signal: AbortSignal) {
|
||||
const response = await fetch(`${this.baseUrl}/api/playground/keys/${encodeURIComponent(keyId)}/chat/completions`, {
|
||||
method: 'POST', credentials: 'include', signal,
|
||||
headers: { 'Content-Type': 'application/json', 'X-Moyi-Source': 'playground', 'Idempotency-Key': crypto.randomUUID() },
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }], stream: true, max_tokens: input.maxTokens }),
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: userMessage(input.prompt, input.mediaUrl) }], stream: true, max_tokens: input.maxTokens }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({}))
|
||||
@@ -373,18 +383,18 @@ class HttpCatalogClient {
|
||||
await readChatStream(response.body, onDelta)
|
||||
}
|
||||
|
||||
async createMediaTask(apiKey: string, input: { model: string; prompt: string; mediaType: '3d' | 'video' }) {
|
||||
const payload = await this.request<{ task: AsyncTaskResult }>(input.mediaType === 'video' ? '/v1/video/tasks' : '/v1/3d/tasks', {
|
||||
async createMediaTask(apiKey: string, input: { model: string; prompt: string; mediaType: AsyncMediaType; mediaUrl?: string }) {
|
||||
const payload = await this.request<{ task: AsyncTaskResult }>(`/v1/${input.mediaType}/tasks`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${apiKey}`, 'X-Moyi-Source': 'playground' },
|
||||
body: JSON.stringify({ model: input.model, prompt: input.prompt }),
|
||||
body: JSON.stringify({ model: input.model, prompt: input.prompt, ...(input.mediaUrl ? { media_url: input.mediaUrl } : {}) }),
|
||||
})
|
||||
return payload.task
|
||||
}
|
||||
|
||||
async playgroundCreateMediaTask(keyId: string, input: { model: string; prompt: string; mediaType: '3d' | 'video' }) {
|
||||
const payload = await this.request<{ task: AsyncTaskResult }>(`/api/playground/keys/${encodeURIComponent(keyId)}/${input.mediaType === 'video' ? 'video' : '3d'}/tasks`, {
|
||||
method: 'POST', headers: { 'X-Moyi-Source': 'playground' }, body: JSON.stringify({ model: input.model, prompt: input.prompt }),
|
||||
async playgroundCreateMediaTask(keyId: string, input: { model: string; prompt: string; mediaType: AsyncMediaType; mediaUrl?: string }) {
|
||||
const payload = await this.request<{ task: AsyncTaskResult }>(`/api/playground/keys/${encodeURIComponent(keyId)}/${input.mediaType}/tasks`, {
|
||||
method: 'POST', headers: { 'X-Moyi-Source': 'playground' }, body: JSON.stringify({ model: input.model, prompt: input.prompt, ...(input.mediaUrl ? { media_url: input.mediaUrl } : {}) }),
|
||||
})
|
||||
return payload.task
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
export interface MediaResult {
|
||||
imageUrl?: string
|
||||
videoUrl?: string
|
||||
audioUrl?: string
|
||||
modelUrl?: string
|
||||
previewUrl?: string
|
||||
resultUrl?: string
|
||||
resultFormat?: string
|
||||
}
|
||||
|
||||
export function safeMediaUrl(value: unknown): string | undefined {
|
||||
if (typeof value !== 'string' || !value.trim()) return undefined
|
||||
try {
|
||||
const url = new URL(value)
|
||||
return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : undefined
|
||||
} catch { return undefined }
|
||||
}
|
||||
|
||||
/** Normalize generation assets without treating every provider's generic URL as a 3D model. */
|
||||
export function mediaResult(result: Record<string, unknown> = {}, type = ''): MediaResult {
|
||||
const format = typeof result.format === 'string' ? result.format.toLowerCase() : ''
|
||||
const url = safeMediaUrl(result.url)
|
||||
const mime = typeof result.mimeType === 'string' ? result.mimeType.toLowerCase() : ''
|
||||
const suffix = url ? new URL(url).pathname.toLowerCase().split('.').pop() : ''
|
||||
const isImage = type === '图像' || type === 'image' || mime.startsWith('image/') || /^(png|jpe?g|webp|gif|avif)$/.test(format || suffix || '')
|
||||
const isVideo = type === '视频' || type === 'video' || mime.startsWith('video/') || /^(mp4|webm|mov)$/.test(format || suffix || '')
|
||||
const isAudio = type === '音频' || type === 'audio' || mime.startsWith('audio/') || /^(mp3|wav|ogg|m4a|flac|aac)$/.test(format || suffix || '')
|
||||
const isModel = type === '3D' || type === '3d' || /^(glb|gltf|obj|fbx|stl)$/.test(format || suffix || '')
|
||||
return {
|
||||
imageUrl: safeMediaUrl(result.imageUrl) || (isImage ? url : undefined),
|
||||
videoUrl: safeMediaUrl(result.videoUrl) || (isVideo ? url : undefined),
|
||||
audioUrl: safeMediaUrl(result.audioUrl) || (isAudio ? url : undefined),
|
||||
modelUrl: safeMediaUrl(result.modelUrl) || (isModel ? url : undefined),
|
||||
previewUrl: safeMediaUrl(result.previewUrl),
|
||||
resultUrl: url,
|
||||
resultFormat: format || suffix,
|
||||
}
|
||||
}
|
||||
|
||||
export function mediaTypeLabel(type: string): string {
|
||||
return ({ text: '文本', image: '图片', image_url: '图片', video: '视频', audio: '音频', '3d': '3D', glb: 'GLB 模型', multimodal: '多模态' })[type.toLowerCase()] || type
|
||||
}
|
||||
|
||||
export function generationLabel(type: string): string {
|
||||
return ({ 视频: '生成视频', 图像: '生成图片', 音频: '生成音频', '3D': '生成 3D' })[type] || '提交任务'
|
||||
}
|
||||
@@ -29,6 +29,9 @@ export interface ModelItem {
|
||||
description: string
|
||||
latency: string
|
||||
specification: string
|
||||
/** Declared media accepted and returned by this model route. */
|
||||
inputTypes?: string[]
|
||||
outputTypes?: string[]
|
||||
availability: string
|
||||
accent: string
|
||||
icon: Component
|
||||
@@ -82,6 +85,10 @@ export interface TaskItem {
|
||||
modelUrl?: string
|
||||
videoUrl?: string
|
||||
previewUrl?: string
|
||||
imageUrl?: string
|
||||
audioUrl?: string
|
||||
resultUrl?: string
|
||||
resultFormat?: string
|
||||
creditsConsumed?: number
|
||||
remote?: boolean
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import {
|
||||
Zap,
|
||||
} from 'lucide-vue-next'
|
||||
import type { ApiKeyItem, CallMode, ModelItem, ModelType, TaskItem, TaskStatus } from '../types'
|
||||
import { catalogClient, platformApiBaseUrl, type AsyncTaskResult, type CatalogApiKey, type CatalogModel, type LogicalModel, type CatalogProject, type PlatformOverview, type UserUsageRecord } from '../services/catalog'
|
||||
import { catalogClient, platformApiBaseUrl, type AsyncMediaType, type AsyncTaskResult, type CatalogApiKey, type CatalogModel, type LogicalModel, type CatalogProject, type PlatformOverview, type UserUsageRecord } from '../services/catalog'
|
||||
import { buildModelCatalog } from '../services/model-catalog'
|
||||
import { groupDiscountLabel as formatGroupDiscountLabel, modelStandardPriceLabel, platformPriceLabel } from '../services/pricing'
|
||||
import { usePagination } from '../composables/usePagination'
|
||||
@@ -47,6 +47,8 @@ import SlidePanel from '../components/SlidePanel.vue'
|
||||
import UiModal from '../components/UiModal.vue'
|
||||
import ModelGroupPermissions from '../components/ModelGroupPermissions.vue'
|
||||
import UsageHistory from '../components/UsageHistory.vue'
|
||||
import MediaResult from '../components/MediaResult.vue'
|
||||
import { generationLabel, mediaResult, mediaTypeLabel, safeMediaUrl } from '../services/media'
|
||||
|
||||
defineProps<{ view: string; displayName?: string }>()
|
||||
const emit = defineEmits<{ navigate: [view: string]; notify: [message: string]; balance: [value: number | undefined] }>()
|
||||
@@ -76,19 +78,21 @@ const playgroundModels = computed(() => [...new Map(catalogModels.value.map(grou
|
||||
const playgroundGroups = computed(() => catalogModels.value.filter(group => (group.logicalModelId || group.id) === (activeModel.value.logicalModelId || activeModel.value.id)))
|
||||
function selectPlaygroundGroup(id: string) {
|
||||
const group = catalogModels.value.find(item => item.id === id)
|
||||
if (group) { activeModel.value = group; callMode.value = group.mode; response.value = ''; reasoningOutput.value = ''; finishReason.value = ''; activeTaskId.value = '' }
|
||||
if (group) { activeModel.value = group; callMode.value = group.mode; response.value = ''; responseMedia.value = {}; responseError.value = ''; mediaUrl.value = ''; reasoningOutput.value = ''; finishReason.value = ''; activeTaskId.value = '' }
|
||||
}
|
||||
function selectPlaygroundModel(id: string) {
|
||||
const group = catalogModels.value.find(item => (item.logicalModelId || item.id) === id)
|
||||
if (group) selectPlaygroundGroup(group.id)
|
||||
}
|
||||
const prompt = ref('')
|
||||
const mediaUrl = ref('')
|
||||
const running = ref(false)
|
||||
const maxOutputTokens = ref(4096)
|
||||
const reasoningOutput = ref('')
|
||||
const finishReason = ref('')
|
||||
let streamAbort: AbortController | undefined
|
||||
const response = ref('')
|
||||
const responseMedia = ref<ReturnType<typeof mediaResult>>({})
|
||||
const responseError = ref('')
|
||||
const keys = ref<ApiKeyItem[]>([])
|
||||
const { page: keyPage, pageSize: keyPageSize, pagedItems: pagedKeys } = usePagination(keys)
|
||||
@@ -129,6 +133,27 @@ const selectedApiKeyId = ref('')
|
||||
const activeDebugKeys = computed(() => keys.value.filter((key) => key.status === '正常'))
|
||||
const selectedDebugKey = computed(() => activeDebugKeys.value.find((key) => String(key.id) === selectedApiKeyId.value))
|
||||
const debugKeyCanInvoke = computed(() => !!selectedDebugKey.value?.modelIds.includes(activeModel.value.id))
|
||||
const activeMediaKind = computed<AsyncMediaType | undefined>(() => {
|
||||
if (activeModel.value.type === '3D') return '3d'
|
||||
if (activeModel.value.type === '视频') return 'video'
|
||||
if (activeModel.value.type === '图像') return 'image'
|
||||
if (activeModel.value.type === '音频') return 'audio'
|
||||
return undefined
|
||||
})
|
||||
const activeInputTypes = computed(() => activeModel.value.inputTypes || [])
|
||||
const activeOutputTypes = computed(() => activeModel.value.outputTypes || [])
|
||||
const activeAsyncSupported = computed(() => activeModel.value.mode !== '异步' || (!!activeMediaKind.value && activeModel.value.executionReady !== false))
|
||||
const supportsMediaInput = computed(() => activeInputTypes.value.some(input => /image|audio|video|url|media/i.test(input)))
|
||||
const activeModelReady = computed(() => activeModel.value.pricingConfigured === true && activeModel.value.billingReady !== false && activeModel.value.executionReady !== false && activeAsyncSupported.value)
|
||||
const submitLabel = computed(() => callMode.value === '异步' ? generationLabel(activeModel.value.type) : '开始调用')
|
||||
const promptPlaceholder = computed(() => ({
|
||||
'文本': '描述你希望模型完成的任务',
|
||||
'多模态': '描述你希望模型完成的任务,也可以附加媒体地址',
|
||||
'视频': '例如:电影感产品展示视频,柔和运镜与自然光影',
|
||||
'图像': '例如:一只坐在窗边的橘猫,温暖日光,水彩插画',
|
||||
'音频': '请输入希望生成的语音文字或描述音频内容',
|
||||
'3D': '例如:一个低面数的木质机械鸟,游戏资产风格',
|
||||
} as Record<ModelType, string>)[activeModel.value.type] || '描述你希望模型完成的任务')
|
||||
const catalogConnected = ref(false)
|
||||
const overviewLoaded = ref(false)
|
||||
const overview = ref<PlatformOverview>({ generatedAt: '', callsToday: 0, callsThisMonth: 0, asyncTasks: 0, tasks: { queued: 0, running: 0, succeeded: 0, failed: 0 }, series: [], ledger: [] })
|
||||
@@ -293,6 +318,7 @@ function tryModel(model: GalleryModel) {
|
||||
callMode.value = group.mode
|
||||
selectedModel.value = null
|
||||
response.value = ''
|
||||
responseMedia.value = {}
|
||||
reasoningOutput.value = ''
|
||||
finishReason.value = ''
|
||||
emit('navigate', 'playground')
|
||||
@@ -300,7 +326,7 @@ function tryModel(model: GalleryModel) {
|
||||
|
||||
async function runModel() {
|
||||
if (!activeModel.value.id) return emit('notify', '当前没有可调用的模型,请先检查模型目录')
|
||||
if (!prompt.value.trim()) return emit('notify', '请先输入调用内容')
|
||||
if (!prompt.value.trim() && !mediaUrl.value.trim()) return emit('notify', '请先输入调用内容或媒体 URL')
|
||||
if (running.value) return
|
||||
if (callMode.value !== '异步' && (!Number.isInteger(maxOutputTokens.value) || maxOutputTokens.value < 1 || maxOutputTokens.value > 32768)) return emit('notify', '最大输出 Token 须为 1–32768 的整数')
|
||||
if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法提交真实调用')
|
||||
@@ -310,15 +336,19 @@ async function runModel() {
|
||||
return
|
||||
}
|
||||
if (!debugKeyCanInvoke.value) return emit('notify', '该 Key 尚未授权当前模型分组,请切换 Key 或修改模型权限')
|
||||
if (callMode.value === '异步' && !activeAsyncSupported.value) return emit('notify', '当前媒体类型尚未配置异步执行器,暂时不能调用')
|
||||
if (!activeModelReady.value) return emit('notify', '该分组尚未完成执行或计费配置,暂时不能调用')
|
||||
if (mediaUrl.value.trim() && !safeMediaUrl(mediaUrl.value.trim())) return emit('notify', '请输入有效的 http 或 https 图片地址')
|
||||
running.value = true
|
||||
response.value = ''
|
||||
responseMedia.value = {}
|
||||
responseError.value = ''
|
||||
reasoningOutput.value = ''
|
||||
finishReason.value = ''
|
||||
const selectedMode = callMode.value
|
||||
try {
|
||||
if (callMode.value === '异步') {
|
||||
const task = await catalogClient.playgroundCreateMediaTask(apiKey, { model: activeModel.value.id, prompt: prompt.value, mediaType: activeModel.value.type === '视频' ? 'video' : '3d' })
|
||||
const task = await catalogClient.playgroundCreateMediaTask(apiKey, { model: activeModel.value.id, prompt: prompt.value, mediaUrl: mediaUrl.value.trim() || undefined, mediaType: activeMediaKind.value! })
|
||||
const taskItem = mapAsyncTask(task, activeModel.value, prompt.value)
|
||||
tasks.value.unshift(taskItem)
|
||||
activeTaskId.value = task.id
|
||||
@@ -326,15 +356,16 @@ async function runModel() {
|
||||
scheduleTaskPoll(task.id, apiKey)
|
||||
} else if (selectedMode === '流式') {
|
||||
streamAbort = new AbortController()
|
||||
await catalogClient.playgroundStreamChat(apiKey, { model: activeModel.value.id, prompt: prompt.value, maxTokens: maxOutputTokens.value }, (text, reasoning) => { response.value += text; reasoningOutput.value += reasoning }, streamAbort.signal)
|
||||
await catalogClient.playgroundStreamChat(apiKey, { model: activeModel.value.id, prompt: prompt.value, mediaUrl: mediaUrl.value.trim() || undefined, maxTokens: maxOutputTokens.value }, (text, reasoning) => { response.value += text; reasoningOutput.value += reasoning }, streamAbort.signal)
|
||||
} else {
|
||||
const result = await catalogClient.playgroundChatCompletion(apiKey, { model: activeModel.value.id, prompt: prompt.value, maxTokens: maxOutputTokens.value })
|
||||
const result = await catalogClient.playgroundChatCompletion(apiKey, { model: activeModel.value.id, prompt: prompt.value, mediaUrl: mediaUrl.value.trim() || undefined, maxTokens: maxOutputTokens.value })
|
||||
const choice = result.choices[0]
|
||||
const message = choice?.message
|
||||
const reasoning = typeof message?.reasoning_content === 'string' ? message.reasoning_content : typeof message?.reasoning === 'string' ? message.reasoning : ''
|
||||
reasoningOutput.value = reasoning
|
||||
finishReason.value = typeof choice?.finish_reason === 'string' ? choice.finish_reason : ''
|
||||
const content = normalizeAssistantContent(message?.content)
|
||||
responseMedia.value = normalizeAssistantMedia(message?.content)
|
||||
// Keep reasoning separate from the final answer. A small output budget
|
||||
// can legitimately end after reasoning; leave that choice to the user.
|
||||
response.value = content || (reasoning ? '模型仅返回了思考过程,未返回最终答案;可调整最大输出 Token 后重试。' : '模型未返回内容')
|
||||
@@ -361,10 +392,29 @@ function normalizeAssistantContent(value: unknown): string {
|
||||
}).join('')
|
||||
}
|
||||
|
||||
function normalizeAssistantMedia(value: unknown) {
|
||||
if (!Array.isArray(value)) return {}
|
||||
const media: Record<string, unknown> = {}
|
||||
const urlFrom = (entry: unknown) => typeof entry === 'string' ? entry : entry && typeof entry === 'object' && typeof (entry as { url?: unknown }).url === 'string' ? (entry as { url: string }).url : undefined
|
||||
for (const part of value) {
|
||||
if (!part || typeof part !== 'object') continue
|
||||
const item = part as { type?: unknown; image_url?: unknown; video_url?: unknown; audio_url?: unknown; url?: unknown }
|
||||
const url = urlFrom(item.url)
|
||||
if (item.type === 'image_url') media.imageUrl = urlFrom(item.image_url) || url
|
||||
if (item.type === 'video_url' || item.type === 'video') media.videoUrl = urlFrom(item.video_url) || url
|
||||
if (item.type === 'audio_url' || item.type === 'audio') media.audioUrl = urlFrom(item.audio_url) || url
|
||||
}
|
||||
return mediaResult(media, activeModel.value.type)
|
||||
}
|
||||
|
||||
function mapAsyncTask(task: AsyncTaskResult, model: ModelItem, taskPrompt?: string): TaskItem {
|
||||
const modelUrl = task.output?.modelUrl || task.result?.modelUrl || (task.provider ? task.result?.url : undefined)
|
||||
const modelUrl = task.output?.modelUrl || task.result?.modelUrl
|
||||
const videoUrl = task.output?.videoUrl || task.result?.videoUrl
|
||||
const previewUrl = task.output?.previewUrl || task.result?.previewUrl
|
||||
const assets = mediaResult({ ...task.result, ...task.output }, model.type)
|
||||
const imageUrl = assets.imageUrl
|
||||
const audioUrl = assets.audioUrl
|
||||
const resultUrl = assets.resultUrl
|
||||
const creditsConsumed = task.creditsConsumed ?? task.result?.creditsConsumed
|
||||
const statusMap: Record<AsyncTaskResult['status'], TaskStatus> = {
|
||||
queued: '排队中',
|
||||
@@ -376,18 +426,22 @@ function mapAsyncTask(task: AsyncTaskResult, model: ModelItem, taskPrompt?: stri
|
||||
const createdAt = task.createdAt || task.created_at
|
||||
return {
|
||||
id: task.id,
|
||||
name: model.type === '视频' || task.provider === 'seedance' ? '文字生成视频' : '文字生成 3D',
|
||||
name: model.type === '视频' || task.provider === 'seedance' ? '文字生成视频' : model.type === '图像' ? '生成图片' : model.type === '音频' ? '生成音频' : '生成 3D',
|
||||
model: model.name,
|
||||
status: statusMap[task.status],
|
||||
progress: task.status === 'succeeded' ? 100 : Math.round(task.progress || 0),
|
||||
createdAt: createdAt ? formatTaskTime(createdAt) : '刚刚',
|
||||
duration: task.completedAt ? '已完成' : '计算中',
|
||||
result: task.error?.message || (videoUrl ? '视频已生成' : modelUrl ? 'GLB 模型已生成' : task.status === 'succeeded' ? '异步任务已完成' : task.status === 'running' ? `正在生成 · ${Math.round(task.progress || 0)}%` : '等待平台调度'),
|
||||
result: task.error?.message || (videoUrl ? '视频已生成' : imageUrl ? '图片已生成' : audioUrl ? '音频已生成' : modelUrl ? 'GLB 模型已生成' : resultUrl ? '文件已生成' : task.status === 'succeeded' ? '异步任务已完成' : task.status === 'running' ? `正在生成 · ${Math.round(task.progress || 0)}%` : '等待平台调度'),
|
||||
provider: task.provider,
|
||||
prompt: taskPrompt,
|
||||
modelUrl,
|
||||
videoUrl,
|
||||
modelUrl: modelUrl || assets.modelUrl,
|
||||
videoUrl: videoUrl || assets.videoUrl,
|
||||
previewUrl,
|
||||
imageUrl,
|
||||
audioUrl,
|
||||
resultUrl,
|
||||
resultFormat: task.output?.format || task.result?.format,
|
||||
creditsConsumed,
|
||||
remote: true,
|
||||
}
|
||||
@@ -423,7 +477,8 @@ async function pollTask(taskId: string, apiKey: string) {
|
||||
// the balance card and usage counters reflect that settlement immediately
|
||||
// instead of waiting for a full page reload.
|
||||
await refreshOverview()
|
||||
emit('notify', latest.status === 'succeeded' ? '3D 模型生成完成,可以预览和下载' : '3D 任务未能完成')
|
||||
historyRevision.value++
|
||||
emit('notify', latest.status === 'succeeded' ? `${previous.name}完成,可以查看和保存结果` : `${previous.name}未能完成,请查看错误说明`)
|
||||
}
|
||||
} catch (error) {
|
||||
taskPollers.delete(taskId)
|
||||
@@ -464,7 +519,7 @@ function mapCatalogModels(items: CatalogModel[], providers: Array<{ id: string;
|
||||
...mapCatalogModel(item), logicalModelId: item.logicalModelId,
|
||||
provider: providerNames.get(item.providerId) || item.providerId,
|
||||
vendorName: item.vendorName,
|
||||
sourceLabel: item.sourceLabel, pricing: item.pricing, pricingConfigured: item.pricingConfigured, billingReady: item.billingReady, priority: item.priority, maxConcurrency: item.maxConcurrency, executionReady: item.executionReady,
|
||||
sourceLabel: item.sourceLabel, pricing: item.pricing, pricingConfigured: item.pricingConfigured, billingReady: item.billingReady, priority: item.priority, maxConcurrency: item.maxConcurrency, executionReady: item.executionReady, inputTypes: item.inputTypes, outputTypes: item.outputTypes,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -481,6 +536,8 @@ function mapCatalogModel(item: LogicalModel): ModelItem {
|
||||
description: item.description,
|
||||
latency: item.mode === 'async' ? '异步任务' : '待采样',
|
||||
specification: item.outputTypes.join(' / ') || '统一接口',
|
||||
inputTypes: item.inputTypes,
|
||||
outputTypes: item.outputTypes,
|
||||
availability: item.status === 'active' ? '在线' : '已停用',
|
||||
accent: item.type === '3d' ? 'orange' : 'violet',
|
||||
icon: item.type === '3d' ? Box : item.type === 'image' ? Sparkles : MessageSquareText,
|
||||
@@ -645,7 +702,7 @@ async function createProject() {
|
||||
</section>
|
||||
<section class="playground-grid">
|
||||
<article class="panel request-panel">
|
||||
<header class="panel-header"><div><span>REQUEST</span><h3>请求配置</h3></div><button class="icon-button" @click="prompt = ''; response = ''; reasoningOutput = ''; finishReason = ''; activeTaskId = ''"><RefreshCcw :size="16" /></button></header>
|
||||
<header class="panel-header"><div><span>REQUEST</span><h3>请求配置</h3></div><button class="icon-button" @click="prompt = ''; mediaUrl = ''; response = ''; responseMedia = {}; responseError = ''; reasoningOutput = ''; finishReason = ''; activeTaskId = ''"><RefreshCcw :size="16" /></button></header>
|
||||
<div class="playground-selectors">
|
||||
<label>模型<select class="text-input" aria-label="调试模型" :value="activeModel.logicalModelId || activeModel.id" :disabled="running || !playgroundModels.length" @change="selectPlaygroundModel(($event.target as HTMLSelectElement).value)"><option v-for="model in playgroundModels" :key="model.logicalModelId || model.id" :value="model.logicalModelId || model.id">{{ model.name }}</option></select></label>
|
||||
<label>分组<select class="text-input" aria-label="调试分组" :value="activeModel.id" :disabled="running || !playgroundGroups.length" @change="selectPlaygroundGroup(($event.target as HTMLSelectElement).value)"><option v-for="group in playgroundGroups" :key="group.id" :value="group.id">{{ group.sourceLabel || '默认分组' }} · {{ group.provider }}</option></select></label>
|
||||
@@ -654,24 +711,27 @@ async function createProject() {
|
||||
<div class="segment"><button v-for="mode in ['同步','流式','异步']" :key="mode" :disabled="running || (activeModel.mode === '异步' ? mode !== '异步' : mode === '异步')" :class="{ active: callMode === mode }" @click="callMode = mode as CallMode">{{ mode }}</button></div>
|
||||
<label v-if="callMode !== '异步'" class="form-label token-limit">最大输出 Token<input v-model.number="maxOutputTokens" class="text-input" type="number" min="1" max="32768" step="1" :disabled="running" /></label>
|
||||
<small v-if="callMode !== '异步'">按分组人民币售价和实际 Token 用量扣费;调用前预留额度,结束后释放差额。</small>
|
||||
<div v-if="activeInputTypes.length || activeOutputTypes.length" class="capability-strip"><span>输入</span><em v-for="input in activeInputTypes" :key="`input-${input}`">{{ mediaTypeLabel(input) }}</em><span>输出</span><em v-for="output in activeOutputTypes" :key="`output-${output}`">{{ mediaTypeLabel(output) }}</em></div>
|
||||
<p v-if="!activeModelReady && activeModel.id" class="request-unavailable" role="status">{{ activeModel.executionReady === false ? '该分组尚未接通相应的执行服务,暂时不能调用。' : !activeModel.pricingConfigured || activeModel.billingReady === false ? '该分组的计费尚未配置完成,暂时不能调用。' : '该模型的调用方式暂不支持在线调试。' }}</p>
|
||||
<label v-if="supportsMediaInput" class="form-label media-input-label"><span>媒体 URL(可选)</span><small>使用模型供应商可访问的 http 或 https 地址;图片会在这里预览</small><input v-model="mediaUrl" class="text-input" type="url" placeholder="https://…/media" :disabled="running" /><img v-if="safeMediaUrl(mediaUrl) && activeInputTypes.some(input => /image/i.test(input))" class="input-media-preview" :src="safeMediaUrl(mediaUrl)" alt="参考图片预览" /></label>
|
||||
<label class="form-label prompt-label"><span>输入内容</span><small>{{ prompt.length }}/4000</small></label>
|
||||
<textarea v-model="prompt" maxlength="4000" :placeholder="callMode === '异步' ? activeModel.type === '视频' ? '例如:电影感产品展示视频,柔和运镜与自然光影' : '例如:一个低面数的木质机械鸟,游戏资产风格' : '描述你希望模型完成的任务'"></textarea>
|
||||
<div class="request-footer"><span><ShieldCheck :size="14" />{{ catalogConnected ? '通过 MOYI Key 调用真实网关' : '连接服务后才能调用' }}</span><button class="button primary" :disabled="running || !catalogConnected || !activeModel.id" @click="runModel"><Play v-if="!running" :size="16" /><span v-else class="spinner"></span>{{ running ? '提交中…' : callMode === '异步' ? activeModel.type === '视频' ? '生成视频' : '生成 3D' : '开始调用' }}</button></div>
|
||||
<textarea v-model="prompt" maxlength="4000" :placeholder="promptPlaceholder" :disabled="running"></textarea>
|
||||
<div class="request-footer"><span><ShieldCheck :size="14" />{{ catalogConnected ? '通过所选 MOYI Key 调用' : '连接服务后才能调用' }}</span><button class="button primary" :disabled="running || !catalogConnected || !activeModel.id || !activeModelReady || !debugKeyCanInvoke" @click="runModel"><Play v-if="!running" :size="16" /><span v-else class="spinner"></span>{{ running ? '提交中…' : submitLabel }}</button></div>
|
||||
</article>
|
||||
<article class="panel response-panel">
|
||||
<header class="panel-header"><div><span>RESPONSE</span><h3>{{ callMode === '异步' ? '任务状态' : '模型输出' }}</h3></div><button class="icon-button" :class="{ copied: copySucceeded('response') }" :disabled="!response" :title="copySucceeded('response') ? '已复制' : '复制响应'" @click="copy(response, '响应内容', 'response')"><Check v-if="copySucceeded('response')" :size="16" /><Copy v-else :size="16" /></button></header>
|
||||
<button v-if="running && callMode === '流式'" class="button secondary" @click="streamAbort?.abort()">停止接收</button>
|
||||
<details v-if="reasoningOutput"><summary>思考过程</summary><pre class="response-content">{{ reasoningOutput }}</pre></details>
|
||||
<div v-if="running && !response" class="response-state"><span class="loading-orbit"><i></i></span><strong>{{ callMode === '异步' ? activeModel.type === '视频' ? '正在创建视频任务' : '正在创建 3D 任务' : '模型正在生成响应' }}</strong><p>请求通过模亦灵枢统一网关发送</p></div>
|
||||
<div v-if="running && !response" class="response-state"><span class="loading-orbit"><i></i></span><strong>{{ callMode === '异步' ? `正在提交${generationLabel(activeModel.type)}任务` : '模型正在生成响应' }}</strong><p>请求通过模亦灵枢统一网关发送</p></div>
|
||||
<div v-else-if="callMode === '异步' && activeTask" class="live-task-result">
|
||||
<div class="task-preview" :class="{ empty: !activeTask.previewUrl && !activeTask.videoUrl }"><video v-if="activeTask.videoUrl" :src="activeTask.videoUrl" controls></video><img v-else-if="activeTask.previewUrl" :src="activeTask.previewUrl" alt="异步任务预览" /><span v-else><Box :size="34" /><small>{{ activeTask.status === '已完成' ? '结果已生成' : '生成预览中' }}</small></span><em>{{ activeTask.provider === 'tripo' ? 'TRIPO' : activeTask.provider === 'seedance' ? 'SEEDANCE' : 'MOYI GATEWAY' }}</em></div>
|
||||
<MediaResult :media="activeTask" :pending="activeTask.status === '排队中' || activeTask.status === '执行中'" />
|
||||
<div class="live-task-head"><span class="status-chip" :class="activeTask.status"><i></i>{{ activeTask.status }}</span><code>{{ activeTask.id }}</code></div>
|
||||
<div class="live-progress"><div><span>任务进度</span><strong>{{ activeTask.progress }}%</strong></div><span><i :style="{ width: `${activeTask.progress}%` }"></i></span></div>
|
||||
<p>{{ activeTask.result }}</p>
|
||||
<dl v-if="activeTask.creditsConsumed !== undefined" class="task-cost"><dt>上游任务消耗</dt><dd>{{ activeTask.creditsConsumed }} credits</dd></dl>
|
||||
<div class="live-task-actions"><button class="button secondary" @click="emit('navigate', 'tasks')"><FileClock :size="16" />任务中心</button><button v-if="activeTask.modelUrl" class="button primary" @click="openTaskAsset(activeTask.modelUrl)"><Download :size="16" />下载 GLB</button><button v-if="activeTask.videoUrl" class="button primary" @click="openTaskAsset(activeTask.videoUrl)"><ExternalLink :size="16" />查看视频</button><button v-if="activeTask.previewUrl" class="icon-button" title="打开预览" @click="openTaskAsset(activeTask.previewUrl)"><ExternalLink :size="16" /></button></div>
|
||||
<div class="live-task-actions"><button class="button secondary" @click="emit('navigate', 'tasks')"><FileClock :size="16" />任务中心</button></div>
|
||||
</div>
|
||||
<div v-else-if="response || responseError" class="response-result"><div><span class="status-chip" :class="responseError ? 'failed' : running ? 'muted' : 'success'"><i></i>{{ responseError ? '调用未正常完成' : running ? '正在输出' : '调用完成' }}</span><small>MOYI unified response<span v-if="finishReason"> · finish_reason: {{ finishReason }}</span></small></div><p>{{ response }}</p><p v-if="responseError" role="alert">{{ responseError }}</p></div>
|
||||
<div v-else-if="response || responseError || responseMedia.imageUrl || responseMedia.videoUrl || responseMedia.audioUrl" class="response-result"><div><span class="status-chip" :class="responseError ? 'failed' : running ? 'muted' : 'success'"><i></i>{{ responseError ? '调用未正常完成' : running ? '正在输出' : '调用完成' }}</span><small>MOYI unified response<span v-if="finishReason"> · finish_reason: {{ finishReason }}</span></small></div><MediaResult v-if="responseMedia.imageUrl || responseMedia.videoUrl || responseMedia.audioUrl || responseMedia.modelUrl || responseMedia.resultUrl" :media="responseMedia" /><p v-if="response">{{ response }}</p><p v-if="responseError" role="alert">{{ responseError }}</p></div>
|
||||
<div v-else class="response-state empty"><span class="response-icon"><Sparkles :size="28" /></span><strong>等待模型响应</strong><p>配置请求并点击“开始调用”</p></div>
|
||||
</article>
|
||||
</section>
|
||||
@@ -772,7 +832,9 @@ export OPENAI_API_KEY="你的 MOYI 用户 API Key"
|
||||
$env:OPENAI_API_KEY="你的 MOYI 用户 API Key"
|
||||
# model 使用模型广场中的调用模型 ID</code></pre><div class="docs-note"><Info :size="18" /><p>部分新版 Codex 工作流默认调用 <code>/v1/responses</code>、工具调用或专用认证流程,当前 MOYI 尚未承诺兼容这些接口;若客户端不能切换到 Chat Completions,会出现 404 或参数不兼容,应改用 Cherry Studio、OpenCode 的 OpenAI-compatible 模式,或等待平台提供 Responses 兼容接口。</p></div></article>
|
||||
|
||||
<article class="panel docs-detail-card"><header class="panel-header"><div><span>API REFERENCE</span><h3>接口、流式和异步任务</h3></div></header><div class="docs-reference-table"><div><code>GET {{ platformApiBaseUrl }}/models</code><span>查询当前 Key 已授权的模型</span></div><div><code>POST {{ platformApiBaseUrl }}/chat/completions</code><span>同步聊天;传 <code>stream: true</code> 获取 SSE 流式响应</span></div><div><code>POST {{ platformApiBaseUrl }}/3d/tasks</code><span>提交 3D 异步任务</span></div><div><code>POST {{ platformApiBaseUrl }}/video/tasks</code><span>提交视频异步任务</span></div><div><code>GET {{ platformApiBaseUrl }}/tasks/<task-id></code><span>查询异步任务进度与结果</span></div></div><p class="docs-detail-warning">文本聊天的费用在完整响应后结算;流式连接中断时仍会根据使用记录处理结算。3D、视频模型不能通过聊天接口调用。</p></article>
|
||||
<article class="panel docs-detail-card"><header class="panel-header"><div><span>API REFERENCE</span><h3>接口、流式和异步任务</h3></div></header><div class="docs-reference-table"><div><code>GET {{ platformApiBaseUrl }}/models</code><span>查询当前 Key 已授权的模型与模型 ID</span></div><div><code>POST {{ platformApiBaseUrl }}/chat/completions</code><span>文本、多模态同步聊天;传 <code>stream: true</code> 获取 SSE 流式响应</span></div><div><code>POST {{ platformApiBaseUrl }}/3d/tasks</code><span>提交 3D 异步任务</span></div><div><code>POST {{ platformApiBaseUrl }}/video/tasks</code><span>提交视频异步任务</span></div><div><code>POST {{ platformApiBaseUrl }}/image/tasks</code><span>提交图片异步任务(仅已接通的模型分组)</span></div><div><code>POST {{ platformApiBaseUrl }}/audio/tasks</code><span>提交音频异步任务(仅已接通的模型分组)</span></div><div><code>GET {{ platformApiBaseUrl }}/tasks/<task-id></code><span>查询异步任务进度与图片、视频、音频或 3D 文件结果</span></div></div><p class="docs-detail-warning">文本和多模态聊天的费用在完整响应后结算;流式连接中断时仍会根据使用记录处理结算。异步媒体任务必须使用与模型类型匹配的任务接口,结果链接可能有有效期,请及时保存。</p></article>
|
||||
|
||||
<article class="panel docs-detail-card"><header class="panel-header"><div><span>MEDIA & MULTIMODAL</span><h3>图片、视频、3D 与语音</h3></div></header><div class="docs-faq"><p><strong>图片输入</strong><span>在在线调试中选择支持 image / image_url 的模型,填入可公开访问的 HTTPS 图片 URL,再补充文字提示。OpenAI-compatible 客户端使用 <code>messages[].content</code> 的 text + image_url 数组。</span></p><p><strong>异步输出</strong><span>图片、视频、音频和 3D 任务返回任务 ID,状态为 queued / running / succeeded / failed;成功后在 <code>output</code> 或 <code>result</code> 中返回对应文件 URL。</span></p><p><strong>在线预览</strong><span>平台会按 MIME 或文件格式分别渲染图片、视频播放器、音频播放器和 3D 文件下载;不要把视频或图片 URL 当作 GLB 下载。</span></p></div></article>
|
||||
|
||||
<article class="panel docs-detail-card"><header class="panel-header"><div><span>TROUBLESHOOTING</span><h3>常见问题</h3></div></header><div class="docs-faq"><p><strong>401 / INVALID_API_KEY</strong><span>确认使用的是用户端 API Key,前缀和完整值没有多余空格;停用的 Key 需要先重新启用。</span></p><p><strong>403 / MODEL_FORBIDDEN</strong><span>当前 Key 没有授权这个模型或渠道分组;回到 API Keys 编辑权限。</span></p><p><strong>404 / MODEL_NOT_FOUND</strong><span>模型 ID 填错,或管理员已停用模型/分组;重新从模型详情复制调用 ID。</span></p><p><strong>429 / KEY_BUSY 或 MODEL_BUSY</strong><span>分别表示当前 Key 并发已满,或上游分组共享并发已满;等待后重试,不要重复创建 Key。</span></p><p><strong>余额不足 / PROVIDER_NOT_CONFIGURED</strong><span>用户余额、渠道凭据或上游钱包需要管理员检查;不要在客户端暴露供应商密钥。</span></p></div></article>
|
||||
</section>
|
||||
@@ -793,7 +855,7 @@ $env:OPENAI_API_KEY="你的 MOYI 用户 API Key"
|
||||
</section>
|
||||
<template #footer><button class="button primary full" :disabled="!hasCallableGroup(selectedModel)" @click="tryModel(selectedModel)"><Play :size="16" />{{ !selectedModel.groups.length ? '分组待上线' : hasCallableGroup(selectedModel) ? '在线试用' : modelUnavailableLabel(selectedModel) }}</button><button class="button secondary full" @click="selectedModel = null; emit('navigate', 'docs')"><BookOpen :size="16" />查看文档</button></template>
|
||||
</SlidePanel>
|
||||
<SlidePanel v-if="selectedTask" :title="selectedTask.name" eyebrow="TASK DETAILS" @close="selectedTask = null"><div v-if="selectedTask.videoUrl || selectedTask.previewUrl" class="drawer-task-preview"><video v-if="selectedTask.videoUrl" :src="selectedTask.videoUrl" controls></video><img v-else :src="selectedTask.previewUrl" alt="任务结果预览" /></div><div class="task-drawer-status"><span class="status-chip" :class="selectedTask.status"><i></i>{{ selectedTask.status }}</span><strong>{{ selectedTask.progress }}%</strong></div><div class="drawer-progress"><span><i :style="{ width: `${selectedTask.progress}%` }"></i></span><small>{{ selectedTask.result }}</small></div><dl class="detail-list"><div><dt>任务 ID</dt><dd><code>{{ selectedTask.id }}</code></dd></div><div><dt>模型</dt><dd>{{ selectedTask.model }}</dd></div><div v-if="selectedTask.provider"><dt>上游通道</dt><dd>{{ selectedTask.provider }}</dd></div><div v-if="selectedTask.creditsConsumed !== undefined"><dt>任务消耗</dt><dd>{{ selectedTask.creditsConsumed }} credits</dd></div><div><dt>创建时间</dt><dd>{{ selectedTask.createdAt }}</dd></div><div><dt>耗时</dt><dd>{{ selectedTask.duration }}</dd></div></dl><div v-if="selectedTask.prompt" class="drawer-note"><Info :size="16" /><span>{{ selectedTask.prompt }}</span></div><template #footer><button v-if="selectedTask.modelUrl" class="button primary full" @click="openTaskAsset(selectedTask.modelUrl)"><Download :size="16" />下载 GLB 模型</button><button v-if="selectedTask.videoUrl" class="button primary full" @click="openTaskAsset(selectedTask.videoUrl)"><ExternalLink :size="16" />打开生成视频</button><button class="button secondary full" @click="selectedTask = null">关闭详情</button></template></SlidePanel>
|
||||
<SlidePanel v-if="selectedTask" :title="selectedTask.name" eyebrow="TASK DETAILS" @close="selectedTask = null"><MediaResult :media="{ modelUrl: selectedTask.modelUrl, imageUrl: selectedTask.imageUrl, videoUrl: selectedTask.videoUrl, audioUrl: selectedTask.audioUrl, previewUrl: selectedTask.previewUrl, resultUrl: selectedTask.resultUrl, resultFormat: selectedTask.resultFormat }" :pending="selectedTask.status !== '已完成'" /><div class="task-drawer-status"><span class="status-chip" :class="selectedTask.status"><i></i>{{ selectedTask.status }}</span><strong>{{ selectedTask.progress }}%</strong></div><div class="drawer-progress"><span><i :style="{ width: `${selectedTask.progress}%` }"></i></span><small>{{ selectedTask.result }}</small></div><dl class="detail-list"><div><dt>任务 ID</dt><dd><code>{{ selectedTask.id }}</code></dd></div><div><dt>模型</dt><dd>{{ selectedTask.model }}</dd></div><div v-if="selectedTask.provider"><dt>上游通道</dt><dd>{{ selectedTask.provider }}</dd></div><div v-if="selectedTask.creditsConsumed !== undefined"><dt>任务消耗</dt><dd>{{ selectedTask.creditsConsumed }} credits</dd></div><div><dt>创建时间</dt><dd>{{ selectedTask.createdAt }}</dd></div><div><dt>耗时</dt><dd>{{ selectedTask.duration }}</dd></div></dl><div v-if="selectedTask.prompt" class="drawer-note"><Info :size="16" /><span>{{ selectedTask.prompt }}</span></div><template #footer><button v-if="selectedTask.modelUrl" class="button primary full" @click="openTaskAsset(selectedTask.modelUrl)"><Download :size="16" />下载模型文件</button><button v-if="selectedTask.videoUrl" class="button primary full" @click="openTaskAsset(selectedTask.videoUrl)"><ExternalLink :size="16" />打开生成视频</button><button class="button secondary full" @click="selectedTask = null">关闭详情</button></template></SlidePanel>
|
||||
|
||||
<UiModal v-if="deleteKeyTarget" title="删除 API Key" @close="!keyBusy && (deleteKeyTarget = undefined)"><p>确认删除「{{ deleteKeyTarget.name }}」?删除后无法重新启用,已有调用记录和任务会保留。</p><template #footer><button class="button secondary" :disabled="keyBusy" @click="deleteKeyTarget = undefined">取消</button><button class="button danger" :disabled="keyBusy" @click="deleteKey">{{ keyBusy ? '删除中…' : '确认删除' }}</button></template></UiModal>
|
||||
<UiModal v-if="createKeyOpen" title="创建 API Key" eyebrow="NEW CREDENTIAL" @close="createKeyOpen = false"><p class="modal-description">个人 Key 适合个人开发调试,项目 Key 适合服务端应用和团队协作。创建后再配置该 Key 可调用的具体模型。</p><label class="form-label">Key 名称</label><input v-model="keyName" class="text-input" placeholder="例如:生产环境" /><label class="form-label">Key 归属</label><div class="option-list"><button :class="{ active: keyScopeType === 'personal' }" @click="keyScopeType = 'personal'"><span><i></i><strong>个人 Key</strong><small>归属当前账号</small></span><Check v-if="keyScopeType === 'personal'" :size="16" /></button><button :class="{ active: keyScopeType === 'project' }" @click="keyScopeType = 'project'"><span><i></i><strong>项目 Key</strong><small>归属工作区/项目</small></span><Check v-if="keyScopeType === 'project'" :size="16" /></button></div><div v-if="keyScopeType === 'project'"><label class="form-label"><span>选择项目</span><button class="text-link" type="button" @click="openProjectModal">新建项目</button></label><select v-model="selectedProjectId" class="text-input"><option value="" disabled>请选择项目</option><option v-for="project in projects" :key="project.id" :value="project.id">{{ project.name }}</option></select></div><div class="permission-hint"><ShieldCheck :size="16" /><span>Key 创建后默认不开放模型权限,请在下一步选择具体可调用模型。</span></div><template #footer><button class="button secondary" @click="createKeyOpen = false">取消</button><button class="button primary" @click="createKey"><KeyRound :size="16" />生成 Key</button></template></UiModal>
|
||||
@@ -829,6 +891,13 @@ $env:OPENAI_API_KEY="你的 MOYI 用户 API Key"
|
||||
.playground-selectors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
|
||||
.playground-selectors label { display: grid; gap: 8px; font-size: 13px; min-width: 0; }
|
||||
.playground-selectors select { width: 100%; min-width: 0; }
|
||||
.capability-strip { display:flex; flex-wrap:wrap; align-items:center; gap:6px; padding:9px 10px; margin-top:12px; border:1px solid #e6e9f1; border-radius:8px; color:#687378; font-size:11px; background:#fbfcff; }
|
||||
.capability-strip span { color:#475569; font-weight:700; margin-right:3px; }
|
||||
.capability-strip em { padding:3px 7px; border-radius:5px; color:#5942b1; font-style:normal; background:#f0edff; }
|
||||
.media-input-label { display:grid; gap:8px; }
|
||||
.media-input-label small { color:var(--muted); font-weight:400; }
|
||||
.input-media-preview { width:100%; max-height:160px; object-fit:contain; border:1px solid var(--border); border-radius:8px; background:var(--soft); }
|
||||
.request-unavailable { margin:12px 0 0; padding:10px 12px; border:1px solid #f2d5a2; border-radius:8px; color:#8a5c14; font-size:11px; line-height:1.55; background:#fff8e8; }
|
||||
@media(max-width: 1180px) { .playground-grid { grid-template-columns: minmax(0, 1fr); } }
|
||||
@media(max-width: 700px) { .playground-selectors { grid-template-columns: minmax(0, 1fr); } }
|
||||
</style>
|
||||
Reference in new issue
Block a user